24.3.3.2. Memory size
Can be set across emulators with:
./run --memory 512M
We can verify this on the guest directly from the kernel with:
cat /proc/meminfo
as of LKMC 1e969e832f66cb5a72d12d57c53fb09e9721d589 this output contains:
MemTotal: 498472 kB
which we expand with:
printf '0x%X\n' $((498472 * 1024))
to:
0x1E6CA000
TODO: why is this value a bit smaller than 512M?
free
also gives the same result:
free -b
contains:
total used free shared buffers cached Mem: 510435328 20385792 490049536 0 503808 2760704 -/+ buffers/cache: 17121280 493314048 Swap: 0 0 0
which we expand with:
printf '0x%X\n' 510435328$((498472 * 1024)
man free
from Ubuntu’s procps 3.3.15 tells us that free
obtains this information from /proc/meminfo
as well.
From C, we can get this information with sysconf(_SC_PHYS_PAGES)
or get_phys_pages()
:
./linux/total_memory.out
Source: userland/linux/total_memory.c
Output:
sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) = 0x1E6CA000 sysconf(_SC_AVPHYS_PAGES) * sysconf(_SC_PAGESIZE) = 0x1D178000 get_phys_pages() * sysconf(_SC_PAGESIZE) = 0x1E6CA000 get_avphys_pages() * sysconf(_SC_PAGESIZE) = 0x1D178000
This is mentioned at: https://stackoverflow.com/questions/22670257/getting-ram-size-in-c-linux-non-precise-result/22670407#22670407
AV means available and gives the free memory: https://stackoverflow.com/questions/14386856/c-check-available-ram/57659190#57659190