Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zenghui Yu" <zenghui.yu@linux.dev>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, vbabka@kernel.org, surenb@google.com,
	mhocko@suse.com, brendan.jackman@linux.dev, hannes@cmpxchg.org,
	ziy@nvidia.com
Subject: Re: [PATCH] mm/page_alloc: clear page tag refs when onlining hotplugged memory
Date: Wed, 21 Oct 2026 16:11:23 +0000	[thread overview]
Message-ID: <sashiko-outbox-180460@kernel.org> (raw)
In-Reply-To: <20261020161053.59879-1-zenghui.yu@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm/page_alloc: clear_page_tag_ref() called on tail pages in __free_pages_core()
--

commit e2abce3265909945612b858336381b3dbe9dca76
Author: Zenghui Yu (Huawei) <zenghui.yu@linux.dev>

mm/page_alloc: clear page tag refs when onlining hotplugged memory

This commit calls clear_page_tag_ref() on hotplugged pages in
__free_pages_core() so that freeing never-allocated pages into the buddy
allocator does not trigger a warning under CONFIG_MEM_ALLOC_PROFILING_DEBUG.

> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 2daf358269ae7..9cef0e9294abb 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1603,6 +1603,7 @@ void __meminit __free_pages_core(struct page *page, unsigned int order,
>  			VM_WARN_ON_ONCE(PageReserved(p));
>  			__ClearPageOffline(p);
>  			set_page_count(p, 0);
> +			clear_page_tag_ref(p);
>  		}
>  
>  		adjust_managed_page_count(page, nr_pages);

[Severity: Medium]
Should clear_page_tag_ref() be called once on page outside the per-page
loop (and for both MEMINIT_HOTPLUG and MEMINIT_EARLY contexts) rather than
on every p inside the MEMINIT_HOTPLUG loop?

Under CONFIG_MEM_ALLOC_PROFILING_DEBUG, clear_page_tag_ref(p) sets the
page's tag reference to CODETAG_EMPTY (or CODETAG_ID_EMPTY when compressed
profiling is enabled) rather than NULL. When __free_pages_core() calls
__free_pages_ok() -> __free_pages_prepare(), only the first page's marker
is consumed and reset back to NULL:

mm/page_alloc.c:__free_pages_prepare()
    pgalloc_tag_sub(page, 1 << order);
        alloc_tag_sub(ref, bytes)
            if (is_codetag_empty(ref)) {
                ref->ct = NULL;
                return;
            }

Calling clear_page_tag_ref(p) on all nr_pages leaves CODETAG_EMPTY set on
the remaining (1 << order) - 1 tail pages in the buddy allocator. If one of
those pages is later allocated without a tag (for example via an _noprof
allocation where current->alloc_tag is NULL) and subsequently freed, the
leftover CODETAG_EMPTY marker prevents alloc_tag_sub_check() from warning.
Other callers such as init_cma_reserved_pageblock() and
memblock_free_pages() only call clear_page_tag_ref(page) on the head page:

mm/mm_init.c:init_cma_reserved_pageblock() {
    do {
        __ClearPageReserved(p);
        set_page_count(p, 0);
    } while (++p, --i);
    ...
    /* pages were reserved and not allocated */
    clear_page_tag_ref(page);
    __free_pages(page, pageblock_order);
}

In addition, placing clear_page_tag_ref() only in the MEMINIT_HOTPLUG
branch misses MEMINIT_EARLY callers of __free_pages_core() that run after
allocation tag references are initialized and do not call
clear_page_tag_ref() themselves, such as deferred_free_pages() in
mm/mm_init.c (when compressed profiling is enabled) and do_collection() in
mm/kmsan/init.c (where KMSAN intercepts pages in memblock_free_pages()
before clear_page_tag_ref(page) and releases them later via
__free_pages_core(..., MEMINIT_EARLY)).

เครดิต

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261020161053.59879-1-zenghui.yu@linux.dev?part=1


      reply	other threads:[~2026-10-21 16:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 16:10 [PATCH] mm/page_alloc: clear page tag refs when onlining hotplugged memory Zenghui Yu
2026-10-21 16:11 ` sashiko-bot [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=sashiko-outbox-180460@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.jackman@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=zenghui.yu@linux.dev \
    --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