/usr/bin/time -f '%M' reports memory usage size that is 4 time greater than actual, at least with my current kernel 2.6.34-gentoo-r1 on x86_64. Reproducible: Always Steps to Reproduce: 1. Ensure you have proper kernel. 2.6.34-gentoo-r1 should be enough; I am not sure for 2.6.32 and 2.6.33. Anyway, you need at least >=2.6.32 for proper support of ru_maxrss in getrusage(2). 2. emerge sys-process/time (I've got 1.7-r1) 3. Get a tool to allocate memory... Like that: $ cat >alloc.cpp #include <stdlib.h> #include <stdio.h> #include <assert.h> int main(int ac, char**av) { assert(ac == 2); int kb = atoi(av[1]); int size = kb * 1024; printf ("Allocating %d kb\n", kb); char *p = (char*) malloc(size); if (!p) { printf("Failed to allocate, exiting\n"); return 1; } for (int i = 0; i < size; i+= 128) { p[i] = 1; } return 0; } ^D $ c++ -o alloc ./alloc.cpp 3. $ for i in 100000 200000; do /usr/bin/time -f '%M' ./alloc $i; done Actual Results: Allocating 100000 kb 403696 Allocating 200000 kb 803696 Expected Results: Allocating 100000 kb (something near to 100000) Allocating 200000 kb (something near to 200000) It seems like linux kernel returns ru_maxrss as kb, while /usr/bin/time expects that value as number of pages and tries to convert that to kb again. Maybe that link would be relevant: http://www.mail-archive.com/linux-api@vger.kernel.org/msg00364.html $ emerge --info Portage 2.1.8.3 (default/linux/amd64/10.0, gcc-4.4.3, glibc-2.11.2-r0, 2.6.34-gentoo-r1 x86_64) ================================================================= System uname: Linux-2.6.34-gentoo-r1-x86_64-Intel-R-_Xeon-R-_CPU_E5620_@_2.40GHz-with-gentoo-1.12.13 Timestamp of tree: Mon, 19 Jul 2010 01:45:01 +0000 ccache version 2.4 [enabled] app-shells/bash: 4.0_p37 dev-java/java-config: 2.1.11 dev-lang/python: 2.6.5-r2, 3.1.2-r3 dev-util/ccache: 2.4-r7 dev-util/cmake: 2.8.1-r2 sys-apps/baselayout: 1.12.13 sys-apps/sandbox: 1.6-r2 sys-devel/autoconf: 2.65 sys-devel/automake: 1.11.1 sys-devel/binutils: 2.20.1-r1 sys-devel/gcc: 4.4.3-r2 sys-devel/gcc-config: 1.4.1 sys-devel/libtool: 2.2.6b virtual/os-headers: 2.6.30-r1 ACCEPT_KEYWORDS="amd64" ACCEPT_LICENSE="* -@EULA dlj-1.1" CBUILD="x86_64-pc-linux-gnu" CFLAGS="-O2 -pipe" CHOST="x86_64-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/share/X11/xkb" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo" CXXFLAGS="-O2 -pipe" DISTDIR="/var/tmp/portage-distfiles" FEATURES="assume-digests ccache distlocks fixpackages news parallel-fetch protect-owned sandbox sfperms strict unmerge-logs unmerge-orphans userfetch" GENTOO_MIRRORS="http://distfiles.gentoo.org" LANG="ru_RU.UTF-8" LDFLAGS="-Wl,-O1" MAKEOPTS="-j12" PKGDIR="/usr/portage/packages" PORTAGE_CONFIGROOT="/" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/usr/portage" SYNC="rsync://rsync.gentoo.org/gentoo-portage" USE="X acl amd64 berkdb bzip2 cairo cli cracklib crypt cups cxx djvu dri fortran gdbm gpm iconv ipv6 jpeg kpathsea mmx modules mudflap multilib ncurses nls nptl nptlonly nsplugin openmp pam pcre perl png pppd python qt3support rar readline reflection session spl sse sse2 ssl ssse3 sysfs tcpd tiff unicode xorg zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" FOO2ZJS_DEVICES="hpp1505" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="intel mga" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" Unset: CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PORTDIR_OVERLAY
http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.32 says: --- begin quote --- commit 1f10206cf8e945220f7220a809d8bfc15c21f9a5 Author: Jiri Pirko <jpirko@redhat.com> Date: Tue Sep 22 16:44:10 2009 -0700 getrusage: fill ru_maxrss value Make ->ru_maxrss value in struct rusage filled accordingly to rss hiwater mark. This struct is filled as a parameter to getrusage syscall. ->ru_maxrss value is set to KBs which is the way it is done in BSD systems. /usr/bin/time (gnu time) application converts ->ru_maxrss to KBs which seems to be incorrect behavior. Maintainer of this util was notified by me with the patch which corrects it and cc'ed. --- end quote --- So, resolution "UPSTREAM"?
This problem still seems to exist. I am seeing the wrong output from sys-process/time-1.7-r1. There is a patch available at https://launchpadlibrarian.net/84899767/time.patch which I found in an Ubuntu bug report: https://bugs.launchpad.net/ubuntu/+source/time/+bug/742248 Is it possible to incorporate this patch in the near future?
Still outputting bad results after 4 years. Is there intention of fixing this?
+*time-1.7-r2 (01 Feb 2015) + + 01 Feb 2015; Lars Wendler <polynomial-c@gentoo.org> +time-1.7-r2.ebuild, + +files/time-1.7-incorrect_memory_usage.patch: + Fixed incorrect memory usage (bug #332253). +