[RFC PATCH 0/1] netlink: Netlink process event for cgroup migration

Prakash Sangappa posted 1 patch 1 month, 3 weeks ago
drivers/connector/cn_proc.c  | 28 ++++++++++++++++++++++++++++
include/linux/cn_proc.h      |  3 +++
include/uapi/linux/cn_proc.h | 14 ++++++++++++--
kernel/cgroup/cgroup-v1.c    |  7 ++++++-
kernel/cgroup/cgroup.c       |  5 ++++-
5 files changed, 53 insertions(+), 4 deletions(-)
[RFC PATCH 0/1] netlink: Netlink process event for cgroup migration
Posted by Prakash Sangappa 1 month, 3 weeks ago
With cgroup based resource management, it becomes useful for
userspace to be notified when a task changes cgroup membership.
Unexpected migrations can lead to incorrect resource accounting
and enforcement resulting in undesirable behavior or failures.
Applications/userspace have to poll /proc to detect changes to 
cgroup membership, which is inefficient when dealing with a large
number of tasks.

Add a new netlink proc connector event that gets generated when
a task migrates between cgroups. This allows applications/tools
to monitor cgroup membership changes without periodic polling. 

The netlink proc event will include task's pid/tgid, initiator
process pid/tgid and the cgroup id.  

Prakash Sangappa (1):
  netlink: Add Netlink process event for cgroup migration

 drivers/connector/cn_proc.c  | 28 ++++++++++++++++++++++++++++
 include/linux/cn_proc.h      |  3 +++
 include/uapi/linux/cn_proc.h | 14 ++++++++++++--
 kernel/cgroup/cgroup-v1.c    |  7 ++++++-
 kernel/cgroup/cgroup.c       |  5 ++++-
 5 files changed, 53 insertions(+), 4 deletions(-)

-- 
2.43.7
Re: [RFC PATCH 0/1] netlink: Netlink process event for cgroup migration
Posted by Michal Koutný 1 month, 3 weeks ago
Hi Prakash.

On Tue, Apr 07, 2026 at 05:23:38PM +0000, Prakash Sangappa <prakash.sangappa@oracle.com> wrote:
> With cgroup based resource management, it becomes useful for
> userspace to be notified when a task changes cgroup membership.
> Unexpected migrations can lead to incorrect resource accounting
> and enforcement resulting in undesirable behavior or failures.
> Applications/userspace have to poll /proc to detect changes to 
> cgroup membership, which is inefficient when dealing with a large
> number of tasks.

You may want to check [1] (and followup discussion).

> Add a new netlink proc connector event that gets generated when
> a task migrates between cgroups. This allows applications/tools
> to monitor cgroup membership changes without periodic polling. 

This CN_IDX_PROC netlink API haunts me at night.
The hook(s) proposed above are IMO more future proof and robust approach
to the process migration that comes as a surprise (and possibly
interferes with intended resource management).

Thanks,
Michal

[1] https://lore.kernel.org/all/20260220-work-bpf-namespace-v1-2-866207db7b83@kernel.org/
Re: [RFC PATCH 0/1] netlink: Netlink process event for cgroup migration
Posted by Christian Brauner 1 month, 3 weeks ago
On Wed, Apr 08, 2026 at 02:54:17PM +0200, Michal Koutný wrote:
> Hi Prakash.
> 
> On Tue, Apr 07, 2026 at 05:23:38PM +0000, Prakash Sangappa <prakash.sangappa@oracle.com> wrote:
> > With cgroup based resource management, it becomes useful for
> > userspace to be notified when a task changes cgroup membership.
> > Unexpected migrations can lead to incorrect resource accounting
> > and enforcement resulting in undesirable behavior or failures.
> > Applications/userspace have to poll /proc to detect changes to 
> > cgroup membership, which is inefficient when dealing with a large
> > number of tasks.
> 
> You may want to check [1] (and followup discussion).
> 
> > Add a new netlink proc connector event that gets generated when
> > a task migrates between cgroups. This allows applications/tools
> > to monitor cgroup membership changes without periodic polling. 
> 
> This CN_IDX_PROC netlink API haunts me at night.

Yeah, let's not go down that route...
Re: [RFC PATCH 0/1] netlink: Netlink process event for cgroup migration
Posted by Prakash Sangappa 1 month, 3 weeks ago
Hi Michal,

Thanks for look into this patch proposal.


> On Apr 8, 2026, at 5:54 AM, Michal Koutný <mkoutny@suse.com> wrote:
> 
> Hi Prakash.
> 
> On Tue, Apr 07, 2026 at 05:23:38PM +0000, Prakash Sangappa <prakash.sangappa@oracle.com> wrote:
>> With cgroup based resource management, it becomes useful for
>> userspace to be notified when a task changes cgroup membership.
>> Unexpected migrations can lead to incorrect resource accounting
>> and enforcement resulting in undesirable behavior or failures.
>> Applications/userspace have to poll /proc to detect changes to 
>> cgroup membership, which is inefficient when dealing with a large
>> number of tasks.
> 
> You may want to check [1] (and followup discussion).

Will take a look.

> 
>> Add a new netlink proc connector event that gets generated when
>> a task migrates between cgroups. This allows applications/tools
>> to monitor cgroup membership changes without periodic polling.
> 
> This CN_IDX_PROC netlink API haunts me at night.
> The hook(s) proposed above are IMO more future proof and robust approach
> to the process migration that comes as a surprise (and possibly
> interferes with intended resource management).

Ok, with [1] would there be bpf hooks that can be used for notification
of cgroup migration events?  Will take a look.

Thanks,
-Prakash

> 
> Thanks,
> Michal
> 
> [1] https://lore.kernel.org/all/20260220-work-bpf-namespace-v1-2-866207db7b83@kernel.org/