[PATCH slab/for-next 10/14] fanotify: specify SLAB_MAY_ACCOUNT for event caches

From: Harry Yoo (Meta)

Date: Wed Oct 21 2026 - 07:56:08 EST


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)

Assisted-by: LLM
Cc: Jan Kara <jack@xxxxxxx>
Cc: Amir Goldstein <amir73il@xxxxxxxxx>
Cc: linux-fsdevel@xxxxxxxxxxxxxxx
Signed-off-by: Harry Yoo (Meta) <harry@xxxxxxxxxx>
---
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 a32c6634d592..bc1227e521a8 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