* [PATCH slab/for-next v2 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches
2026-11-25 21:37 [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata Harry Yoo (Meta)
@ 2026-11-25 21:37 ` Harry Yoo (Meta)
2026-11-27 13:35 ` Niklas Schnelle
2026-12-03 14:59 ` Hao Li
2026-11-26 11:10 ` [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata sashiko-bot
` (3 subsequent siblings)
4 siblings, 2 replies; 9+ messages in thread
From: Harry Yoo (Meta) @ 2026-11-25 21:37 UTC (permalink / raw)
To: Vlastimil Babka, Andrew Morton, Suren Baghdasaryan,
Johannes Weiner, Michal Hocko, Shakeel Butt, Roman Gushchin
Cc: Hao Li, Christoph Lameter, David Rientjes, Muchun Song, Hao Ge,
Pedro Falcato, linux-mm, linux-kernel, kernel-team,
Harry Yoo (Meta), Liam R. Howlett, Alice Ryhl, Andrew Ballance,
Matthew Wilcox, linux-fsdevel, Alexander Viro, Christian Brauner,
Jan Kara, David S. Miller, Jakub Kicinski,
Sebastian Andrzej Siewior, Jiayuan Chen, netdev, Kees Cook,
David Hildenbrand, Lorenzo Stoakes, Catalin Marinas, Will Deacon,
Mark Rutland, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Robin Murphy, Joerg Roedel (AMD), Amir Goldstein,
Casey Schaufler, Paul Moore, James Morris, Serge E. Hallyn,
linux-security-module, Richard Weinberger, Anton Ivanov,
Johannes Berg, Eric Dumazet, Niklas Schnelle, Matthew Rosato,
Gerald Schaefer, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
linux-arm-kernel, iommu, linux-s390, linux-sunxi
vfio, iommufd and vhost-vdpa call iommu_map() with GFP_KERNEL_ACCOUNT
and the gfp is passed down to the drivers' page table allocations.
Specify SLAB_MAY_ACCOUNT when the object may be charged to a memcg.
__GFP_ACCOUNT without SLAB_MAY_ACCOUNT will not be allowed.
Paths:
VFIO_IOMMU_MAP_DMA -> iommu_map(GFP_KERNEL_ACCOUNT)
-> s390_iommu_map_pages() -> dma_walk_cpu_trans()
-> kmem_cache_alloc(dma_{region,page}_table_cache)
iommu_map(GFP_KERNEL_ACCOUNT) -> arm_v7s_map_pages()
-> __arm_v7s_alloc_table() -> kmem_cache_zalloc(data->l2_tables)
iommu_map(GFP_KERNEL_ACCOUNT) -> sun50i_iommu_map()
-> sun50i_dte_get_page_table() -> kmem_cache_zalloc(iommu->pt_pool)
Cc: Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: "Joerg Roedel (AMD)" <joro@8bytes.org>
Cc: Niklas Schnelle <schnelle@linux.ibm.com>
Cc: Matthew Rosato <mjrosato@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Chen-Yu Tsai <wens@kernel.org>
Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
Cc: Samuel Holland <samuel@sholland.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: iommu@lists.linux.dev
Cc: linux-s390@vger.kernel.org
Cc: linux-sunxi@lists.linux.dev
Signed-off-by: Harry Yoo (Meta) <harry@kernel.org>
---
drivers/iommu/io-pgtable-arm-v7s.c | 2 +-
drivers/iommu/s390-iommu.c | 4 ++--
drivers/iommu/sun50i-iommu.c | 3 ++-
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c
index 1dbef8c55007..b544e5da237a 100644
--- a/drivers/iommu/io-pgtable-arm-v7s.c
+++ b/drivers/iommu/io-pgtable-arm-v7s.c
@@ -706,7 +706,7 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg,
data->l2_tables = kmem_cache_create("io-pgtable_armv7s_l2",
ARM_V7S_TABLE_SIZE(2, cfg),
ARM_V7S_TABLE_SIZE(2, cfg),
- slab_flag, NULL);
+ slab_flag | SLAB_MAY_ACCOUNT, NULL);
if (!data->l2_tables)
goto out_free_data;
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index a280ad4f63b7..467b97ec18dc 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -198,14 +198,14 @@ static int __init dma_alloc_cpu_table_caches(void)
dma_region_table_cache = kmem_cache_create("PCI_DMA_region_tables",
ZPCI_TABLE_SIZE,
ZPCI_TABLE_ALIGN,
- 0, NULL);
+ SLAB_MAY_ACCOUNT, NULL);
if (!dma_region_table_cache)
return -ENOMEM;
dma_page_table_cache = kmem_cache_create("PCI_DMA_page_tables",
ZPCI_PT_SIZE,
ZPCI_PT_ALIGN,
- 0, NULL);
+ SLAB_MAY_ACCOUNT, NULL);
if (!dma_page_table_cache) {
kmem_cache_destroy(dma_region_table_cache);
return -ENOMEM;
diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c
index acdccb7c9eef..604a357cc1fb 100644
--- a/drivers/iommu/sun50i-iommu.c
+++ b/drivers/iommu/sun50i-iommu.c
@@ -1011,7 +1011,8 @@ static int sun50i_iommu_probe(struct platform_device *pdev)
iommu->pt_pool = kmem_cache_create(dev_name(&pdev->dev),
PT_SIZE, PT_SIZE,
- SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA32,
+ SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA32 |
+ SLAB_MAY_ACCOUNT,
NULL);
if (!iommu->pt_pool)
return -ENOMEM;
--
2.54.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH slab/for-next v2 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches
2026-11-25 21:37 ` [PATCH slab/for-next v2 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches Harry Yoo (Meta)
@ 2026-11-27 13:35 ` Niklas Schnelle
2026-12-03 14:59 ` Hao Li
1 sibling, 0 replies; 9+ messages in thread
From: Niklas Schnelle @ 2026-11-27 13:35 UTC (permalink / raw)
To: Harry Yoo (Meta), Vlastimil Babka, Andrew Morton,
Suren Baghdasaryan, Johannes Weiner, Michal Hocko, Shakeel Butt,
Roman Gushchin
Cc: Hao Li, Christoph Lameter, David Rientjes, Muchun Song, Hao Ge,
Pedro Falcato, linux-mm, linux-kernel, kernel-team,
Liam R. Howlett, Alice Ryhl, Andrew Ballance, Matthew Wilcox,
linux-fsdevel, Alexander Viro, Christian Brauner, Jan Kara,
David S. Miller, Jakub Kicinski, Sebastian Andrzej Siewior,
Jiayuan Chen, netdev, Kees Cook, David Hildenbrand,
Lorenzo Stoakes, Catalin Marinas, Will Deacon, Mark Rutland,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Robin Murphy, Joerg Roedel (AMD), Amir Goldstein, Casey Schaufler,
Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
Richard Weinberger, Anton Ivanov, Johannes Berg, Eric Dumazet,
Matthew Rosato, Gerald Schaefer, Chen-Yu Tsai, Jernej Skrabec,
Samuel Holland, linux-arm-kernel, iommu, linux-s390, linux-sunxi
On Wed, 2026-11-25 at 21:37 +0000, Harry Yoo (Meta) wrote:
> vfio, iommufd and vhost-vdpa call iommu_map() with GFP_KERNEL_ACCOUNT
> and the gfp is passed down to the drivers' page table allocations.
> Specify SLAB_MAY_ACCOUNT when the object may be charged to a memcg.
> __GFP_ACCOUNT without SLAB_MAY_ACCOUNT will not be allowed.
>
> Paths:
> VFIO_IOMMU_MAP_DMA -> iommu_map(GFP_KERNEL_ACCOUNT)
> -> s390_iommu_map_pages() -> dma_walk_cpu_trans()
> -> kmem_cache_alloc(dma_{region,page}_table_cache)
> iommu_map(GFP_KERNEL_ACCOUNT) -> arm_v7s_map_pages()
> -> __arm_v7s_alloc_table() -> kmem_cache_zalloc(data->l2_tables)
> iommu_map(GFP_KERNEL_ACCOUNT) -> sun50i_iommu_map()
> -> sun50i_dte_get_page_table() -> kmem_cache_zalloc(iommu->pt_pool)
>
> Cc: Will Deacon <will@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: "Joerg Roedel (AMD)" <joro@8bytes.org>
> Cc: Niklas Schnelle <schnelle@linux.ibm.com>
> Cc: Matthew Rosato <mjrosato@linux.ibm.com>
> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
> Cc: Chen-Yu Tsai <wens@kernel.org>
> Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
> Cc: Samuel Holland <samuel@sholland.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: iommu@lists.linux.dev
> Cc: linux-s390@vger.kernel.org
> Cc: linux-sunxi@lists.linux.dev
> Signed-off-by: Harry Yoo (Meta) <harry@kernel.org>
> ---
> drivers/iommu/io-pgtable-arm-v7s.c | 2 +-
> drivers/iommu/s390-iommu.c | 4 ++--
> drivers/iommu/sun50i-iommu.c | 3 ++-
> 3 files changed, 5 insertions(+), 4 deletions(-)
--- snip ---
> index a280ad4f63b7..467b97ec18dc 100644
> --- a/drivers/iommu/s390-iommu.c
> +++ b/drivers/iommu/s390-iommu.c
> @@ -198,14 +198,14 @@ static int __init dma_alloc_cpu_table_caches(void)
> dma_region_table_cache = kmem_cache_create("PCI_DMA_region_tables",
> ZPCI_TABLE_SIZE,
> ZPCI_TABLE_ALIGN,
> - 0, NULL);
> + SLAB_MAY_ACCOUNT, NULL);
> if (!dma_region_table_cache)
> return -ENOMEM;
>
> dma_page_table_cache = kmem_cache_create("PCI_DMA_page_tables",
> ZPCI_PT_SIZE,
> ZPCI_PT_ALIGN,
> - 0, NULL);
> + SLAB_MAY_ACCOUNT, NULL);
> if (!dma_page_table_cache) {
> kmem_cache_destroy(dma_region_table_cache);
> return -ENOMEM;
Looks good and the explanation makes sense to me. Thanks.
Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com> # s390-iommu
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH slab/for-next v2 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches
2026-11-25 21:37 ` [PATCH slab/for-next v2 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches Harry Yoo (Meta)
2026-11-27 13:35 ` Niklas Schnelle
@ 2026-12-03 14:59 ` Hao Li
1 sibling, 0 replies; 9+ messages in thread
From: Hao Li @ 2026-12-03 14:59 UTC (permalink / raw)
To: Harry Yoo (Meta)
Cc: Vlastimil Babka, Andrew Morton, Suren Baghdasaryan,
Johannes Weiner, Michal Hocko, Shakeel Butt, Roman Gushchin,
Christoph Lameter, David Rientjes, Muchun Song, Hao Ge,
Pedro Falcato, linux-mm, linux-kernel, kernel-team,
Liam R. Howlett, Alice Ryhl, Andrew Ballance, Matthew Wilcox,
linux-fsdevel, Alexander Viro, Christian Brauner, Jan Kara,
David S. Miller, Jakub Kicinski, Sebastian Andrzej Siewior,
Jiayuan Chen, netdev, Kees Cook, David Hildenbrand,
Lorenzo Stoakes, Catalin Marinas, Will Deacon, Mark Rutland,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Robin Murphy, Joerg Roedel (AMD), Amir Goldstein, Casey Schaufler,
Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
Richard Weinberger, Anton Ivanov, Johannes Berg, Eric Dumazet,
Niklas Schnelle, Matthew Rosato, Gerald Schaefer, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, linux-arm-kernel, iommu,
linux-s390, linux-sunxi
On Wed, Nov 25, 2026 at 09:37:10PM +0000, Harry Yoo (Meta) wrote:
> vfio, iommufd and vhost-vdpa call iommu_map() with GFP_KERNEL_ACCOUNT
> and the gfp is passed down to the drivers' page table allocations.
> Specify SLAB_MAY_ACCOUNT when the object may be charged to a memcg.
> __GFP_ACCOUNT without SLAB_MAY_ACCOUNT will not be allowed.
>
> Paths:
> VFIO_IOMMU_MAP_DMA -> iommu_map(GFP_KERNEL_ACCOUNT)
> -> s390_iommu_map_pages() -> dma_walk_cpu_trans()
> -> kmem_cache_alloc(dma_{region,page}_table_cache)
> iommu_map(GFP_KERNEL_ACCOUNT) -> arm_v7s_map_pages()
> -> __arm_v7s_alloc_table() -> kmem_cache_zalloc(data->l2_tables)
> iommu_map(GFP_KERNEL_ACCOUNT) -> sun50i_iommu_map()
> -> sun50i_dte_get_page_table() -> kmem_cache_zalloc(iommu->pt_pool)
>
> Cc: Will Deacon <will@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: "Joerg Roedel (AMD)" <joro@8bytes.org>
> Cc: Niklas Schnelle <schnelle@linux.ibm.com>
> Cc: Matthew Rosato <mjrosato@linux.ibm.com>
> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
> Cc: Chen-Yu Tsai <wens@kernel.org>
> Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
> Cc: Samuel Holland <samuel@sholland.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: iommu@lists.linux.dev
> Cc: linux-s390@vger.kernel.org
> Cc: linux-sunxi@lists.linux.dev
> Signed-off-by: Harry Yoo (Meta) <harry@kernel.org>
> ---
> drivers/iommu/io-pgtable-arm-v7s.c | 2 +-
> drivers/iommu/s390-iommu.c | 4 ++--
> drivers/iommu/sun50i-iommu.c | 3 ++-
> 3 files changed, 5 insertions(+), 4 deletions(-)
Looks good to me.
Reviewed-by: Hao Li <hao.li@linux.dev>
--
Thanks,
Hao
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata
2026-11-25 21:37 [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata Harry Yoo (Meta)
2026-11-25 21:37 ` [PATCH slab/for-next v2 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches Harry Yoo (Meta)
@ 2026-11-26 11:10 ` sashiko-bot
2026-11-26 15:24 ` Shakeel Butt
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26 11:10 UTC (permalink / raw)
To: Harry Yoo (Meta)
Cc: linux-security-module, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger
Sashiko has finished reviewing this 14-patch series:
- Patches 1-13: no issues found.
- Patch 14 ("mm/slab: do not set SLAB_MAY_ACCOUNT for all caches"): 1
potential issue (1 Low)
A detailed review has been sent as a separate reply to patch 14.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-memalloc-prof-dont-waste-slabobj-ext-metadata-v2-0-7c680f02a734@kernel.org
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata
2026-11-25 21:37 [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata Harry Yoo (Meta)
2026-11-25 21:37 ` [PATCH slab/for-next v2 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches Harry Yoo (Meta)
2026-11-26 11:10 ` [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata sashiko-bot
@ 2026-11-26 15:24 ` Shakeel Butt
2026-11-29 5:16 ` Chris Down
2026-12-03 15:08 ` Harry Yoo
4 siblings, 0 replies; 9+ messages in thread
From: Shakeel Butt @ 2026-11-26 15:24 UTC (permalink / raw)
To: Harry Yoo (Meta)
Cc: Vlastimil Babka, Andrew Morton, Suren Baghdasaryan,
Johannes Weiner, Michal Hocko, Roman Gushchin, Hao Li,
Christoph Lameter, David Rientjes, Muchun Song, Hao Ge,
Pedro Falcato, linux-mm, linux-kernel, kernel-team,
Liam R. Howlett, Alice Ryhl, Andrew Ballance, Matthew Wilcox,
linux-fsdevel, Alexander Viro, Christian Brauner, Jan Kara,
David S. Miller, Jakub Kicinski, Sebastian Andrzej Siewior,
Jiayuan Chen, netdev, Kees Cook, David Hildenbrand,
Lorenzo Stoakes, Catalin Marinas, Will Deacon, Mark Rutland,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Robin Murphy, Joerg Roedel (AMD), Amir Goldstein, Casey Schaufler,
Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
Richard Weinberger, Anton Ivanov, Johannes Berg, Eric Dumazet,
maple-tree, Paolo Abeni, Simon Horman, Jason Xing,
Willem de Bruijn, Mina Almasry, Björn Töpel,
Mike Rapoport, Michal Hocko, Ingo Molnar, Peter Zijlstra,
Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
Anshuman Khandual, linux-arm-kernel, Christophe Leroy (CS GROUP),
linuxppc-dev, Niklas Schnelle, Matthew Rosato, Gerald Schaefer,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, iommu, linux-s390,
linux-sunxi, linux-um, cgroups
On Wed, Nov 25, 2026 at 09:37:01PM +0000, Harry Yoo (Meta) wrote:
> TL;DR
> -----
>
> The purpose of this series is to convert existing slab users that
> specify __GFP_ACCOUNT on allocations to specify SLAB_MAY_ACCOUNT on
> cache creation, to reduce memory waste for slab metadata with
> CONFIG_MEMCG=y && CONFIG_MEM_ALLOC_PROFILING=y.
>
[...]
>
> Signed-off-by: Harry Yoo (Meta) <harry@kernel.org>
For the series:
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata
2026-11-25 21:37 [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata Harry Yoo (Meta)
` (2 preceding siblings ...)
2026-11-26 15:24 ` Shakeel Butt
@ 2026-11-29 5:16 ` Chris Down
2026-12-03 14:22 ` Harry Yoo
2026-12-03 15:08 ` Harry Yoo
4 siblings, 1 reply; 9+ messages in thread
From: Chris Down @ 2026-11-29 5:16 UTC (permalink / raw)
To: Harry Yoo (Meta)
Cc: Vlastimil Babka, Andrew Morton, Suren Baghdasaryan,
Johannes Weiner, Michal Hocko, Shakeel Butt, Roman Gushchin,
Hao Li, Christoph Lameter, David Rientjes, Muchun Song, Hao Ge,
Pedro Falcato, linux-mm, linux-kernel, kernel-team,
Liam R. Howlett, Alice Ryhl, Andrew Ballance, Matthew Wilcox,
linux-fsdevel, Alexander Viro, Christian Brauner, Jan Kara,
David S. Miller, Jakub Kicinski, Sebastian Andrzej Siewior,
Jiayuan Chen, netdev, Kees Cook, David Hildenbrand,
Lorenzo Stoakes, Catalin Marinas, Will Deacon, Mark Rutland,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Robin Murphy, Joerg Roedel (AMD), Amir Goldstein, Casey Schaufler,
Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
Richard Weinberger, Anton Ivanov, Johannes Berg, Eric Dumazet,
maple-tree, Paolo Abeni, Simon Horman, Jason Xing,
Willem de Bruijn, Mina Almasry, Björn Töpel,
Mike Rapoport, Michal Hocko, Ingo Molnar, Peter Zijlstra,
Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
Anshuman Khandual, linux-arm-kernel, Christophe Leroy (CS GROUP),
linuxppc-dev, Niklas Schnelle, Matthew Rosato, Gerald Schaefer,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, iommu, linux-s390,
linux-sunxi, linux-um, cgroups
Hi Harry,
Harry Yoo (Meta) writes:
>While I tried to make sure the sweep is exhaustive, there can be a
>missing conversion. However that is not a correctness problem:
>the objects are just no longer charged to memcgs. Patch 13 adds
>VM_WARN_ON_ONCE in __memcg_slab_post_alloc_hook() to catch such a
>missing conversion.
This series looks good, thank you. But in terms of documentation, I
think we are a little bit light on where the SLAB_MAY_ACCOUNT
requirement is written down. Right now it's only written next to
SLAB_MAY_ACCOUNT in slab.h, but with that it's likely that people
adding __GFP_ACCOUNT won't see it. Could you also perhaps put it in
the __GFP_ACCOUNT comment in gfp_types.h and in
Documentation/core-api/memory-allocation.rst, which both still describe
__GFP_ACCOUNT as enough on its own? The comment above kmem_cache_charge()
also still says that only KMALLOC_NORMAL objects are skipped, so that
could be fixed in patch 14 as well.
I wouldn't block on that, but it would be good to improve this. I've
looked through these and am happy with them, and have tested where
possible so you can add:
Reviewed-by: Chris Down <chris@chrisdown.name>
For patches 1, 13 and 14:
Tested-by: Chris Down <chris@chrisdown.name>
Chris
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata
2026-11-29 5:16 ` Chris Down
@ 2026-12-03 14:22 ` Harry Yoo
0 siblings, 0 replies; 9+ messages in thread
From: Harry Yoo @ 2026-12-03 14:22 UTC (permalink / raw)
To: Chris Down
Cc: Vlastimil Babka, Andrew Morton, Suren Baghdasaryan,
Johannes Weiner, Michal Hocko, Shakeel Butt, Roman Gushchin,
Hao Li, Christoph Lameter, David Rientjes, Muchun Song, Hao Ge,
Pedro Falcato, linux-mm, linux-kernel, kernel-team,
Liam R. Howlett, Alice Ryhl, Andrew Ballance, Matthew Wilcox,
linux-fsdevel, Alexander Viro, Christian Brauner, Jan Kara,
David S. Miller, Jakub Kicinski, Sebastian Andrzej Siewior,
Jiayuan Chen, netdev, Kees Cook, David Hildenbrand,
Lorenzo Stoakes, Catalin Marinas, Will Deacon, Mark Rutland,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Robin Murphy, Joerg Roedel (AMD), Amir Goldstein, Casey Schaufler,
Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
Richard Weinberger, Anton Ivanov, Johannes Berg, Eric Dumazet,
maple-tree, Paolo Abeni, Simon Horman, Jason Xing,
Willem de Bruijn, Mina Almasry, Björn Töpel,
Mike Rapoport, Michal Hocko, Ingo Molnar, Peter Zijlstra,
Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
Anshuman Khandual, linux-arm-kernel, Christophe Leroy (CS GROUP),
linuxppc-dev, Niklas Schnelle, Matthew Rosato, Gerald Schaefer,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, iommu, linux-s390,
linux-sunxi, linux-um, cgroups
On Sat, Nov 28, 2026 at 09:16:29PM -0800, Chris Down wrote:
> Hi Harry,
Hi Chris,
> Harry Yoo (Meta) writes:
> >While I tried to make sure the sweep is exhaustive, there can be a
> >missing conversion. However that is not a correctness problem:
> >the objects are just no longer charged to memcgs. Patch 13 adds
> >VM_WARN_ON_ONCE in __memcg_slab_post_alloc_hook() to catch such a
> >missing conversion.
>
> This series looks good, thank you. But in terms of documentation, I
> think we are a little bit light on where the SLAB_MAY_ACCOUNT
> requirement is written down. Right now it's only written next to
> SLAB_MAY_ACCOUNT in slab.h, but with that it's likely that people
> adding __GFP_ACCOUNT won't see it.
Good point!
> Could you also perhaps put it in
> the __GFP_ACCOUNT comment in gfp_types.h and in
> Documentation/core-api/memory-allocation.rst, which both still describe
> __GFP_ACCOUNT as enough on its own? The comment above kmem_cache_charge()
> also still says that only KMALLOC_NORMAL objects are skipped, so that
> could be fixed in patch 14 as well.
Ack, I'll adjust the docs part.
> I wouldn't block on that, but it would be good to improve this. I've
> looked through these and am happy with them, and have tested where
> possible so you can add:
>
> Reviewed-by: Chris Down <chris@chrisdown.name>
(Assuming this is for all patches 1-14)
> For patches 1, 13 and 14:
>
> Tested-by: Chris Down <chris@chrisdown.name>
>
> Chris
Thanks a lot for reviewing and testing, Chris!
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata
2026-11-25 21:37 [PATCH slab/for-next v2 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata Harry Yoo (Meta)
` (3 preceding siblings ...)
2026-11-29 5:16 ` Chris Down
@ 2026-12-03 15:08 ` Harry Yoo
4 siblings, 0 replies; 9+ messages in thread
From: Harry Yoo @ 2026-12-03 15:08 UTC (permalink / raw)
To: Vlastimil Babka, Andrew Morton, Suren Baghdasaryan,
Johannes Weiner, Michal Hocko, Shakeel Butt, Roman Gushchin
Cc: Hao Li, Christoph Lameter, David Rientjes, Muchun Song, Hao Ge,
Pedro Falcato, linux-mm, linux-kernel, kernel-team,
Liam R. Howlett, Alice Ryhl, Andrew Ballance, Matthew Wilcox,
linux-fsdevel, Alexander Viro, Christian Brauner, Jan Kara,
David S. Miller, Jakub Kicinski, Sebastian Andrzej Siewior,
Jiayuan Chen, netdev, Kees Cook, David Hildenbrand,
Lorenzo Stoakes, Catalin Marinas, Will Deacon, Mark Rutland,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Robin Murphy, Joerg Roedel (AMD), Amir Goldstein, Casey Schaufler,
Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
Richard Weinberger, Anton Ivanov, Johannes Berg, Eric Dumazet,
maple-tree, Paolo Abeni, Simon Horman, Jason Xing,
Willem de Bruijn, Mina Almasry, Björn Töpel,
Mike Rapoport, Michal Hocko, Ingo Molnar, Peter Zijlstra,
Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
Anshuman Khandual, linux-arm-kernel, Christophe Leroy (CS GROUP),
linuxppc-dev, Niklas Schnelle, Matthew Rosato, Gerald Schaefer,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, iommu, linux-s390,
linux-sunxi, linux-um, cgroups
Thank you for the all ACKs and reviews, folks!
I feel this is almost ready for mainline but given that we're already
reaching -rc6 soon I guess it should target v7.6. I will give it a
couple of weeks and post v3.
--
Cheers,
Harry / Hyeonggon
On Wed, Nov 25, 2026 at 09:37:01PM +0000, Harry Yoo (Meta) wrote:
> TL;DR
> -----
>
> The purpose of this series is to convert existing slab users that
> specify __GFP_ACCOUNT on allocations to specify SLAB_MAY_ACCOUNT on
> cache creation, to reduce memory waste for slab metadata with
> CONFIG_MEMCG=y && CONFIG_MEM_ALLOC_PROFILING=y.
>
> Longer version of the cover letter
> ----------------------------------
>
> Currently, there are two ways to charge slab objects to memory
> cgroups: 1) specify SLAB_ACCOUNT during cache creation, or 2) specify
> __GFP_ACCOUNT on allocation. The latter method made it impossible to
> assume that certain slab caches are never charged to memory cgroups.
>
> Since commit d4404b0f5b8b ("mm/slab: stop allocating objcg pointers when
> unnecessary"), slabobj_ext allocates the space for the objcg pointer
> only for caches with SLAB_MAY_ACCOUNT. However, kmem_cache_create() sets
> the flag on every cache, because any cache may be used with
> __GFP_ACCOUNT.
>
> As a result, sizeof(struct obj_cgroup *) bytes are wasted for each
> unaccounted slab object when both memalloc profiling and memcg are
> enabled. This is suboptimal when memalloc profiling is used to
> profile memory allocations on production.
>
> So, let's make memcg charging opt-in and stop wasting memory!
>
> New rule for slab users: a cache must specify SLAB_MAY_ACCOUNT
> (explicitly or implied by SLAB_ACCOUNT) for its objects to be charged
> to a memcg. Otherwise __GFP_ACCOUNT is ignored and triggers a warning on
> debug kernels (CONFIG_DEBUG_VM=y).
>
> The approach is quite straightforward, but converting all caches that
> may pass __GFP_ACCOUNT without SLAB_ACCOUNT at once is not.
> As a best-effort approach, I swept the whole tree (with help of an
> LLM) for paths that pass __GFP_ACCOUNT into slab allocations either
> directly or indirectly.
>
> While I tried to make sure the sweep is exhaustive, there can be a
> missing conversion. However that is not a correctness problem:
> the objects are just no longer charged to memcgs. Patch 13 adds
> VM_WARN_ON_ONCE in __memcg_slab_post_alloc_hook() to catch such a
> missing conversion.
>
> Patch 1 allows passing SLAB_MAY_ACCOUNT to kmem_cache_create(),
> patches 2-12 specify SLAB_MAY_ACCOUNT for the caches found by
> the sweep, and patch 14 stops setting SLAB_MAY_ACCOUNT on all caches.
>
> Memory savings and testing
> --------------------------
>
> On an idle x86 VM with both memalloc profiling and memcg enabled,
> slabobj_ext memory (the alloc_slab_obj_exts entry in /proc/allocinfo)
> drops from 1,280KB to 910KB (-29%) after boot. The savings are expected
> to be larger on real workloads, which allocate far more unaccounted slab
> objects (8 bytes per unaccounted slab object).
>
> Each tested cache was verified with the warning in patch 13:
> I confirmed that 1) the warning is triggered without the conversion,
> and 2) specifying SLAB_MAY_ACCOUNT resolves it. However I could not test
> io-pgtable_armv7s_l2 and sun50i's pt_pool caches due to lack of the
> hardware and emulation support. So they are compile-tested only.
>
> cache tested environment
> --------------------- ------ -----------------------
> radix_tree_node yes x86
> maple_node yes x86
> buffer_head yes x86
> skbuff_head_cache yes x86
> fanotify_*_event yes x86
> smack_rule yes x86
> io-pgtable_armv7s_l2 no compile-tested only
> thread_stack yes ppc64le (64K pages)
> pgd_cache (arm64) yes arm64 (64K pages)
> PGT_CACHE (powerpc) yes ppc64le
> PCI_DMA_*_tables yes s390x (zPCI + vfio)
> hostfs_inode_cache yes UML
> sun50i pt_pool no compile-tested only
>
> Signed-off-by: Harry Yoo (Meta) <harry@kernel.org>
> ---
> Changes in v2:
> - Rebased onto the latest slab/for-next.
> - Collected Acked-by from Jakub and Reviewed-by from Casey. Thanks!
> - Patch 1
> - Resolve "sysfs: cannot create duplicate filename" warning by
> encoding SLAB_MAY_ACCOUNT in create_unique_id() (kernel test robot,
> Sashiko).
> - Define SLAB_MAY_ACCOUNT in tools/include/linux/slab.h to fix
> the build of tools/testing/{radix-tree,vma} (Mike, Sashiko).
> - Swept the tree again on the new base. No new cache needs
> SLAB_MAY_ACCOUNT.
> - Re-tested all the conversions on the new base.
> - Link to v1: https://patch.msgid.link/20261021-memalloc-prof-dont-waste-slabobj-ext-metadata-v1-0-096800aa3330@kernel.org
^ permalink raw reply [flat|nested] 9+ messages in thread