Comment 7 for bug 742248

Revision history for this message
In , Michael (michael-redhat-bugs) wrote :

Description of problem:

GNU time can print out the maximum RSS usage of its subprocess. The ru_maxrss value returned by the wait4 syscall is in units of kilobytes, but GNU time incorrectly treats this as a number of pages, multiplying the value by 4 before displaying it.

Version-Release number of selected component (if applicable):
time-1.7-37.fc12.i686

How reproducible: Always

Steps to Reproduce:
1. /usr/bin/time -f %M perl -e '"x" x 400 x 1024 x 1024'

Actual results: A bit over 1600000, indicating maximum RSS usage of 1.6 GB. This is not even possible on my system as it only has 1 GB of physical RAM.

Expected results: Approximately 400000, since Perl should only be allocating around 400 MB.

Additional info:

Applying strace to the above command, it is clear that time is multiplying the ru_maxrss value returned by wait4:

$ strace -ve wait4 /usr/bin/time -f %M perl -e '"x" x 400 x 1024 x 1024'
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, {ru_utime={0, 146977}, ru_stime={0, 676897}, ru_maxrss=411356, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=102901, ru_majflt=1, ru_nswap=0, ru_inblock=176, ru_oublock=0, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=1, ru_nivcsw=40}) = 7459
--- {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=7459, si_status=0, si_utime=14, si_stime=68} (Child exited) ---
1645424

According to the getrusage(2) manpage:

  ru_maxrss (since Linux 2.6.32)
     This is the maximum resident set size used (in kilobytes). [...]

I've attached a simple patch that simply skips the "pages to kilobytes" conversion for this field.