Skip to content

Make bsd process accounting work in pid namespaces

Pavel Emelyanov lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest10 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10Bsdacct: rename acct_blbls to bsd_acct_structkernel/acct.c+2 -20 replies
2/10Pidns: use kzalloc when allocating new pid_namespace structkernel/pid_namespace.c+2 -60 replies
3/10Pidns: add the struct bsd_acct_struct pointer on pid_namespace structinclude/linux/pid_namespace.h+5 -00 replies
4/10Bsdacct: "truthify" a comment near acct_processkernel/acct.c+0 -10 replies
5/10Bsdacct: make check timer accept a bsd_acct_struct argumentkernel/acct.c+5 -40 replies
6/10Bsdacct: turn the acct_lock from on-the-struct to globalkernel/acct.c+21 -210 replies
7/10Bsdacct: make internal code work with passed bsd_acct_struct, not globalkernel/acct.c+39 -380 replies
8/10Bsdacct: switch from global bsd_acct_struct instance to per-pidns oneinclude/linux/acct.h kernel/acct.c kernel/pid_namespace.c+71 -180 replies
9/10Bsdacct: turn acct off for all pidns-s on umount timekernel/acct.c+16 -120 replies
10/10Bsdacct: account dying tasks in all relevant namespaceskernel/acct.c+14 -73 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/10] Make bsd process accounting work in pid namespaces

After I fixed access to task->tgid in kernel/acct.c, Oleg pointed out some bad side effects with this accounting vs pid namespaces interaction. I.e. when some task in pid namespace sets this accounting up, this blocks all the others from doing the same. Restricting this to init namespace only could help, but didn't look as a grace solution.

So here is the approach to make this accounting work with pid namespaces properly.

The idea is simple - when a task dies it accounts itself in each namespace it is visible from and which set the accounting up.

For example here are the commands run and the output of lastcomm from init and sub namespaces:

init_ns# accton pacct
sub_ns# accton pacct (this is a different file - sub ns is run in
a chroot-ed environment)
init_ns# cat /dev/null
sub_ns# ls /dev/null
init_ns# accton
sub_ns# accton

sub_ns# lastcomm -f pacct

ls                      0        [136,0]    0.00 secs Thu May 15 10:30
accton                  0        [136,0]    0.00 secs Thu May 15 10:30

init_ns# lastcomm -f pacct

accton                  root     pts/0      0.00 secs Thu May 15 14:30 << got from sub
cat                     root     pts/1      0.00 secs Thu May 15 14:30
ls                      root     pts/0      0.00 secs Thu May 15 14:30 << got from sub
accton                  root     pts/1      0.00 secs Thu May 15 14:30

That was the summary, the details are in patches.

The set was sent for RFC a month ago, but I got only one, but positive response from Oleg. Hopefully, he can confirm one now.