getrusage(RUSAGE_BOTH)

From: Rasmus Villemoes
Date: Sat Jan 18 2020 - 11:48:47 EST


RUSAGE_BOTH exists in the uapi header, but currently sys_getrusage
rejects it with -EINVAL:

SYSCALL_DEFINE2(getrusage, int, who, struct rusage __user *, ru)
{
struct rusage r;

if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
who != RUSAGE_THREAD)
return -EINVAL;

getrusage(RUSAGE_BOTH) is used by the exit code in various places. But
is there any good reason not to allow userspace to use it? Of course one
can get the same info with two calls using RUSAGE_CHILDREN +
RUSAGE_SELF, but that seems a bit silly when the kernel already has the
code to do the summation.

Apart from the obvious addition above, I think the only thing needed is
to adjust the conditions where mm_highwater_rss gets updated:

if (who != RUSAGE_CHILDREN && who != RUSAGE_BOTH) {
struct mm_struct *mm = get_task_mm(p);

if (mm) {
setmax_mm_hiwater_rss(&maxrss, mm);
mmput(mm);
}



If RUSAGE_BOTH is not supposed to be used, perhaps it should be removed
from the uapi header?

Rasmus