9

From man time:

M      Maximum resident set size of the process during its lifetime, in Kilobytes.

From ulimit -a:

max memory size         (kbytes, -m) unlimited

But a "kilobyte" may mean either 1000 or 1024 bytes. I guess here it is a round 1024, but I want to be sure. Authoritative reference would be appreciated.

Feel free to rephrase my question as: do time and ulimit conform to the IEC recommendation, or use "kilobyte/kbyte" in the kibibyte meaning.

abukaj
  • 485

3 Answers3

9

Per man dir.1:

The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

Per info ls:

‘-h’
‘--human-readable’
Append a size letter to each size, such as ‘M’ for mebibytes. Powers of 1024 are used, not 1000; ‘M’ stands for 1,048,576 bytes. This option is equivalent to --block-size=human-readable. Use the --si option if you prefer powers of 1000.

The output for ls is further backed up in the source here and here.

It would seem as though the single letter is the 1024 measurement. The two digit character abbreviations are the 1000 SI units.

Since ulimit is builtin to bash, going to their source is the definitive...source. I'm often punny, but you can see it here and here:

Values are in 1024-byte increments, except for -t, which is in seconds,
-p, which is in increments of 512 bytes, and -u, which is an unscaled
number of processes.

Your version is probably older than the bash-5.2-rc3, which is fine, the size of that item hasn't changed in at least the last decade since 4.0.38 was released. You can see it here and here.

Edit: the man page for units.7 explains this in detail, but it appears to be quite messy from the UnitsPolicy.

CG3
  • 316
  • 1
  • 7
7

No, kilobytes is 1000. We follow the International System of Units so the prefix "kilo" refers to 1000 not 1024. Any other reference is wrong.

1024 is Kibibytes (kilo binary)

From ulimit -a:

max memory size (kbytes, -m) unlimited

This I consider a bug. It should explicity state kilo or kibi; not kbytes

man time:

M Maximum resident set size of the process during its lifetime, in Kilobytes.

  • ulimit uses KIBIbytes

    limit.rlim_cur = newlimit * 512;
    limit.rlim_max = newlimit * 512;
    
  • GNU time usus KIBIbytes if you look at the source. The manual is wrong.

    It uses:

    tmp = pages / 1024;  /* Smaller first, */
    size = tmp / 1024;    /* then smaller.  */
    
Rinzwind
  • 309,379
3

A kilobyte is 1000 bytes (SI prefix meaning thousand). A kibibyte is 1024 bytes (IEC prefix meaning kilo binary).

This convention has been used since 1998, but I guess the usage of these prefixes are not as known as they should be.

This is also why a 1 TB (terabyte) harddisk is only 0.91 TiB (tebibytes, as reported by the filesystem).

A related issue is when authors state that a number is given in "kbytes". Since this is not an official declaration, you don't know if they mean one or the other.

Since the ulimit help page says: "Values are in 1024-byte increments", I believe it is safe to assume that they do in fact mean kibibytes when they write kbytes.

On the other hand, since man time explicitly states that values are in kilobytes, one would have to assume that the authors are aware what a kilobyte is, and that they do in fact mean 1000 bytes.

In any case however, to be 100% certain that the authors haven't written anything that is explicitly wrong, you should check the sourcecode or consult the author of the program.

References:

Artur Meinild
  • 31,035