I am booting a disk image via PXE, it is a full system on an initrd ramdisk. I would like to measure the actual free memory of the system (not including buffers and file system caching). I was told this is done by adding the MemFree, Buffers and Cached values from /proc/meminfo. For a regular system this gives accurate results.

However with my ramdisk setup it does not give accurate results. I assume that the memory that is used by the ramdisk is added to the "Cached" value:

[root@node1 ~]# cat /proc/meminfo
MemTotal:        8173700 kB
MemFree:         7443696 kB
Buffers:               0 kB
Cached:           650236 kB
SwapCached:            0 kB
MemCommitted:          0 kB
VirtualSwap:           0 kB
Active:            27156 kB
Inactive:         632204 kB
Active(anon):       4636 kB
Inactive(anon):     4616 kB
Active(file):      22520 kB
Inactive(file):   627588 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:          9156 kB
Mapped:             8712 kB
Shmem:               128 kB
Slab:              38548 kB
SReclaimable:      29420 kB
SUnreclaim:         9128 kB
KernelStack:         536 kB
PageTables:         1268 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     4086848 kB
Committed_AS:      51216 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      288032 kB
VmallocChunk:   34359448036 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       10240 kB 
DirectMap2M:     8378368 kB

Now this unfortunately gives me incorrect values for two metrics I would like to calculate: %MemUsed and AmountMemFreeActual. With a Ramdisk the "Cached" value is at least in part unreclaimable, and therefore cannot be used to calculate the actual Free memory.

To calculate both correctly, I would need to know the memory usage of the ramdisk, and i do not think I can simply take the "Cached" value, since this might also include other Cached Filesystem data.

Preferably I would like to take the ramdisk memory use out of the picture for both metrics, since it is unreclaimable memory AFAIK. Any ideas where to look?

Edit: "free" (@answer1) does provide the same wrong values. The "free" value from the "free" output is misleading anyways. "Free" memory is usually "Free"+"Buffers"+"Cached". My problem is that the ramdisk as non reclaimable memory (unlike usually cached filesystem data) cannot be reclaimed.

  • you might have to manually subtract the usage of any tmpfs - df -t tmpfs (e.g. if you are using an initramfs) - and any old-style ramdisk devices (e.g. initrd). At least when running an old-style initrd, I expect you can just look at the size of the ramdisk: blockdev --getsize64 /dev/ram0. – sourcejedi Oct 25 '18 at 15:09

Is there a reason you can't use the free command to determine how much RAM is available?

# free output in MBs
$ free -m
             total       used       free     shared    buffers     cached
Mem:          7800       6724       1075          0        397       1952
-/+ buffers/cache:       4374       3425
Swap:         5823         27       5796

The above shows that without the buffers and cache there's ~3.4GB free.

| improve this answer | |
  • 2
    thats correct. The Problem with that 3.4 GB free calculation is the assumption that cached and buffered is reclaimable memory. With initramfs that assumption is wrong concerning cached, thus the free calculation +/- buffers/cache is incorrect/meaningless. – dfens123 Jun 5 '13 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.