Memory size for kernel mmap operation

There is no direct relationship between the size of the executable and the size in memory. Here's a very quick overview of what happens when a binary is executed:

  1. The kernel parses the file and breaks it into section. Some sections are directly loaded into memory, in separate pages. Some sections aren't loaded at all (e.g. debugging symbols).
  2. If the executable is dynamically linked, the kernel calls the dynamic loader, and it loads the required shared libraries and performs link edition as required.
  3. The program starts executing its code, and usually it will request more memory to store data.

For more information about executable formats, linking, and executable loading, you can read Linkers and Loaders by John R. Levine.

In a 5kB executable, it's likely that everything is code or data that needs to be loaded into memory except for the header. The executable code will be at least one page, perhaps two, and then there will be at least one page for the stack, probably one page or for the heap (other data), plus memory used by shared libraries.

Under Linux, you can inspect the memory mappings for an executable with cat /proc/$pid/maps. The format is documented in the proc(5) man page; see also Understanding Linux /proc/id/maps.