Skip to contentSkip to conversation

cgroups: skip processes from other namespaces when listing a cgroup

PATCH In review gowrishankar 3 participants 3 messages Dec 7, 2008 – Dec 8, 2008 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroups: skip processes from other namespaces when listing a cgroup

Once tasks are populated from system namespace inside cgroup, container replaces other namespace task with 0 while listing tasks, inside container.

Though this is expected behaviour from container end, there is no use of showing unwanted 0s.

In below patch, we check if a process is in same namespace before loading into pid array.

changes for vpid and pid_t

---
 kernel/cgroup.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
kernel/cgroup.c +3 -1
index 35eebd5..588d305 100644
@@ -2012,13 +2012,15 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan)
 static int pid_array_load(pid_t *pidarray, int npids, struct cgroup *cgrp)
 {
     int n = 0;
+    pid_t vpid;
     struct cgroup_iter it;
     struct task_struct *tsk;
     cgroup_iter_start(cgrp, &it);
     while ((tsk = cgroup_iter_next(cgrp, &it))) {
         if (unlikely(n == npids))
             break;
-        pidarray[n++] = task_pid_vnr(tsk);
+        if ((vpid = task_pid_vnr(tsk)) > 0)
+            pidarray[n++] = vpid;
     }
     cgroup_iter_end(cgrp, &it);
     return n;
Signature · 1 line
1.5.5.1

A message that is not in the archive (sent off-list or not yet received): 493BE1A9.8030503-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org

#2 lore raw
Quoted 24 lines · gowrishankar

Once tasks are populated from system namespace inside cgroup, container replaces other namespace task with 0 while listing tasks, inside container.

Though this is expected behaviour from container end, there is no use of showing unwanted 0s.

In below patch, we check if a process is in same namespace before loading into pid array.

changes for vpid and pid_t
---
kernel/cgroup.c | 4 +++-

1 files changed, 3 insertions(+), 1 deletions(-)
kernel/cgroup.c +0 -0
index 35eebd5..588d305 100644

kernel/cgroup.c int cgroup_scan_tasks(struct cgroup_scanner *scan) · line 2015

Quoted 4 lines
kernel/cgroup.c +1 -0
@@ -2012,13 +2012,15 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan)
 static int pid_array_load(pid_t *pidarray, int npids, struct cgroup *cgrp)
 {
    int n = 0;
+    pid_t vpid;

The formatting does not seem right, what is your tab space set to?

Quoted 16 lines
kernel/cgroup.c +2 -1
    struct cgroup_iter it;
    struct task_struct *tsk;
    cgroup_iter_start(cgrp, &it);
    while ((tsk = cgroup_iter_next(cgrp, &it))) {
        if (unlikely(n == npids))
            break;
-        pidarray[n++] = task_pid_vnr(tsk);
+        if ((vpid = task_pid_vnr(tsk)) > 0)
+            pidarray[n++] = vpid;
    }
    cgroup_iter_end(cgrp, &it);
    return n;
Signature · 1 line
1.5.5.1
Signature · 1 line
	Balbir

A message that is not in the archive (sent off-list or not yet received): 20081208151412.GN13333-SINUvgVNF2CyUtPGxGje5AC/[email protected]

#4 lore raw
Quoted 13 lines · Balbir Singh

kernel/cgroup.c int cgroup_scan_tasks(struct cgroup_scanner *scan) · line 2026

Quoted 12 lines · gowrishankar
    struct cgroup_iter it;
    struct task_struct *tsk;
    cgroup_iter_start(cgrp, &it);
    while ((tsk = cgroup_iter_next(cgrp, &it))) {
        if (unlikely(n == npids))
            break;
kernel/cgroup.c +2 -1
-        pidarray[n++] = task_pid_vnr(tsk);
+        if ((vpid = task_pid_vnr(tsk)) > 0)
+            pidarray[n++] = vpid;
    }
    cgroup_iter_end(cgrp, &it);
    return n;

One more thing...

Please cc Eric and Suka on patches like this. If we get many users like this we'll probably want to add some common function. Or if someone missed using one, they can probably suggest one.

-- Dave