From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82E13C10F25 for ; Tue, 10 Mar 2020 02:15:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 41C1F2146E for ; Tue, 10 Mar 2020 02:15:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sdXXgWoE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41C1F2146E 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 D41BE6B0099; Mon, 9 Mar 2020 22:15:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF1F56B009B; Mon, 9 Mar 2020 22:15:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C087C6B009C; Mon, 9 Mar 2020 22:15:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id A91F06B0099 for ; Mon, 9 Mar 2020 22:15:58 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6916B181AEF00 for ; Tue, 10 Mar 2020 02:15:58 +0000 (UTC) X-FDA: 76577837196.15.rule98_5137b09adec47 X-HE-Tag: rule98_5137b09adec47 X-Filterd-Recvd-Size: 5382 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 02:15:57 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id t3so5601843pgn.1 for ; Mon, 09 Mar 2020 19:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DdrFQDAszevNZWGKLs0KhI8Z5mlt3pd+gP4BSpLEsIU=; b=sdXXgWoEp/uNOeN6rxc3e0AtayQM2oC6+7UtgEZHJlpEktBIaUuVefbIAG6SRV4r5z aQpRBTSeu1zVAWhrcAOb8rBC/ofdc9fuuJU1PxuXFhUYcEzMn8mSSKNT0eOdUw/IMXHl PuWWe27tQ1BntoqUxYj/aHm9DEAjwZOSgSKV5OAmLqly4KqQNICauUd2c10uwfc1Y2sV 5aoWjjLh6CMPCzjl6yjkRcChpn+NJo4PPvAt0uLp1x8/XbxkffDIXtFoKG4WcPKMWVdy srHps1BSl+k0az7lyqFrVXEn0dUFsChkfAMl8b6JPwA/5lJdJ48z9rDse/GuEZgbVhSY YMzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=DdrFQDAszevNZWGKLs0KhI8Z5mlt3pd+gP4BSpLEsIU=; b=NZfT6rEpZWy03OPWKldbQFLIqyI3ZPN7B+68WYSGfb6bmAEvI5jc5EMmzEZkFdW8IW KJf9P+VvaiNXljRnJ9fvEd3RyLRqOkY1l/3LkNyoyMyN8Of+ptR1+jFEMabriB1x0io0 S+cZDi8yy4cmA8f9JnxYSu+Tcx5FcOAVbsjRRE3n7tZSn0re7D3hCPQEC2vUFCTWsVMM NYKSxiWY1nLMwLQ9VWa4MuqGHuMpTn7Wa4n7F+KSwWA5eBwIbpA+0PkZnLIisTlTIxkE RkslQnUYhUYtyIg3+BtZ8d2Y2MhFiQBmaFL6tLwM7QXxsyhnu/8p3hvXiFFyZ1YojyVA 68wg== X-Gm-Message-State: ANhLgQ3jZ8oQtvDwuxRJqPclG+nZyY6gR48bmAq77T8keWRqYZ20uNkO YZ/wFFq7Gtch9ND3LkAyiX0= X-Google-Smtp-Source: ADFU+vuOU6qWutQSQWa7o/wiV/D/dUOOLwxw3tr5IhdWumlMc3aw9hOipD4I5yo5iKYaed5EA83AKA== X-Received: by 2002:a63:6dc5:: with SMTP id i188mr18130801pgc.82.1583806556574; Mon, 09 Mar 2020 19:15:56 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id y15sm22420211pfl.149.2020.03.09.19.15.55 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 09 Mar 2020 19:15:56 -0700 (PDT) Date: Tue, 10 Mar 2020 10:15:53 +0800 From: chenqiwu To: Alexander Duyck Cc: Andrew Morton , linux-mm , chenqiwu Subject: Re: [PATCH] mm/page_alloc: simplify page_is_buddy() for better code readability Message-ID: <20200310021553.GB8961@cqw-OptiPlex-7050> References: <1583655036-5025-1-git-send-email-qiwuchen55@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) 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: On Mon, Mar 09, 2020 at 09:53:08AM -0700, Alexander Duyck wrote: > On Sun, Mar 8, 2020 at 12:10 AM wrote: > > > > From: chenqiwu > > > > Simplify page_is_buddy() to reduce the redundant code for better > > code readability. > > > > Signed-off-by: chenqiwu > > --- > > mm/page_alloc.c | 13 +++---------- > > 1 file changed, 3 insertions(+), 10 deletions(-) > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 79e950d..c6eef38 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -797,16 +797,8 @@ 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); > > - > > - return 1; > > - } > > - > > - if (PageBuddy(buddy) && page_order(buddy) == order) { > > + if ((page_is_guard(buddy) || PageBuddy(buddy)) > > + && page_order(buddy) == order) { > > /* > > * zone check is done late to avoid uselessly > > * calculating zone/node ids for pages that could > > Instead of keeping the if statement as is couldn't you flatten this > out further by just returning 0 if !page_is_guard && !PageBuddy? > > So something like: > if (!page_is_guard(buddy) && !PageBuddy(buddy)) > return0; > > if (page_order(buddy) != order) > return 0; > > I feel like this would be more readable than sorting out the > parenthesis for the conditional statement. Then you can also just get > rid of the indenting and braces for the rest of the statement. With > that it would more closely match the description above as well as you > are going through and checking a - d as separate tests. I agree, for performance considering, I think the second conditional statement should be moved up. I will resend this as proper patch v2 for review.