Just a few notes about how to get informations how memory on linux, and common tools to read them.
It’s possible to read about memory use under linux by multiple ways: /proc/meminfo, free, vmstat, top…
Those tools allow to get information about physical memory as virtual memory.
Firstly, we can get general infos reading /proc/meminfo or using free:
- MemTotal: Total usable ram (i.e. physical ram minus a few reserved bits and the kernel binary code)
- MemFree: Is sum of LowFree+HighFree (overall stat)
- Buffers: Memory in buffer cache
- Cached: Memory in the pagecache (diskcache) minus SwapCache (Doesn’t include SwapCached though)
- SwapCached: Memory that once was swapped out, is swapped back in but still also is in the swapfile
Then, we have to understand the top output:
- Virtual: Virtual memory allocated, including all code, data and shared libraries
- Resident: Non swapped physical memory
- Shared: Amount of memory available potentially shared with other proccesses
vmstat reports virtual memory statistics:
Les noyaux Linux récents fournissent un mécanisme pour que le noyau libère certains éléments stockés en mémoire à la demande, ce qui permet de libérer une partie de la mémoire. Pour cela, il faut utiliser le fichier /proc/sys/vm/drop_caches:
Recent linux kernels provide a mechanism to drop the page cache, inodes and dentry caches, which can free up a lot of memory, using virtual file /proc/sys/vm/drop_caches:
To free pagecache:
To free dentries and inodes:
To free pagecache, dentries and inodes:
These operations are non destructive and will only free non used things. Think to sync to flush I/O buffers before, and you may free more memory.