Re: [PATCH slab/for-next v2 04/14] fs/buffer: specify SLAB_MAY_ACCOUNT for buffer_head cache

From: Jan Kara

Date: Thu Nov 26 2026 - 04:05:55 EST


On Wed 25-11-26 21:37:05, Harry Yoo (Meta) wrote:
> Buffer heads are allocated with __GFP_ACCOUNT to charge them to the
> memcg of the folio they are attached to. Specify SLAB_MAY_ACCOUNT when
> the object may be charged to a memcg. __GFP_ACCOUNT without
> SLAB_MAY_ACCOUNT will not be allowed.
>
> Path: ext4_getblk() -> folio_alloc_buffers(GFP_NOFS | __GFP_ACCOUNT)
> -> alloc_buffer_head() -> kmem_cache_zalloc(bh_cachep)
>
> Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
> Cc: Christian Brauner <brauner@xxxxxxxxxx>
> Cc: Jan Kara <jack@xxxxxxx>
> Cc: linux-fsdevel@xxxxxxxxxxxxxxx
> Signed-off-by: Harry Yoo (Meta) <harry@xxxxxxxxxx>

Looks good. Feel free to add:

Acked-by: Jan Kara <jack@xxxxxxx>

Honza

> ---
> fs/buffer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/buffer.c b/fs/buffer.c
> index f951559e7d32..4c24f4546106 100644
> --- a/fs/buffer.c
> +++ b/fs/buffer.c
> @@ -3006,7 +3006,7 @@ void __init buffer_init(void)
> int ret;
>
> bh_cachep = KMEM_CACHE(buffer_head,
> - SLAB_RECLAIM_ACCOUNT|SLAB_PANIC);
> + SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MAY_ACCOUNT);
> /*
> * Limit the bh occupancy to 10% of ZONE_NORMAL
> */
>
> --
> 2.54.0
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR