From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>, Hao Ge <hao.ge@linux.dev>,
Vlastimil Babka <vbabka@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <brendan.jackman@linux.dev>,
Zi Yan <ziy@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>,
Usama Arif <usamaarif642@gmail.com>,
Shakeel Butt <shakeel.butt@linux.dev>,
Harry Yoo <harry@kernel.org>, Hao Li <hao.li@linux.dev>,
Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>
Cc: linux-mm@kvack.org, "David Hildenbrand (Arm)" <david@kernel.org>
Subject: [PATCH 3/3] mempool: account the element array to the caller
Date: Thu, 19 Nov 2026 09:52:22 +0100 [thread overview]
Message-ID: <20261119-alloc_tag-v1-3-efcccfd3a9c9@kernel.org> (raw)
In-Reply-To: <20261119-alloc_tag-v1-0-efcccfd3a9c9@kernel.org>
mempool_create_node() accounts the struct mempool and all elements to
the caller, but the array of element pointers allocated by
mempool_init_node() and mempool_resize() ends up being accounted to
mm/mempool.c in /proc/allocinfo.
Let's consistently account all mempool allocations to the caller, like
ptr_ring_init() and ptr_ring_resize() do, by using the _noprof variants.
mempool_init_node() is only called from mempool_init_noprof() and
mempool_create_node_noprof(), which already set the allocation tag.
While at it, make mempool_init_node() static and rename it to
mempool_init_node_noprof(): it is not used outside of mm/mempool.c, and
calling it without an allocation tag would be wrong.
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
include/linux/mempool.h | 3 ---
mm/mempool.c | 19 ++++++++++---------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/include/linux/mempool.h b/include/linux/mempool.h
index 5444dcb63efa8..7f8e257017c01 100644
--- a/include/linux/mempool.h
+++ b/include/linux/mempool.h
@@ -38,9 +38,6 @@ static inline bool mempool_is_saturated(struct mempool *pool)
}
void mempool_exit(struct mempool *pool);
-int mempool_init_node(struct mempool *pool, int min_nr,
- mempool_alloc_t *alloc_fn, mempool_free_t *free_fn,
- void *pool_data, gfp_t gfp_mask, int node_id);
int mempool_init_noprof(struct mempool *pool, int min_nr,
mempool_alloc_t *alloc_fn, mempool_free_t *free_fn,
void *pool_data);
diff --git a/mm/mempool.c b/mm/mempool.c
index 5e0ba516efdbf..30cbe44d464b3 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -243,7 +243,7 @@ void mempool_destroy(struct mempool *pool)
}
EXPORT_SYMBOL(mempool_destroy);
-int mempool_init_node(struct mempool *pool, int min_nr,
+static int mempool_init_node_noprof(struct mempool *pool, int min_nr,
mempool_alloc_t *alloc_fn, mempool_free_t *free_fn,
void *pool_data, gfp_t gfp_mask, int node_id)
{
@@ -257,8 +257,9 @@ int mempool_init_node(struct mempool *pool, int min_nr,
* max() used here to ensure storage for at least 1 element to support
* zero minimum pool
*/
- pool->elements = kmalloc_array_node(max(1, min_nr), sizeof(void *),
- gfp_mask, node_id);
+ pool->elements = kmalloc_array_node_noprof(max(1, min_nr),
+ sizeof(void *), gfp_mask,
+ node_id);
if (!pool->elements)
return -ENOMEM;
@@ -279,7 +280,6 @@ int mempool_init_node(struct mempool *pool, int min_nr,
return 0;
}
-EXPORT_SYMBOL(mempool_init_node);
/**
* mempool_init - initialize a memory pool
@@ -299,8 +299,8 @@ int mempool_init_noprof(struct mempool *pool, int min_nr,
mempool_alloc_t *alloc_fn, mempool_free_t *free_fn,
void *pool_data)
{
- return mempool_init_node(pool, min_nr, alloc_fn, free_fn,
- pool_data, GFP_KERNEL, NUMA_NO_NODE);
+ return mempool_init_node_noprof(pool, min_nr, alloc_fn, free_fn,
+ pool_data, GFP_KERNEL, NUMA_NO_NODE);
}
EXPORT_SYMBOL(mempool_init_noprof);
@@ -333,8 +333,8 @@ struct mempool *mempool_create_node_noprof(int min_nr,
if (!pool)
return NULL;
- if (mempool_init_node(pool, min_nr, alloc_fn, free_fn, pool_data,
- gfp_mask, node_id)) {
+ if (mempool_init_node_noprof(pool, min_nr, alloc_fn, free_fn,
+ pool_data, gfp_mask, node_id)) {
kfree(pool);
return NULL;
}
@@ -384,7 +384,8 @@ int mempool_resize_noprof(struct mempool *pool, int new_min_nr)
spin_unlock_irqrestore(&pool->lock, flags);
/* Grow the pool */
- new_elements = kmalloc_objs(*new_elements, new_min_nr);
+ new_elements = kmalloc_array_noprof(new_min_nr, sizeof(*new_elements),
+ GFP_KERNEL);
if (!new_elements)
return -ENOMEM;
--
2.56.1
prev parent reply other threads:[~2026-11-19 8:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:52 [PATCH 0/3] alloc_tag: two fixes and one cleanup David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 1/3] alloc_tag: handle a NULL tag in alloc_tag_set_inaccurate() David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 2/3] mempool: fix missing alloc tagging in mempool_resize() David Hildenbrand (Arm)
2026-11-19 8:52 ` David Hildenbrand (Arm) [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=20261119-alloc_tag-v1-3-efcccfd3a9c9@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=cl@gentwo.org \
--cc=hannes@cmpxchg.org \
--cc=hao.ge@linux.dev \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=usamaarif642@gmail.com \
--cc=vbabka@kernel.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