From: chenqiwu Date: Thu, 2 Apr 2020 04:09:56 +0000 (-0700) Subject: mm/page_alloc: simplify page_is_buddy() for better code readability X-Git-Tag: v5.10.7~2924^2~37 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe925c0cb05b5616353e8b68eb914c9840cad2f9;p=platform%2Fkernel%2Flinux-rpi.git mm/page_alloc: simplify page_is_buddy() for better code readability Simplify page_is_buddy() to reduce the redundant code for better code readability. Signed-off-by: chenqiwu Signed-off-by: Andrew Morton Reviewed-by: Alexander Duyck Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Vlastimil Babka Acked-by: Pankaj Gupta Link: http://lkml.kernel.org/r/1583853751-5525-1-git-send-email-qiwuchen55@gmail.com Signed-off-by: Linus Torvalds --- diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 43a405c..c494bf2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -792,32 +792,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