Re: [PATCH slab/for-next v2 10/14] fanotify: specify SLAB_MAY_ACCOUNT for event caches
From: Jan Kara
Date: Thu Nov 26 2026 - 04:06:53 EST
On Wed 25-11-26 21:37:11, Harry Yoo (Meta) wrote:
> fanotify events are allocated with GFP_KERNEL_ACCOUNT and charged to
> the memcg of the listener. Specify SLAB_MAY_ACCOUNT when the object
> may be charged to a memcg. __GFP_ACCOUNT without SLAB_MAY_ACCOUNT
> will not be allowed.
>
> Path: fsnotify() -> fanotify_handle_event()
> -> fanotify_alloc_event(GFP_KERNEL_ACCOUNT)
> -> kmem_cache_alloc(fanotify_{fid,path,perm,mnt}_event_cachep)
>
> Cc: Jan Kara <jack@xxxxxxx>
> Cc: Amir Goldstein <amir73il@xxxxxxxxx>
> 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/notify/fanotify/fanotify_user.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 63c9759fc3b0..3575c681abc1 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -2184,14 +2184,16 @@ static int __init fanotify_user_setup(void)
> fanotify_mark_cache = KMEM_CACHE(fanotify_mark,
> SLAB_PANIC|SLAB_ACCOUNT);
> fanotify_fid_event_cachep = KMEM_CACHE(fanotify_fid_event,
> - SLAB_PANIC);
> + SLAB_PANIC|SLAB_MAY_ACCOUNT);
> fanotify_path_event_cachep = KMEM_CACHE(fanotify_path_event,
> - SLAB_PANIC);
> + SLAB_PANIC|SLAB_MAY_ACCOUNT);
> if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) {
> fanotify_perm_event_cachep =
> - KMEM_CACHE(fanotify_perm_event, SLAB_PANIC);
> + KMEM_CACHE(fanotify_perm_event,
> + SLAB_PANIC|SLAB_MAY_ACCOUNT);
> }
> - fanotify_mnt_event_cachep = KMEM_CACHE(fanotify_mnt_event, SLAB_PANIC);
> + fanotify_mnt_event_cachep = KMEM_CACHE(fanotify_mnt_event,
> + SLAB_PANIC|SLAB_MAY_ACCOUNT);
>
> fanotify_max_queued_events = FANOTIFY_DEFAULT_MAX_EVENTS;
> init_user_ns.ucount_max[UCOUNT_FANOTIFY_GROUPS] =
>
> --
> 2.54.0
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR