Linux System Memory Utilization
Linux System Memory Utilization
In this Document
Purpose
Questions and Answers
Q1. How to read 'free' command output.
A1. How to read 'free' command output.
A1.1 From the perspective of Operating System
A1.2 From the perspective of applications
A1.3 More accurate
Q2. How to forcefully free the cached memory.
Q3. How the cached memory improve the system performance.
Q4. How to get the memory usage by a specific process.
Q5. When hugepage is enabled.
References
APPLIES TO:
PURPOSE
Some Linux user may be confused by the Linux memory utilize: the memory used by application and the memory reported by 'free'
command does not match.
Why this server have only 945MB memory left, which process consume so much memory?
The second line was the memory utilize from the Operating System's perspective:
170MB Memory used for buffers, which was relatively temporary storage
for raw disk blocks, shouldn't get tremendously large.
3631MB Memory used for cached, which was In-memory cache for files
read from the disk (the pagecache, as well as dentry cache, and
inode cache)
The buffer/cache will increase the I/O performance, they can be returned to OS once any application need more memory.
Note: some recently used memory usually don't return to OS unless absolutely necessary:
After excluding the 'buffers' and 'cached' from the 'used' memory, we get the memory utilization from the perspective of applications:
Though it's possible to free the cached memory (see Q2), but kernel would not reclaim the caches for recently used files, unless it's
necessary.
Freeing caches for recently used files may result in performance degradation (see Q3).
# cat /proc/meminfo
MemTotal: 8069496 kB
MemFree: 6369944 kB
Buffers: 341724 kB
Cached: 414800 kB
SwapCached: 0 kB
Active: 839852 kB
Inactive: 503996 kB
[SNIP]
So you may consider free memory as MemFree + Inactive for a system with good performance, while free + buffers + cached is the
bottom line.
However, if after it has been determined that a specific case does need the cache to be forcibly freed, follow the instructions below:
According to Linux kernel document: writing to /proc/sys/vm/drop_caches will cause the kernel to drop clean caches, dentries and
inodes from memory, causing that memory to become free.
To free pagecache:
Create a new file of 200MB, we can also see the cached increased by 200MB, exactly the same size of the newly create file.
real 0m0.102s
user 0m0.000s
sys 0m0.038s
Drop the cached memory, so the file was not cached anymore.
Redo the test, the result was about 20 times slower than the cached.
real 0m2.016s
user 0m0.001s
sys 0m0.128s
1) Linux would not load the entire resource (VSZ) into memory, but only part of them are residential on the physical memory (RSS).
For example, the Virtual memory size required by bash was 108500KB, but only 1864KB are residential on memory.
2) Many libraries are shared between processes, they only consume 1 copy of the memory for many different processes.
For example, in the following output, ld-2.12.so, libc-2.12.so, libdl-2.12.so, and libnss_files-2.12.so are shared libraries, which may be
used by other processes as well.
When hugepage is enabled, kernel reserved a specified amount memory for hugepage.
Only the applications support hugepage such as Oracle Database with proper configuration are able to make use of hugepage.
To verify the hugepage utilization:
# cat /proc/meminfo
[SNIP]
HugePages_Total: 1000
HugePages_Free: 600
HugePages_Rsvd: 400
HugePages_Surp: 0
Hugepagesize: 2048 kB
[SNIP]
In the above example, kernel reserved 1000 * 2048kB (HugePages_Total * Hugepagesize) for hugepage.
Part of the hugepage were unused and wasted, the amounts equal to (HugePages_Free - HugePages_Rsvd) * Hugepagesize,
That's (600 - 400) * 2048kb wasted.
It's very important not to waste hugepage, since most applications don't support it.
For Oracle Database, please follow this note for proper hugepage configuration.
Shell Script to Calculate Values Recommended Linux HugePages / HugeTLB Configuration (Doc ID 401749.1)
REFERENCES
https://www.kernel.org/doc/Documentation/sysctl/vm.txt
NOTE:1502301.1 - How to Check Whether a System is Under Memory Pressure
NOTE:1630754.1 - How to Calculate Memory Usage on Linux
Didn't find what you are looking for?