Skip to content

Conversation

@mihalicyn
Copy link
Member

@mihalicyn mihalicyn commented Oct 31, 2025

Virtualize /proc/pressure/{cpu, io, memory} by doing a simple
passthrough of write()/poll() syscalls to the underlying cgroup's
/sys/fs/cgroup/x/y/z/{cpu, io, memory}.pressure file.

Implementation is a bit tricky because FUSE notifications must
be issued asynchroniously and we have to use a separate thread for this.

My main concern here was to ensure that no thread leaks are possible,
cause it can be a potenial DoS for host.

If PSITRIGGERTEST macro is defined, then instead of poll-ing on a real
fd we do a simple nanosleep() with 3 seconds delay. This needed to enable
CI testing of this feature.

For a "real-world" testing, I was using an example program from [1],
but with cpu counter instead of memory. To make cpu pressure I use
"sysbench --threads="$(nproc)" cpu run" command.

Link: https://www.kernel.org/doc/Documentation/accounting/psi.rst [1]

This change is safe, cause I'm adding a union and we have enough
space for void *.

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
Signed-off-by: Alexander Mikhalitsyn <[email protected]>
Signed-off-by: Alexander Mikhalitsyn <[email protected]>
Define SIG_NOTIFY_POLL_WAKEUP as SIGRTMIN + 0 and install
noop signal handler. This signal will be used to manage
notification threads.

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
Virtualize /proc/pressure/{cpu, io, memory} by doing a simple
passthrough of write()/poll() syscalls to the underlying cgroup's
/sys/fs/cgroup/x/y/z/{cpu, io, memory}.pressure file.

Implementation is a bit tricky because FUSE notifications must
be issued asynchroniously and we have to use a separate thread for this.

My main concern here was to ensure that no thread leaks are possible,
cause it can be a potenial DoS for host.

If PSITRIGGERTEST macro is defined, then instead of poll-ing on a real
fd we do a simple nanosleep() with 1 second delay. This needed to enable
CI testing of this feature.

For a "real-world" testing, I was using an example program from [1],
but with cpu counter instead of memory. To make cpu pressure I use
"sysbench --threads="$(nproc)" cpu run" command.

Link: https://www.kernel.org/doc/Documentation/accounting/psi.rst [1]
Signed-off-by: Alexander Mikhalitsyn <[email protected]>
Signed-off-by: Alexander Mikhalitsyn <[email protected]>
@mihalicyn mihalicyn force-pushed the psi_write_support branch 3 times, most recently from 4600fb5 to 4b3921f Compare October 31, 2025 18:17
Let's make PSI triggers virtulization opt-in feature.

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
@mihalicyn mihalicyn marked this pull request as ready for review November 3, 2025 14:23
@stgraber stgraber merged commit c67f5f8 into lxc:main Nov 4, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants