From patchwork Tue Mar 10 15:22:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11429655 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 BD2D0139A for ; Tue, 10 Mar 2020 15:22:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8950B21655 for ; Tue, 10 Mar 2020 15:22:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kJ/BXz/w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8950B21655 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 CA07D6B0005; Tue, 10 Mar 2020 11:22:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C50806B0006; Tue, 10 Mar 2020 11:22:38 -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 B3EEC6B0007; Tue, 10 Mar 2020 11:22:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0057.hostedemail.com [216.40.44.57]) by kanga.kvack.org (Postfix) with ESMTP id 9B9F46B0005 for ; Tue, 10 Mar 2020 11:22:38 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5FEDB4DB2 for ; Tue, 10 Mar 2020 15:22:38 +0000 (UTC) X-FDA: 76579819596.10.light28_6e527e0ef6f3b X-Spam-Summary: 2,0,0,bb9bbba058032b65,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:3866:3867:3870:3871:3874: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.210.195:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.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:23,LUA_SUMMARY:none X-HE-Tag: light28_6e527e0ef6f3b X-Filterd-Recvd-Size: 4529 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 15:22:37 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id b72so3061019pfb.11 for ; Tue, 10 Mar 2020 08:22:37 -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=EY9lFreAZ3AAn+r8xmwmuCckTmy61hYRhjGqopYfRTU=; b=kJ/BXz/whpjcWl/8v9MI957RfV3m8IBe56al8QNMRheXMlJ3/MY9WR00FWowKv9tTM SCIokSay21rvOWB/FHT2AUq2eCDLWejTd4ZA0CwkzYYnu/pVjRsCxksPpLrgR6mlrYYK 1t1+S38DFtLzMdUE469bdYJMLIQsKOn2D2PNtoEZJqrIJYDkkp48TsWNwljjmZNbo+y1 HdUCqm6Z/OEd1kI5T++N4P8x4XHyopRDKVmckW4SxF/+kab7FN/MZvhRa+Su++eBC5oO 4Ck/BFF9rUkUdfAMYCWk6FHnve5k3M0CSjnPPZpD/6JLZSbCZI2H5oBH+F8vNwNBJNUG yPAw== 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=EY9lFreAZ3AAn+r8xmwmuCckTmy61hYRhjGqopYfRTU=; b=Yg9wk807fjYW28oRdWCU6W7D/Q9itE4hnLeKLGhl6hW1FaxRLx5jyx4oA1ujTy2Rhu +5gTYdIFitXKgPg3cYCeE8bDt+/H2ao3/yUre7wp2oeMfn0Z2G93CSydpdmCPPEBYWrR SzX8KQKdl9OrpwXWK2lA57kkENS7R4lxvGhNyoIh4KKlYfmZZHAtrlDtVtqYkpUJDfUu pcpqpboBh6AAIiRENoUYyGIJGl1wU4Qs665fKT7xdu/h8KOPiPeLORBTtoCf8ZsbV0VJ NTpoALfHOMlr+HyjYoeYvwJYvPY7Vg+G7G5Dakx0U2fD/HgCacYW9rBRv/IQBsmV9eQw igRw== X-Gm-Message-State: ANhLgQ3Z3dwOCjXSAvBdiDiWVuflKIAM3IKt/Ac2I3AsFunzBD0ArcuP b83k2AnfQbaYtbKR6PUHGCs= X-Google-Smtp-Source: ADFU+vuTFFJyAbME/SPVGH+xE0uBn9DoHNYgRhPXoEUt2I/5n+fu4sXNHBaC84CmRA4t2eUbCiGltg== X-Received: by 2002:a63:a601:: with SMTP id t1mr21702859pge.23.1583853756772; Tue, 10 Mar 2020 08:22:36 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id x2sm45938961pge.2.2020.03.10.08.22.35 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 10 Mar 2020 08:22:35 -0700 (PDT) From: qiwuchen55@gmail.com To: akpm@linux-foundation.org, willy@infradead.org, vbabka@suse.cz, pankaj.gupta.linux@gmail.com, alexander.duyck@gmail.com, bhe@redhat.com Cc: linux-mm@kvack.org, chenqiwu Subject: [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability Date: Tue, 10 Mar 2020 23:22:31 +0800 Message-Id: <1583853751-5525-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: Alexander Duyck Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Vlastimil Babka Acked-by: Pankaj Gupta --- changes in v4: - change the return type of page_is_buddy() from int to bool. - reflow the comment into fewer lines. --- mm/page_alloc.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3c4eb75..229fc8c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -791,32 +791,25 @@ static inline void set_page_order(struct page *page, unsigned int order) * * For recording page's order, we use page_private(page). */ -static inline int page_is_buddy(struct page *page, struct page *buddy, +static inline bool 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 false; - return 1; - } + if (page_order(buddy) != order) + return false; - 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 false; - VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy); + VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy); - return 1; - } - return 0; + return true; } #ifdef CONFIG_COMPACTION