From: Harry Yoo <harry.yoo@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Christoph Lameter <cl@linux.com>,
David Rientjes <rientjes@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Matthew Wilcox <willy@infradead.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mm, slab: use frozen pages for large kmalloc
Date: Fri, 30 May 2025 13:17:36 +0900 [thread overview]
Message-ID: <aDkxYOmMlpOl6xat@hyeyoo> (raw)
In-Reply-To: <20250529-frozen-pages-for-large-kmalloc-v1-1-b3aa52a8fa17@suse.cz>
On Thu, May 29, 2025 at 10:56:26AM +0200, Vlastimil Babka wrote:
> Since slab pages are now frozen, it makes sense to have large kmalloc()
> objects behave same as small kmalloc(), as the choice between the two is
> an implementation detail depending on allocation size.
>
> Notably, increasing refcount on a slab page containing kmalloc() object
> is not possible anymore, so it should be consistent for large kmalloc
> pages.
>
> Therefore, change large kmalloc to use the frozen pages API.
>
> Because of some unexpected fallout in the slab pages case (see commit
> b9c0e49abfca ("mm: decline to manipulate the refcount on a slab page"),
> implement the same kind of checks and warnings as part of this change.
>
> Notably, networking code using sendpage_ok() to determine whether the
> page refcount can be manipulated in the network stack should continue
> behaving correctly. Before this change, the function returns true for
> large kmalloc pages and page refcount can be manipulated. After this
> change, the function will return false.
>
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
Acked-by: Harry Yoo <harry.yoo@oracle.com>
--
Cheers,
Harry / Hyeonggon
> include/linux/mm.h | 4 +++-
> mm/slub.c | 7 +++++--
> 2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index bf55206935c467f7508e863332063bb15f904a24..d3eb6adf9fa949fbd611470182a03c743b16aac7 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1549,6 +1549,8 @@ static inline void get_page(struct page *page)
> struct folio *folio = page_folio(page);
> if (WARN_ON_ONCE(folio_test_slab(folio)))
> return;
> + if (WARN_ON_ONCE(folio_test_large_kmalloc(folio)))
> + return;
> folio_get(folio);
> }
>
> @@ -1643,7 +1645,7 @@ static inline void put_page(struct page *page)
> {
> struct folio *folio = page_folio(page);
>
> - if (folio_test_slab(folio))
> + if (folio_test_slab(folio) || folio_test_large_kmalloc(folio))
> return;
>
> folio_put(folio);
> diff --git a/mm/slub.c b/mm/slub.c
> index dc9e729e1d269b5d362cb5bc44f824640ffd00f3..d7a62063a1676a327e13536bf724f0160f1fc8dc 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -4281,8 +4281,11 @@ static void *___kmalloc_large_node(size_t size, gfp_t flags, int node)
> if (unlikely(flags & GFP_SLAB_BUG_MASK))
> flags = kmalloc_fix_flags(flags);
>
> + if (node == NUMA_NO_NODE)
> + node = numa_mem_id();
> +
> flags |= __GFP_COMP;
> - folio = (struct folio *)alloc_pages_node_noprof(node, flags, order);
> + folio = (struct folio *)__alloc_frozen_pages_noprof(flags, order, node, NULL);
> if (folio) {
> ptr = folio_address(folio);
> lruvec_stat_mod_folio(folio, NR_SLAB_UNRECLAIMABLE_B,
> @@ -4778,7 +4781,7 @@ static void free_large_kmalloc(struct folio *folio, void *object)
> lruvec_stat_mod_folio(folio, NR_SLAB_UNRECLAIMABLE_B,
> -(PAGE_SIZE << order));
> __folio_clear_large_kmalloc(folio);
> - folio_put(folio);
> + free_frozen_pages(&folio->page, order);
> }
>
> /*
>
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-05-30 4:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-29 8:56 [PATCH 0/2] " Vlastimil Babka
2025-05-29 8:56 ` [PATCH 1/2] mm, slab: use " Vlastimil Babka
2025-05-29 15:46 ` Roman Gushchin
2025-05-30 16:59 ` Matthew Wilcox
2025-05-30 4:17 ` Harry Yoo [this message]
2025-05-29 8:56 ` [PATCH 2/2] mm, slab: support NUMA policy " Vlastimil Babka
2025-05-29 14:57 ` Christoph Lameter (Ampere)
2025-05-29 15:59 ` Vlastimil Babka
2025-05-30 19:05 ` Christoph Lameter (Ampere)
2025-06-02 8:24 ` Vlastimil Babka
2025-05-30 7:11 ` Harry Yoo
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=aDkxYOmMlpOl6xat@hyeyoo \
--to=harry.yoo@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@suse.cz \
--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