* [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability
@ 2020-03-10 15:22 qiwuchen55
2020-03-10 15:55 ` Alexander Duyck
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: qiwuchen55 @ 2020-03-10 15:22 UTC (permalink / raw
To: akpm, willy, vbabka, pankaj.gupta.linux, alexander.duyck, bhe
Cc: linux-mm, chenqiwu
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 v4:
- change the return type of page_is_buddy() from int to bool.
- reflow the comment into fewer lines.
---
mm/page_alloc.c | 33 +++++++++++++--------------------
1 file changed, 13 insertions(+), 20 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3c4eb75..229fc8c 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -791,32 +791,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
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability
2020-03-10 15:22 [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability qiwuchen55
@ 2020-03-10 15:55 ` Alexander Duyck
2020-03-10 18:09 ` Matthew Wilcox
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Duyck @ 2020-03-10 15:55 UTC (permalink / raw
To: qiwuchen55
Cc: Andrew Morton, Matthew Wilcox, Vlastimil Babka,
pankaj.gupta.linux, bhe, linux-mm, chenqiwu
On Tue, Mar 10, 2020 at 8:22 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>
> ---
> changes in v4:
> - change the return type of page_is_buddy() from int to bool.
> - reflow the comment into fewer lines.
> ---
Looks good to me.
Reviewed-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
> mm/page_alloc.c | 33 +++++++++++++--------------------
> 1 file changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 3c4eb75..229fc8c 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -791,32 +791,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
> --
> 1.9.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability
2020-03-10 15:22 [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability qiwuchen55
2020-03-10 15:55 ` Alexander Duyck
@ 2020-03-10 18:09 ` Matthew Wilcox
2020-03-10 18:23 ` Vlastimil Babka
2020-03-10 19:09 ` Pankaj Gupta
3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2020-03-10 18:09 UTC (permalink / raw
To: qiwuchen55
Cc: akpm, vbabka, pankaj.gupta.linux, alexander.duyck, bhe, linux-mm,
chenqiwu
On Tue, Mar 10, 2020 at 11:22:31PM +0800, 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>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability
2020-03-10 15:22 [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability qiwuchen55
2020-03-10 15:55 ` Alexander Duyck
2020-03-10 18:09 ` Matthew Wilcox
@ 2020-03-10 18:23 ` Vlastimil Babka
2020-03-10 19:09 ` Pankaj Gupta
3 siblings, 0 replies; 5+ messages in thread
From: Vlastimil Babka @ 2020-03-10 18:23 UTC (permalink / raw
To: qiwuchen55, akpm, willy, pankaj.gupta.linux, alexander.duyck, bhe
Cc: linux-mm, chenqiwu
On 3/10/20 4:22 PM, 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>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability
2020-03-10 15:22 [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability qiwuchen55
` (2 preceding siblings ...)
2020-03-10 18:23 ` Vlastimil Babka
@ 2020-03-10 19:09 ` Pankaj Gupta
3 siblings, 0 replies; 5+ messages in thread
From: Pankaj Gupta @ 2020-03-10 19:09 UTC (permalink / raw
To: qiwuchen55
Cc: Andrew Morton, willy, vbabka, alexander.duyck, Baoquan He,
linux-mm, chenqiwu
[-- Attachment #1: Type: text/plain, Size: 2305 bytes --]
> Simplify page_is_buddy() to reduce the redundant code for better code
> readability.
>
> Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
> ---
> changes in v4:
> - change the return type of page_is_buddy() from int to bool.
> - reflow the comment into fewer lines.
> ---
> mm/page_alloc.c | 33 +++++++++++++--------------------
> 1 file changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 3c4eb75..229fc8c 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -791,32 +791,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
> --
>
Acked-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
> 1.9.1
>
>
[-- Attachment #2: Type: text/html, Size: 3406 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-03-10 19:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-10 15:22 [PATCH v4] mm/page_alloc: simplify page_is_buddy() for better code readability qiwuchen55
2020-03-10 15:55 ` Alexander Duyck
2020-03-10 18:09 ` Matthew Wilcox
2020-03-10 18:23 ` Vlastimil Babka
2020-03-10 19:09 ` Pankaj Gupta
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.