From patchwork Tue Mar 10 02:34:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11428311 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 7D4571800 for ; Tue, 10 Mar 2020 02:34:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4820E20728 for ; Tue, 10 Mar 2020 02:34:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="p1GQy/xb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4820E20728 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 6560E6B00A1; Mon, 9 Mar 2020 22:34:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6069F6B00A3; Mon, 9 Mar 2020 22:34:31 -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 51B7A6B00A4; Mon, 9 Mar 2020 22:34:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 3A0366B00A1 for ; Mon, 9 Mar 2020 22:34:31 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EF548180AD815 for ; Tue, 10 Mar 2020 02:34:30 +0000 (UTC) X-FDA: 76577883942.10.dime30_61997fa92145e X-Spam-Summary: 2,0,0,cc4a1aaf9733a455,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: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.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:23,LUA_SUMMARY:none X-HE-Tag: dime30_61997fa92145e X-Filterd-Recvd-Size: 4349 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 02:34:30 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id b72so2186488pfb.11 for ; Mon, 09 Mar 2020 19:34:30 -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=1jVlFXnPIswdmcUS2KhghzNWC4Wu8MZE4GHTBIKCva0=; b=p1GQy/xbfcYASPMVRTK47LqgZVgCbJQcsO9s4I+7hVy5iVS+wzfByCR30EuobUODOP n3AeQuRscEFg1wF3LUWGirPNZYpOKFbVyUektuCuji/qPnCArSB9P+W5m2RG5eyUYU61 TTWg5fhSnafWesk+RAa/LqEGcmYqUG2z26K1GYIlZ2QKLeldTr/j1C6lDSVmXKo0fL08 6fTxhjgNSsFcRYTlr7uPFdW1qY/V716VnyV4DWHRFLj8ZGLgaa2tpkDWNV+ARkaJ0cQu FwHCTlt9hxbft5KHhgGixQV8DWfXFYkog+Kc/RMzQhGHFAIMZ2b5KGo1qDGDaHbJURti 8D0A== 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=1jVlFXnPIswdmcUS2KhghzNWC4Wu8MZE4GHTBIKCva0=; b=kIqqT3YLuGWQe+FevftUlnRJ21NbCbPTruTIcmj8L/ARWrD1IbCfEYplfFciQZYzxR 4gsI0gplI8+G4canw7cwyq8UN1CQkfMIqulEPF7IlvDGFn7gBgZ0SFQMpbfhfQWIqBUK ea2ZSgdW0Ax0CjWHKCoJtL0ip9wu+YpheZ3/nDR9ML/Yadj2QAQlctI8jjctCIOke4zT WQLbQar6ti5WXOh4Ik70NcUIADY1g8xgomA2rUASuBr2LZY/95KoTj5tcJfAmLeUNvpX cUrGfpAtzymxsI5kQzIEwcR/KbMjKljnvs4FdFfhoRVdXGYXI+NWGJsu+x4mV8w3LEMR oTJg== X-Gm-Message-State: ANhLgQ1aYKlDXUc0pHjyMhewwCwcxv6g4+oFW0t5qw2PAGuf3A9J9SCu djyQ7BKB6bBanD/LNfv0fEw= X-Google-Smtp-Source: ADFU+vtDsxJNQ+S3uWnzmdWktPG0v9V+VKwlB1/CIcpZ+WNzegJFAWU3UmhOnT4aRWaZCXOAxVDr7w== X-Received: by 2002:aa7:870f:: with SMTP id b15mr2944813pfo.190.1583807669631; Mon, 09 Mar 2020 19:34:29 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id x72sm7633963pfc.156.2020.03.09.19.34.28 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 09 Mar 2020 19:34:29 -0700 (PDT) From: qiwuchen55@gmail.com To: akpm@linux-foundation.org, pankaj.gupta.linux@gmail.com, alexander.duyck@gmail.com, willy@infradead.org, bhe@redhat.com Cc: linux-mm@kvack.org, chenqiwu Subject: [PATCH v2] mm/page_alloc: simplify page_is_buddy() for better code readability Date: Tue, 10 Mar 2020 10:34:24 +0800 Message-Id: <1583807664-10343-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 --- changes in v2: - split the conditional statement into four separate tests for better code readability. --- 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..b221f6d 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_order(buddy) != order) + return 0; - return 1; - } + if (!page_is_guard(buddy) && !PageBuddy(buddy)) + 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