[REGRESSION] Two issues that prevent process accounting (taskstats) from working correctly

From: Martin Steigerwald
Date: Mon Dec 19 2016 - 07:13:30 EST


ïHello Ingo, Peter, Nicolas, Andrew, Balbir, Shailabh, Jay, Gerlof and Marc,

starting from a Debian bug report of mine, Gerlof Langeveld, developer of
system and process monitor atopÂ, found two issues with process accounting.

[1] http://atoptool.nl/


I did some guess work on who might be the maintainer for this, but please feel
free to add further CcÂs as you see fit. Or ask for removal for Cc if you are
not working on this anymore.

Gerlof found two issues which I also reported to the kernel bug tracker. I
copy and paste the summaries that Gerlof prepared:


1) Sometimes process accounting does not work at all.

The acct() system call (to activate process accounting) return value 0,
which means that process accounting is activated successfully.
However, no process accounting records are written whatsoever. This
situation can be reproduced with the program 'acctdemo.c'
that you can find as attachment. When this program gives the message
"found a process accounting record!", the situation is okay
and process accounting works fine to the file '/tmp/mypacct'. When the
message 'No process accounting record yet....' is repeatedly given,
process accounting does not work and will not work at all. It might be
that you have to start this program several times before you get
this situation (preferably start/finish lots of processes in the mean time).
This problem is probably caused by a new mechanism introduced in the
kernel code (..../linux/kernel/acct.c) that is called 'slow accounting'
and has to be solved in the kernel code.

I experience this problem on Debian8 with a 4.8 kernel and on CentOS7
with a 4.8 kernel.

I reported this as:

Bug 190271 - process accounting sometimes does not work
https://bugzilla.kernel.org/show_bug.cgi?id=190271



2) When using the NETLINK inface, the command TASKSTATS_CMD_GET
consequently returns -EINVAL.

The code that is used by the atopacctd daemon is based on the demo code
'getdelays.c' that can be found in the kernel source code tree
(..../linux/Documentation/accounting/getdelays.c). Also this 'getdelays'
program does not work any more (also -EINVAL on the same call)
with the newer kernels. I really spent a lot of time on this issue to
get the code running (there are many places in the kernel code where
-EINVAL for this call can be given), but I did not succeed. It is really
an incompatibility introduced by the kernel code.
It would be nice if the kernel maintainers provide a working version of
the getdelays program in the kernel source tree.

I only experience this problem on Debian8 with a 4.8 kernel (virtual
machine with 4 cores).
On CentOS7 with a 4.8 kernel it works fine (physical machine with 4 cores).

I will anyhow adapt atopacctd for this issue that it detects and logs
the -EINVAL and terminates.
The current version of atopacctd keeps running which is not useful at all.


I reported this as:

Bug 190711 - Process accounting: Using the NETLINK inface, the command
TASKSTATS_CMD_GET returns -EINVAL

https://bugzilla.kernel.org/show_bug.cgi?id=190711


Marc Haber, maintainer of atop package, Gerlof Langeveld, developer of atop
and I are currently discussing workarounds with atop and/or systemd service
fail for the time till upstream kernels with this issues fixed are shipped by
distributions. Still it would be nice to remove those work-arounds and have
the kernel work correctly again at some time in the future.

Thanks,
--
Martin Steigerwald | Trainer

teamix GmbH
SÃdwestpark 43
90449 NÃrnberg

Tel.: +49 911 30999 55 | Fax: +49 911 30999 99
mail: martin.steigerwald@xxxxxxxxx | web: http://www.teamix.de | blog: http://blog.teamix.de

Amtsgericht NÃrnberg, HRB 18320 | GeschÃftsfÃhrer: Oliver KÃgow, Richard MÃller

teamix Support Hotline: +49 911 30999-112

*** Bitte liken Sie uns auf Facebook: facebook.com/teamix ***

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#define ACCTFILE "/tmp/mypacct"

main()
{
int fd;
char buf[1024];

if ( (fd = open(ACCTFILE, O_RDWR|O_CREAT|O_TRUNC, 0777)) == -1)
{
perror("Open " ACCTFILE);
exit(1);
}

if (acct(ACCTFILE) == -1)
{
perror("Switch on accounting");
exit(1);
}

if ( fork() == 0 ) // fork new process
exit(0); // child process: finish


// parent process:
// wait for child to finish

wait((int *)0);

// read the process accounting record of the finished child

while (read(fd, buf, sizeof buf) == 0)
{
printf("No process accounting record yet....\n");
sleep(1);
}

printf("Yeeeeah, found a process accounting record!\n");
}