fs/kernfs/dir.c | 21 +++ fs/kernfs/file.c | 20 ++- fs/kernfs/kernfs-internal.h | 3 + include/linux/kernfs.h | 1 + .../selftests/cgroup/test_memcontrol.c | 122 ++++++++++++++++++ 5 files changed, 161 insertions(+), 6 deletions(-)
This series adds support for IN_DELETE_SELF and IN_IGNORED inotify
events to kernfs files.
Currently, kernfs (used by cgroup and others) supports IN_MODIFY events
but fails to notify watchers when the file is removed (e.g. during
cgroup destruction). This forces userspace monitors to maintain resource
intensive side-channels like pidfds, procfs polling, or redundant
directory watches to detect when a cgroup dies and a watched file is
removed.
By generating IN_DELETE_SELF events on destruction, we allow watchers to
rely on a single watch descriptor for the entire lifecycle of the
monitored file, reducing resource usage (file descriptors, CPU cycles)
and complexity in userspace.
The series is structured as follows:
Patch 1 refactors kernfs_elem_attr to support arbitrary event types.
Patch 2 implements the logic to generate DELETE_SELF and IGNORED events
on file removal.
Patch 3 adds selftests to verify the new behavior.
---
Changes in v2:
Remove unused variables from new selftests per kernel test robot
Fix kernfs_type argument per Tejun
Inline checks for FS_MODIFY, FS_DELETE in kernfs_notify_workfn per Tejun
T.J. Mercier (3):
kernfs: allow passing fsnotify event types
kernfs: send IN_DELETE_SELF and IN_IGNORED on file deletion
selftests: memcg: Add tests IN_DELETE_SELF and IN_IGNORED on
memory.events
fs/kernfs/dir.c | 21 +++
fs/kernfs/file.c | 20 ++-
fs/kernfs/kernfs-internal.h | 3 +
include/linux/kernfs.h | 1 +
.../selftests/cgroup/test_memcontrol.c | 122 ++++++++++++++++++
5 files changed, 161 insertions(+), 6 deletions(-)
base-commit: ba268514ea14b44570030e8ed2aef92a38679e85
--
2.53.0.273.g2a3d683680-goog
On Thu, Feb 12, 2026 at 01:58:11PM -0800, T.J. Mercier wrote: > This series adds support for IN_DELETE_SELF and IN_IGNORED inotify > events to kernfs files. > > Currently, kernfs (used by cgroup and others) supports IN_MODIFY events > but fails to notify watchers when the file is removed (e.g. during > cgroup destruction). This forces userspace monitors to maintain resource > intensive side-channels like pidfds, procfs polling, or redundant > directory watches to detect when a cgroup dies and a watched file is > removed. > > By generating IN_DELETE_SELF events on destruction, we allow watchers to > rely on a single watch descriptor for the entire lifecycle of the > monitored file, reducing resource usage (file descriptors, CPU cycles) > and complexity in userspace. > > The series is structured as follows: > Patch 1 refactors kernfs_elem_attr to support arbitrary event types. > Patch 2 implements the logic to generate DELETE_SELF and IGNORED events > on file removal. > Patch 3 adds selftests to verify the new behavior. The patchset looks good to me. Acked-by: Tejun Heo <tj@kernel.org> Thanks. -- tejun
On Mon, Feb 16, 2026 at 10:43 PM Tejun Heo <tj@kernel.org> wrote: > > On Thu, Feb 12, 2026 at 01:58:11PM -0800, T.J. Mercier wrote: > > This series adds support for IN_DELETE_SELF and IN_IGNORED inotify > > events to kernfs files. > > > > Currently, kernfs (used by cgroup and others) supports IN_MODIFY events > > but fails to notify watchers when the file is removed (e.g. during > > cgroup destruction). This forces userspace monitors to maintain resource > > intensive side-channels like pidfds, procfs polling, or redundant > > directory watches to detect when a cgroup dies and a watched file is > > removed. > > > > By generating IN_DELETE_SELF events on destruction, we allow watchers to > > rely on a single watch descriptor for the entire lifecycle of the > > monitored file, reducing resource usage (file descriptors, CPU cycles) > > and complexity in userspace. > > > > The series is structured as follows: > > Patch 1 refactors kernfs_elem_attr to support arbitrary event types. > > Patch 2 implements the logic to generate DELETE_SELF and IGNORED events > > on file removal. > > Patch 3 adds selftests to verify the new behavior. > > The patchset looks good to me. > > Acked-by: Tejun Heo <tj@kernel.org> > > Thanks. > > -- > tejun Thanks Tejun. Amir would prefer I remove the new DELETE event support and keep only the part for DELETE_SELF + IGNORED since adding only DELETE would create an asymmetry with the missing CREATE support. So I will plan to do that in V3 for this series. Thanks, T.J.
On Thu, Feb 12, 2026 at 01:58:11PM -0800, T.J. Mercier wrote: > This series adds support for IN_DELETE_SELF and IN_IGNORED inotify > events to kernfs files. > > Currently, kernfs (used by cgroup and others) supports IN_MODIFY events > but fails to notify watchers when the file is removed (e.g. during > cgroup destruction). This forces userspace monitors to maintain resource > intensive side-channels like pidfds, procfs polling, or redundant > directory watches to detect when a cgroup dies and a watched file is > removed. > > By generating IN_DELETE_SELF events on destruction, we allow watchers to > rely on a single watch descriptor for the entire lifecycle of the > monitored file, reducing resource usage (file descriptors, CPU cycles) > and complexity in userspace. > > The series is structured as follows: > Patch 1 refactors kernfs_elem_attr to support arbitrary event types. > Patch 2 implements the logic to generate DELETE_SELF and IGNORED events > on file removal. > Patch 3 adds selftests to verify the new behavior. > > --- > Changes in v2: > Remove unused variables from new selftests per kernel test robot > Fix kernfs_type argument per Tejun > Inline checks for FS_MODIFY, FS_DELETE in kernfs_notify_workfn per Tejun > > T.J. Mercier (3): > kernfs: allow passing fsnotify event types > kernfs: send IN_DELETE_SELF and IN_IGNORED on file deletion > selftests: memcg: Add tests IN_DELETE_SELF and IN_IGNORED on > memory.events > > fs/kernfs/dir.c | 21 +++ > fs/kernfs/file.c | 20 ++- > fs/kernfs/kernfs-internal.h | 3 + > include/linux/kernfs.h | 1 + > .../selftests/cgroup/test_memcontrol.c | 122 ++++++++++++++++++ > 5 files changed, 161 insertions(+), 6 deletions(-) > > > base-commit: ba268514ea14b44570030e8ed2aef92a38679e85 > -- > 2.53.0.273.g2a3d683680-goog > In future posts, please CC inotify patches to fsdevel and inotify maintainers. Thanks, Amir.
On Mon, Feb 16, 2026 at 8:21 AM Amir Goldstein <amir73il@gmail.com> wrote: > > On Thu, Feb 12, 2026 at 01:58:11PM -0800, T.J. Mercier wrote: > > This series adds support for IN_DELETE_SELF and IN_IGNORED inotify > > events to kernfs files. > > > > Currently, kernfs (used by cgroup and others) supports IN_MODIFY events > > but fails to notify watchers when the file is removed (e.g. during > > cgroup destruction). This forces userspace monitors to maintain resource > > intensive side-channels like pidfds, procfs polling, or redundant > > directory watches to detect when a cgroup dies and a watched file is > > removed. > > > > By generating IN_DELETE_SELF events on destruction, we allow watchers to > > rely on a single watch descriptor for the entire lifecycle of the > > monitored file, reducing resource usage (file descriptors, CPU cycles) > > and complexity in userspace. > > > > The series is structured as follows: > > Patch 1 refactors kernfs_elem_attr to support arbitrary event types. > > Patch 2 implements the logic to generate DELETE_SELF and IGNORED events > > on file removal. > > Patch 3 adds selftests to verify the new behavior. > > > > --- > > Changes in v2: > > Remove unused variables from new selftests per kernel test robot > > Fix kernfs_type argument per Tejun > > Inline checks for FS_MODIFY, FS_DELETE in kernfs_notify_workfn per Tejun > > > > T.J. Mercier (3): > > kernfs: allow passing fsnotify event types > > kernfs: send IN_DELETE_SELF and IN_IGNORED on file deletion > > selftests: memcg: Add tests IN_DELETE_SELF and IN_IGNORED on > > memory.events > > > > fs/kernfs/dir.c | 21 +++ > > fs/kernfs/file.c | 20 ++- > > fs/kernfs/kernfs-internal.h | 3 + > > include/linux/kernfs.h | 1 + > > .../selftests/cgroup/test_memcontrol.c | 122 ++++++++++++++++++ > > 5 files changed, 161 insertions(+), 6 deletions(-) > > > > > > base-commit: ba268514ea14b44570030e8ed2aef92a38679e85 > > -- > > 2.53.0.273.g2a3d683680-goog > > > > In future posts, please CC inotify patches to fsdevel and inotify maintainers. Got it, will do.
© 2016 - 2026 Red Hat, Inc.