From: Alexander Duyck <alexander.duyck@gmail.com>
To: qiwuchen55@gmail.com
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm <linux-mm@kvack.org>, chenqiwu <chenqiwu@xiaomi.com>
Subject: Re: [PATCH] mm/page_alloc: simplify page_is_buddy() for better code readability
Date: Mon, 9 Mar 2020 09:53:08 -0700 [thread overview]
Message-ID: <CAKgT0UfnNQjKezdWueiBOtNROqzATuxEwwDMy1dRO0unAWG8nw@mail.gmail.com> (raw)
In-Reply-To: <1583655036-5025-1-git-send-email-qiwuchen55@gmail.com>
On Sun, Mar 8, 2020 at 12:10 AM <qiwuchen55@gmail.com> wrote:
>
> From: chenqiwu <chenqiwu@xiaomi.com>
>
> Simplify page_is_buddy() to reduce the redundant code for better
> code readability.
>
> Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
> ---
> 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.
next prev parent reply other threads:[~2020-03-09 16:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-08 8:10 [PATCH] mm/page_alloc: simplify page_is_buddy() for better code readability qiwuchen55
2020-03-08 8:44 ` Baoquan He
2020-03-08 12:23 ` Matthew Wilcox
2020-03-09 16:53 ` Alexander Duyck [this message]
2020-03-10 2:15 ` chenqiwu
2020-03-09 19:18 ` Pankaj Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKgT0UfnNQjKezdWueiBOtNROqzATuxEwwDMy1dRO0unAWG8nw@mail.gmail.com \
--to=alexander.duyck@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chenqiwu@xiaomi.com \
--cc=linux-mm@kvack.org \
--cc=qiwuchen55@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).