Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] samples/cgroup: fix issues in the event listener samples
@ 2026-11-02 12:25 Song Hu
  2026-11-02 12:25 ` [PATCH 1/4] samples/cgroup: fix poll error handling in memcg_event_listener Song Hu
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Song Hu @ 2026-11-02 12:25 UTC (permalink / raw)
  To: hannes, mhocko, roman.gushchin, shakeelb, muchun.song, akpm
  Cc: tj, tjmercier, ddrokosov, cgroups, linux-mm, linux-kernel,
	Song Hu

The two event-listener samples in samples/cgroup mishandle the
lifetime of the monitored file and poll() errors in several ways.

Patch 1 fixes the poll error guard in memcg_event_listener, which
tests "errno != EAGAIN", an error poll() never reports, so an
interrupted poll (EINTR) from a signal exits the listener instead of
resuming.

Patch 2 makes memcg_event_listener exit cleanly when the monitored
cgroup is removed.  Since eea5d2bb34ba ("kernfs: Send IN_DELETE_SELF
and IN_IGNORED") kernfs delivers both events on rmdir; the sample
warns and keeps polling, so a supervisor still counts it as alive
while the monitored cgroup is gone.  Verified against a real
container lifecycle: the unpatched listener stays alive across
docker rm -f, the patched one exits.

Patch 3 arms the inotify watch before reading the counter baseline in
memcg_event_listener, closing the window in which events were lost.

Patch 4 stops cgroup_event_listener from letting dirname(3) modify
argv[1] in place, which truncated the path reported in every event
line and made the two-listener setup taught by
Documentation/admin-guide/cgroup-v1/memory.rst produce
indistinguishable output.

Patches 1 and 2 were verified against a real container lifecycle
(docker rm -f) in a QEMU/KVM virtual machine; patch 3 runs on every
listener start; patch 4 is compile-tested only.

Song Hu (4):
  samples/cgroup: fix poll error handling in memcg_event_listener
  samples/cgroup: exit cleanly when the monitored memcg is removed
  samples/cgroup: arm the inotify watch before reading the baseline
  samples/cgroup: don't let dirname() clobber the monitored path

 samples/cgroup/cgroup_event_listener.c | 18 +++++++---
 samples/cgroup/memcg_event_listener.c  | 50 +++++++++++++++++++-------
 2 files changed, 51 insertions(+), 17 deletions(-)

-- 
2.53.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-03 12:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02 12:25 [PATCH 0/4] samples/cgroup: fix issues in the event listener samples Song Hu
2026-11-02 12:25 ` [PATCH 1/4] samples/cgroup: fix poll error handling in memcg_event_listener Song Hu
2026-11-02 12:25 ` [PATCH 2/4] samples/cgroup: exit cleanly when the monitored memcg is removed Song Hu
2026-11-02 12:25 ` [PATCH 3/4] samples/cgroup: arm the inotify watch before reading the baseline Song Hu
2026-11-03 12:25   ` sashiko-bot
2026-11-02 12:25 ` [PATCH 4/4] samples/cgroup: don't let dirname() clobber the monitored path Song Hu
2026-11-03 12:26   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox