Search code examples
perlunixmemoryout-of-memory32-bit

Why was I able to load 4.19 GB of memory when `perl -V:ptrsize` returned 4?


I have this output:

root@hostname:/home/admin# perl -V:ptrsize
ptrsize='4';

According to this answer, ptrsize='4' means that perl is able to address 4GB of memory.

However, while loading huge data into the memory, I was consistently able to load exactly 4190924 (4.19) before hitting Out of memory error.

Why did it not fail at 4000000 (4GB) as expected?

For the sake of completeness, I checked the amount of memory used by running qx{ grep VmSize /proc/$$/status };


Solution

  • The limit for a 32-bit pointer is 2^32 = 4,294,967,296 bytes, properly expressed as 4 GiB, but commonly called 4GB. This is 4,194,304 kiB (the unit that VmSize reports in). You came within 4kiB (one page, on most systems) of that.