From patchwork Tue Mar 10 09:15:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11428879 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29E0D138D for ; Tue, 10 Mar 2020 09:15:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E00D82467F for ; Tue, 10 Mar 2020 09:15:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GQKlgmMD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E00D82467F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2E1506B0005; Tue, 10 Mar 2020 05:15:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 292646B0006; Tue, 10 Mar 2020 05:15:37 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A7926B0007; Tue, 10 Mar 2020 05:15:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id F37866B0005 for ; Tue, 10 Mar 2020 05:15:36 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9D159181AEF0B for ; Tue, 10 Mar 2020 09:15:36 +0000 (UTC) X-FDA: 76578894672.21.shelf39_6b24319f89b59 X-Spam-Summary: 2,0,0,5aefe89558424800,d41d8cd98f00b204,qiwuchen55@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2731:3138:3139:3140:3141:3142:3353:3865:3867:3870:3871:3874:4321:5007:6261:6653:7576:7875:8957:9413:9592:10004:11026:11232:11473:11658:11914:12043:12048:12296:12297:12517:12519:12555:12679:12683:12895:13069:13311:13357:14096:14110:14181:14384:14394:14721:21080:21094:21323:21444:21451:21627:21666:21990:30012:30054:30070,0,RBL:209.85.214.196:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: shelf39_6b24319f89b59 X-Filterd-Recvd-Size: 4380 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 09:15:36 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id w12so5184150pll.13 for ; Tue, 10 Mar 2020 02:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=542hMZsBjSXcousghtwZzmUvDNeAFDZuvTmk8UAemLU=; b=GQKlgmMDNJ0b9Q1ml63VLoFCK5JEOZJUUvtVXWqRdc0An02y5banEL7dAySHxFGL7X UVDv13ollupf2Blb7DXpogfOy+WLhuF0CL+0j65GgYv/SsBxzjDNb7B5TN9ytVEoGobA QZ+b0/Ovgp31BTcf1z4Hcs2noU0HlIU6fDbxbq9ajyyywVRbwY9smTte5InrVHwotlwS RjEQEZZ7FpdjSpj0QOSGqNk8v4Zgk8DSFstqU42UdlKXScwPaaTqNmg2Qge4o1E/b/qH /P9GzJ1vx/ZIE4IlgXv9bF0KdVcZwbN25iZKc43X9saf6Uv9puKrLCNzw+dl7U85ii4l P8Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=542hMZsBjSXcousghtwZzmUvDNeAFDZuvTmk8UAemLU=; b=O0i8nMRpl9poaMOxbI0OX8n75oWNKXnE0LZkzd88l4WxiGZEljIfwGi5fFDWgbcGAL TAT8LvsMlVsF73atPNx+ezmnI5CziS3rujOOhOw/3oeJajEtFb06IJiT3/kCBsRzNqFK HUdc/ihZ0NHQ4ONqUJ+eyswU5AYtLZ2icB8PDFzD14nP+cESUhbIlWQcOZ+H2L/dMv6e curDwzNtmxebETo3gbT05JoPZsEK2fVEg06R2obW16mybzsZ4o1eYrRUK9og/7ae7eMh GeozQO9xJCZxf+FL9al0MEVFziLgkq/mI6pAX4XTRZzOen2Lj7OVTxgTUrWiEXYESwf5 3KqA== X-Gm-Message-State: ANhLgQ3CoGxBW9jxVtAlK2rjGrPECOfRh6DsDaQ4fh2l2K17bpaj14lM d6JQPwMXGDEaVDoMdxOS9+o= X-Google-Smtp-Source: ADFU+vvTcSSYYkVxc5ntZr29eoQVlQMw+RD0o1IoKNmQG7d2n+DlLIZ3PBmaj5IHxjSH88nOcGKfuw== X-Received: by 2002:a17:902:aa01:: with SMTP id be1mr19051506plb.293.1583831735151; Tue, 10 Mar 2020 02:15:35 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id 13sm45552792pgo.13.2020.03.10.02.15.34 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 10 Mar 2020 02:15:34 -0700 (PDT) From: qiwuchen55@gmail.com To: akpm@linux-foundation.org, vbabka@suse.cz, pankaj.gupta.linux@gmail.com, alexander.duyck@gmail.com, willy@infradead.org, bhe@redhat.com Cc: linux-mm@kvack.org, chenqiwu Subject: [PATCH v3] mm/page_alloc: simplify page_is_buddy() for better code readability Date: Tue, 10 Mar 2020 17:15:29 +0800 Message-Id: <1583831729-14383-1-git-send-email-qiwuchen55@gmail.com> X-Mailer: git-send-email 1.9.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: chenqiwu Simplify page_is_buddy() to reduce the redundant code for better code readability. Signed-off-by: chenqiwu Reviewed-by: Vlastimil Babka --- changes in v3: - exchange the first two condition statements in v2 because the page type must be checked first. --- mm/page_alloc.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3c4eb75..412f5d5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -794,29 +794,23 @@ static inline void set_page_order(struct page *page, unsigned int order) static inline int page_is_buddy(struct page *page, struct page *buddy, unsigned int order) { - if (page_is_guard(buddy) && page_order(buddy) == order) { - if (page_zone_id(page) != page_zone_id(buddy)) - return 0; - - VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy); + if (!page_is_guard(buddy) && !PageBuddy(buddy)) + return 0; - return 1; - } + if (page_order(buddy) != order) + return 0; - if (PageBuddy(buddy) && page_order(buddy) == order) { - /* - * zone check is done late to avoid uselessly - * calculating zone/node ids for pages that could - * never merge. - */ - if (page_zone_id(page) != page_zone_id(buddy)) - return 0; + /* + * zone check is done late to avoid uselessly + * calculating zone/node ids for pages that could + * never merge. + */ + if (page_zone_id(page) != page_zone_id(buddy)) + return 0; - VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy); + VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy); - return 1; - } - return 0; + return 1; } #ifdef CONFIG_COMPACTION