]> git.ipfire.org Git - thirdparty/systemd.git/commit
cgroup-util: Always open cgroupv2 attribute files in O_NONBLOCK mode
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 22 Apr 2025 08:36:21 +0000 (10:36 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 17 Jun 2025 14:07:32 +0000 (15:07 +0100)
commit4fe348cfdf6e65118ab78d5e1a08cbc5a1639ff1
treeb9031d3f50c6f097b614ae3ac1bfb672bc62a706
parent279962a9e8bfb2d96834ec0360388e77fb818d90
cgroup-util: Always open cgroupv2 attribute files in O_NONBLOCK mode

As explained in https://lore.kernel.org/all/20250419183545.1982187-1-shakeel.butt@linux.dev/,
writing to memory.max or memory.high triggers synchronous memory reclaim
if the limit is lowered. This can end up taking nonnegligible amounts
of time, completely blocking pid1 from doing any other work while the
reclaim is ongoing.

To address this problem, the kernel going to add O_NONBLOCK semantics
to memory.max and memory.high. If the file is opened with O_NONBLOCK,
the synchronous memory reclaim is skipped and only triggered later
without blocking the process writing the file. Let's make sure we make
use of this by opening cgroupv2 attribute files with O_NONBLOCK.

We opt to do this for all cgroupv2 attribute files, to make sure that
if the same problem happens elsewhere in the future and is fixed in the
same way, we immediately take advantage of that fix without having to
make changes in systemd as well. We probably never want to block when
writing cgroupv2 attributes and any cases where we do want to block should
indicate so explicitly instead of blocking by default.
src/basic/cgroup-util.c
src/basic/fileio.c
src/basic/fileio.h