From: Vlastimil Babka <vbabka@suse.cz>
To: Zi Yan <ziy@nvidia.com>, linux-mm@kvack.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Steven Rostedt <rostedt@goodmis.org>,
David Hildenbrand <david@redhat.com>,
Mel Gorman <mgorman@techsingularity.net>,
Mike Rapoport <rppt@kernel.org>,
Oscar Salvador <osalvador@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] mm: page_alloc: simplify pageblock migratetype check in __free_one_page().
Date: Sat, 2 Apr 2022 00:14:25 +0200 [thread overview]
Message-ID: <a085d739-aa06-eff0-d350-0df088a7f2d0@suse.cz> (raw)
In-Reply-To: <20220401181109.1477354-1-zi.yan@sent.com>
On 4/1/22 20:11, Zi Yan wrote:
> From: Zi Yan <ziy@nvidia.com>
>
> Move pageblock migratetype check code in the while loop to simplify the
> logic. It also saves redundant buddy page checking code.
>
> Suggested-by: Vlastimil Babka <vbabka@suse.cz>
> Link: https://lore.kernel.org/linux-mm/27ff69f9-60c5-9e59-feb2-295250077551@suse.cz/
> Signed-off-by: Zi Yan <ziy@nvidia.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/page_alloc.c | 46 +++++++++++++++++-----------------------------
> 1 file changed, 17 insertions(+), 29 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 856473e54155..2ea106146686 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1054,7 +1054,6 @@ static inline void __free_one_page(struct page *page,
> int migratetype, fpi_t fpi_flags)
> {
> struct capture_control *capc = task_capc(zone);
> - unsigned int max_order = pageblock_order;
> unsigned long buddy_pfn;
> unsigned long combined_pfn;
> struct page *buddy;
> @@ -1070,8 +1069,7 @@ static inline void __free_one_page(struct page *page,
> VM_BUG_ON_PAGE(pfn & ((1 << order) - 1), page);
> VM_BUG_ON_PAGE(bad_range(zone, page), page);
>
> -continue_merging:
> - while (order < max_order) {
> + while (order < MAX_ORDER - 1) {
> if (compaction_capture(capc, page, order, migratetype)) {
> __mod_zone_freepage_state(zone, -(1 << order),
> migratetype);
> @@ -1082,6 +1080,22 @@ static inline void __free_one_page(struct page *page,
>
> if (!page_is_buddy(page, buddy, order))
> goto done_merging;
> +
> + if (unlikely(order >= pageblock_order)) {
> + /*
> + * We want to prevent merge between freepages on pageblock
> + * without fallbacks and normal pageblock. Without this,
> + * pageblock isolation could cause incorrect freepage or CMA
> + * accounting or HIGHATOMIC accounting.
> + */
> + int buddy_mt = get_pageblock_migratetype(buddy);
> +
> + if (migratetype != buddy_mt
> + && (!migratetype_is_mergeable(migratetype) ||
> + !migratetype_is_mergeable(buddy_mt)))
> + goto done_merging;
> + }
> +
> /*
> * Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page,
> * merge with it and move up one order.
> @@ -1095,32 +1109,6 @@ static inline void __free_one_page(struct page *page,
> pfn = combined_pfn;
> order++;
> }
> - if (order < MAX_ORDER - 1) {
> - /* If we are here, it means order is >= pageblock_order.
> - * We want to prevent merge between freepages on pageblock
> - * without fallbacks and normal pageblock. Without this,
> - * pageblock isolation could cause incorrect freepage or CMA
> - * accounting or HIGHATOMIC accounting.
> - *
> - * We don't want to hit this code for the more frequent
> - * low-order merging.
> - */
> - int buddy_mt;
> -
> - buddy_pfn = __find_buddy_pfn(pfn, order);
> - buddy = page + (buddy_pfn - pfn);
> -
> - if (!page_is_buddy(page, buddy, order))
> - goto done_merging;
> - buddy_mt = get_pageblock_migratetype(buddy);
> -
> - if (migratetype != buddy_mt
> - && (!migratetype_is_mergeable(migratetype) ||
> - !migratetype_is_mergeable(buddy_mt)))
> - goto done_merging;
> - max_order = order + 1;
> - goto continue_merging;
> - }
>
> done_merging:
> set_buddy_order(page, order);
prev parent reply other threads:[~2022-04-01 22:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-01 18:11 [PATCH v2 1/2] mm: page_alloc: simplify pageblock migratetype check in __free_one_page() Zi Yan
2022-04-01 18:11 ` [PATCH v2 2/2] mm: wrap __find_buddy_pfn() with a necessary buddy page validation Zi Yan
2022-04-01 18:29 ` Linus Torvalds
2022-04-01 18:56 ` Zi Yan
2022-04-01 19:01 ` Linus Torvalds
2022-04-01 19:25 ` Zi Yan
2022-04-01 22:33 ` Vlastimil Babka
2022-04-01 22:14 ` Vlastimil Babka [this message]
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=a085d739-aa06-eff0-d350-0df088a7f2d0@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=osalvador@suse.de \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=ziy@nvidia.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).