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 <chenqiwu@xiaomi.com>
Subject: [PATCH v2] mm/page_alloc: simplify page_is_buddy() for better code readability
Date: Tue, 10 Mar 2020 10:34:24 +0800 [thread overview]
Message-ID: <1583807664-10343-1-git-send-email-qiwuchen55@gmail.com> (raw)
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>
---
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
--
1.9.1
next reply other threads:[~2020-03-10 2:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-10 2:34 qiwuchen55 [this message]
2020-03-10 8:28 ` [PATCH v2] mm/page_alloc: simplify page_is_buddy() for better code readability Vlastimil Babka
2020-03-10 9:09 ` chenqiwu
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=1583807664-10343-1-git-send-email-qiwuchen55@gmail.com \
--to=qiwuchen55@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=bhe@redhat.com \
--cc=chenqiwu@xiaomi.com \
--cc=linux-mm@kvack.org \
--cc=pankaj.gupta.linux@gmail.com \
--cc=willy@infradead.org \
/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).