Upload
haish
View
8.479
Download
2
Embed Size (px)
DESCRIPTION
Linux memory consumption - Why memory utilities show a little amount of free RAM? How does Linux kernel utilizes free RAM? What is the real amount of free RAM in the system?
Citation preview
1
Linux Memory Consumption
Hai Shalom
http://www.rt-embedded.com
2
Licensing
This presentation is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
Contributors to this document:Copyright © 2010 Hai Shalom –
http://www.rt-embedded.com
3
Attributions
This presentation is based on the article “Linux memory consumption”, written by Hai Shalom and taken from the Real-Time Embedded blog:http://www.rt-embedded.com/blog/archives/linux-memory-consumption/
4
Where is all the free RAM?
Traditional Unix tools like 'top‘ or ‘free’ often report a surprisingly small amount of free memory after a system has been running for a while. Where does it all go?
You may be thinking that there are problems with memory leaks, or that your available RAM is being used inefficiently or even that your system does not have enough RAM to run correctly.
5
So, where is it? Linux memory consumption concept is all
about efficiency. The system’s RAM is a resource that is meant
to be used; 100% of it (if possible), all the time (if possible).
Linux utilizes unused RAM to cache data and file system meta-data from slower storage devices (Flash or disk) because fetching the information from the RAM is much quicker
6
Continued
Assuming there are no memory leaks, the reason that memory report tools report low amount of free memory is because the RAM is considered to be wasted if it isn’t used.
The kernel tries to utilize the most of the RAM to improve the system performance
7
The /proc/meminfo The kernel provides
a special proc file called meminfo, which displays the memory consumption figures in details :
8
The /proc/meminfo important info MemTotal - Total amount of physical RAM, in
kilobytes. MemFree - The amount of physical RAM, in
kilobytes, left unused by the system. Buffers - The amount of physical RAM, in
kilobytes, used for file buffers. Cached - The amount of physical RAM, in
kilobytes, used as cache memory.
9
Some facts The amount of reclaimable memory in the
system, is the sum of MemFree, Buffers and Cached.
The Linux kernel will provide memory for applications, while reducing the amount of buffers and cached, if required.
10
Some facts - Continued
Using unused (clean) cache for applications will not impact the system performance.
Degradation in the performance will appear once starting to free used cache. In some point (in the last free 1MB) the degradation will be very noticeable and the system will become very slow.
11
Flush and invalidate caches
The following action increases the amount of MemFree by causing the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.To free pagecache:
echo 1 > /proc/sys/vm/drop_cachesTo free dentries and inodes:
echo 2 > /proc/sys/vm/drop_cachesTo free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
12
Flush and invalidate caches
As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.
This command does not free the currently used caches (like running processes).
13
Outcome of dropping caches
14
Kernel tunables regarding memory
min_free_kbytes: Used to force the Linux VM to keep a minimum number of kilobytes free.
overcommit_memory: Controls over-commit of system memory, possibly allowing processes to allocate (but not use) more memory than is actually available.
15
Q&A
Time to ask all the questions…
16
Thank you!
The full article is available at the Real-Time embedded blog: http://www.rt-embedded.com/blog/archives/linux-memory-consumption/
More information and articles are also available in the Real-Time Embedded blog
Contact me in the contact page, or send mail to: mailto:[email protected]
17
Backup slides
18
The /proc/meminfo in detail MemTotal - Total amount of physical RAM, in kilobytes. MemFree - The amount of physical RAM, in kilobytes, left
unused by the system. Buffers - The amount of physical RAM, in kilobytes, used
for file buffers. Cached - The amount of physical RAM, in kilobytes, used
as cache memory. Active - The total amount of buffer or page cache memory,
in kilobytes, that is in active use. This is memory that has been recently used and is usually not reclaimed for other purposes.
19
The /proc/meminfo in detail Inactive - The total amount of buffer or page cache memory, in
kilobytes, that are free and available. This is memory that has not been recently used and can be reclaimed for other purposes.
LowTotal and LowFree - The total and free amount of memory, in kilobytes, that is directly mapped into kernel space. The LowTotal value can vary based on the type of kernel used.
Mapped — The total amount of memory, in kilobytes, which have been used to map devices, files, or libraries using the mmap command.
Slab — The total amount of memory, in kilobytes, used by the kernel to cache data structures for its own use.
Committed_AS — The total amount of memory, in kilobytes, estimated to complete the workload. This value represents the worst case scenario value, and also includes swap memory.
20
The /proc/meminfo in detail
PageTables — The total amount of memory, in kilobytes, dedicated to the lowest page table level.
VMallocTotal — The total amount of memory, in kilobytes, of total allocated virtual address space.
VMallocUsed — The total amount of memory, in kilobytes, of used virtual address space.
VMallocChunk — The largest contiguous block of memory, in kilobytes, of available virtual address space.