[PATCH 0/2] cgroup-v2/freezer: small improvements

Pavel Tikhomirov posted 2 patches 1 month, 2 weeks ago
include/linux/cgroup-defs.h     |   5 ++
kernel/cgroup/cgroup-internal.h |   5 ++
kernel/cgroup/cgroup.c          |   2 +
kernel/cgroup/freezer.c         | 155 ++++++++++++++++++++++++++++++--
4 files changed, 161 insertions(+), 6 deletions(-)
[PATCH 0/2] cgroup-v2/freezer: small improvements
Posted by Pavel Tikhomirov 1 month, 2 weeks ago
This patch series contains two small improvements for cgroup-v2 freezer
controller.

First allows freezing cgroups with kthreads inside, we still won't
freeze kthreads, we still ignore them, but at the same time we allow
cgroup to report frozen when all other non-kthread tasks are frozen.

Second patch adds information into dmesg to identify processes which
prevent cgroup from being frozen or just don't allow it to freeze fast
enough.

I hope these changes will be generally useful for the users of freezer
cgroup controller.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

Pavel Tikhomirov (2):
  cgroup-v2/freezer: Allow freezing with kthreads
  cgroup-v2/freezer: Print information about unfreezable process

 include/linux/cgroup-defs.h     |   5 ++
 kernel/cgroup/cgroup-internal.h |   5 ++
 kernel/cgroup/cgroup.c          |   2 +
 kernel/cgroup/freezer.c         | 155 ++++++++++++++++++++++++++++++--
 4 files changed, 161 insertions(+), 6 deletions(-)

-- 
2.52.0
Re: [PATCH 0/2] cgroup-v2/freezer: small improvements
Posted by Michal Koutný 1 month, 2 weeks ago
On Tue, Dec 23, 2025 at 06:20:06PM +0800, Pavel Tikhomirov <ptikhomirov@virtuozzo.com> wrote:
> First allows freezing cgroups with kthreads inside, we still won't
> freeze kthreads, we still ignore them, but at the same time we allow
> cgroup to report frozen when all other non-kthread tasks are frozen.

kthreads in non-root cgroups are kind of an antipattern.
For which kthreads you would like this change? (See for instance the
commit d96c77bd4eeba ("KVM: x86: switch hugepage recovery thread to
vhost_task") as a possible refactoring of such threads.)

> Second patch adds information into dmesg to identify processes which
> prevent cgroup from being frozen or just don't allow it to freeze fast
> enough.

I can see how this can be useful for debugging, however, it resembles
the existing CONFIG_DETECT_HUNG_TASK and its
kernel.hung_task_timeout_secs. Could that be used instead?

Thanks,
Michal
Re: [PATCH 0/2] cgroup-v2/freezer: small improvements
Posted by Pavel Tikhomirov 1 month, 2 weeks ago
On 12/24/25 01:29, Michal Koutný wrote:
> On Tue, Dec 23, 2025 at 06:20:06PM +0800, Pavel Tikhomirov <ptikhomirov@virtuozzo.com> wrote:
>> First allows freezing cgroups with kthreads inside, we still won't
>> freeze kthreads, we still ignore them, but at the same time we allow
>> cgroup to report frozen when all other non-kthread tasks are frozen.
> 
> kthreads in non-root cgroups are kind of an antipattern.
> For which kthreads you would like this change? (See for instance the
> commit d96c77bd4eeba ("KVM: x86: switch hugepage recovery thread to
> vhost_task") as a possible refactoring of such threads.)

To explain our usecase, I would need to dive a bit into how Virtuozzo containers (OpenVZ) on our custom Virtuozzo kernel works.

In our case we have two custom kernel threads for each container: "kthreadd" and "umh".

https://bitbucket.org/openvz/vzkernel/src/662c0172a9d4aecf52dbaea4f903ccc801b569b2/kernel/ve/ve.c#lines-481
https://bitbucket.org/openvz/vzkernel/src/662c0172a9d4aecf52dbaea4f903ccc801b569b2/kernel/ve/ve.c#lines-581

The "kthreadd" is used to allow creating per-container kthreads, through it we create kthreads for "umh" (explained below) and to create sunrpc svc kthreads in container.

https://bitbucket.org/openvz/vzkernel/src/662c0172a9d4aecf52dbaea4f903ccc801b569b2/net/sunrpc/svc.c#lines-815

The "umh" is used to be able to run userspace commands from kernel in container, e.g.: we use it to virtualize (run in ct) coredump collection, nfs upcall, and cgroup-v1 release-agent.

https://bitbucket.org/openvz/vzkernel/src/662c0172a9d4aecf52dbaea4f903ccc801b569b2/fs/coredump.c#lines-640
https://bitbucket.org/openvz/vzkernel/src/662c0172a9d4aecf52dbaea4f903ccc801b569b2/fs/nfsd/nfs4recover.c#lines-1849
https://bitbucket.org/openvz/vzkernel/src/662c0172a9d4aecf52dbaea4f903ccc801b569b2/kernel/cgroup/cgroup-v1.c#lines-930

And we really want those threads be restricted by the same cgroups as the container.

The commit you've mentioned is an interesting one, we can try to switch our custom kthreads to "vhost_task" similar to what kvm did. It's not obvious if it will fly until we try =)

> 
>> Second patch adds information into dmesg to identify processes which
>> prevent cgroup from being frozen or just don't allow it to freeze fast
>> enough.
> 
> I can see how this can be useful for debugging, however, it resembles
> the existing CONFIG_DETECT_HUNG_TASK and its
> kernel.hung_task_timeout_secs. Could that be used instead?

The hung_task_timeout_secs detects the hang task only if it's in D state and didn't schedule, but it's not the only case. For instance the module I used to test the problem with, is not detected by this mechanism (as it schedules) (https://github.com/Snorch/proc-hang-module). 

Previously we saw tasks sleeping in nfs, presumably waiting for reply from server, which prevented freeze, and though hardlockup/softlockup/hang-task warnings were enabled they didn't trigger. Also one might want a separate timeout for freezer than for general hang cases (general hang timeouts should probably be higher). 

> 
> Thanks,
> Michal

-- 
Best regards, Pavel Tikhomirov
Senior Software Developer, Virtuozzo.