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.