| Summary: | `time` function reports more `maxrss` usage than GNU time | ||
|---|---|---|---|
| Product: | Busybox | Reporter: | herano1999 |
| Component: | Standard Compliance | Assignee: | unassigned |
| Status: | NEW --- | ||
| Severity: | critical | CC: | busybox-cvs, wes |
| Priority: | P1 | ||
| Version: | 1.34.x | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Host: | Target: | ||
| Build: | |||
It seems that time is treating the the `ru_maxrss` value as a count of pages[1][2] but it's already in kilobytes[3]: > ru_maxrss (since Linux 2.6.32) > This is the maximum resident set size used (in kilobytes). [1]: https://git.busybox.net/busybox/tree/miscutils/time.c#n125 [2]: https://git.busybox.net/busybox/tree/miscutils/time.c#n284 [3]: https://man7.org/linux/man-pages/man2/getrusage.2.html (In reply to Wesley Moore from comment #1) Thanks for your information. I've checked the code of GNU time[1] and found that the reporting unit depends on the OS[2]. So the busybox's implementation here may be wrong. [1] https://git.savannah.gnu.org/cgit/time.git/tree/src/time.c [2] https://git.savannah.gnu.org/cgit/time.git/tree/configure.ac#n77 (In reply to herano1999 from comment #2) > So the busybox's implementation here may be wrong. Yep that's what I was pointing out in my comment above. |
use the binary from this C++ file produces: ``` // add.cpp #include <cstdio> char bulk[1 << 20]; int main() { for (int i = 1; i < 1048576; i++) bulk[i] = bulk[i - 1] + 'a'; printf("hello, world\n"); return 0; } ``` and compile it with ``` g++ add.cpp -o add -O2 -static ``` using GNU time 1.7 to monitor the usage ``` /usr/bin/time -v ./add ``` it reports that `add` uses ~1800 kbytes of maxrss, but uses busybox 1.34.1 ``` time -v ./add ``` it reports that `add` uses ~7300 kbytes of maxrss. It's rather 4x more than the GNU time gives. I think there should not be too much gap between the two `time` functions.