Professional Documents
Culture Documents
com/)
P O R TA L
What is cache in "free -m" output and why is memory utilization high for
cache?
$ SOLUTION VERIFIED - Updated March 15 2018 at 1:34 PM - English ()
Environment
Red Hat Enterprise Linux (All Releases)
JBoss Enterprise Application Platform (EAP) - All versions
Issue
What is cache in free -m output and why is memory utilization high for cache ?
How to check memory capacity required for Heap to create new server instance of JBoss by analyzing the free command
output in JBoss, if there is already one instance of JBoss running?
Why are large amounts of memory used by cache?
Physical memory fully utilized frequently in cache
Resolution
What is cache in free -m ?
It shows the amount of RAM which is currently used by the page cache. The page cache is a copy in memory of data which was read
from or written to disk. In simple terms we can say the page cache is a copy of disk data available in memory.
What is the advantage of having the cache mechanism?
C U S T O M E R (https://access.redhat.com/)
Kernel read and write operations
P O R TA L operate on main memory. Whenever any read or write operation is performed, the kernel first needs
to copy the required data into memory:
Read operation:
- go to disk and search for data
- write the data from disk into memory
- perform read operation
Write Operation:
- go to disk and search for data
- write the data from disk into memory
- perform write operation
- copy the modified data back to disk
Summary:
- Accessing disks is very slow compared to accessing memory
- By using cache, fetching and writing data to disk for every read and wrote operation can be avoided
- Periodically, modified ("dirty") data in the page cache is written to disk
- This tremendously increases processing speed and system performance
2. Now clear the page cache with following command NOTE: This command is used only for the sake of explanation. It is not
recommended to use this command if the system performs high I/O operations. Do not use this command in a production
environment.
# sync C U S T O M E R (https://access.redhat.com/)
P O R TA L
# echo 3 > /proc/sys/vm/drop_caches
3. Now check the time required to read the newly created file for the first time after creation. It shows 115 milliseconds.
real 0m0.115s
user 0m0.001s
sys 0m0.002s
4. The "XYZ" file should now be present in cache after Step-3, Now check the time required to read file again. It is only 2 milliseconds.
real 0m0.002s
user 0m0.000s
sys 0m0.001s
5. The access time was reduced by a factor of more than 50. So whenever there is free memory, the kernel will always try to utilize it to
save the required files as cache.
What happens if there is no free RAM left and a new process needs free RAM?
When a new process requires free pages on RAM, at that time the kernel will check if there are any pages in the cache and accordingly
the kernel will reclaim free pages by pushing back (syncing) the files from cache to the local disk and free up memory for new
processes.
# free -m C U S T O M E R (https://access.redhat.com/)
total P O Rused
TA L free shared buffers cached
Mem: 3753 3455 298 0 144 664
-/+ buffers/cache: 2645 1107 <<-- Actual Free RAM
Swap: 4095 75 4020
In the above example, the total memory is 3753 MB, out of which 3455 MB is in use and 298 MB is free.
cache and buffers is considered as used memory, but they can be dropped in favour of applications.
Out of 3455 MB of used RAM, some amount of RAM is used for cache and buffers. As discussed earlier memory from cache and
buffers can be reclaimed whenever there is no free RAM available for new processes. So cache and buffer can be considered as
free RAM. Therefore the actual size of free RAM can be calculated by the below formula:
Per the Linux virtual memory manager, this behavior is normal. To understand why cache memory can become so high, and why
this is not an issue, one must understand how I/O works on Linux. When a user process reads or writes a file, it is actually
modifying a copy of that file in main memory. The kernel creates that copy from the disk and writes back changes to it when
necessary. The memory taken up by these copies is called cached memory.
Cached memory will be consumed whenever a user process initiates a read or write. The kernel will look for a copy of the part of
the file the user is acting on, and, if no such copy exists, it will allocate one new page of cache memory and fill it with the
appropriate contents read out from the disk. If the user only reads the file, this page will be marked as a "clean" cache page.
However, as soon as the user writes the file, the page will be marked "dirty." A kernel thread which appears in ps called pdflush will
wake up periodically and copy all of the pages marked dirty back to the disk, then mark them as clean again. Note that the page
is only re-marked as clean, the page is not freed when it is written back, but is kept around in case something wants to do further
IO on the part of the file it caches.
Cache pages are only freed again when the kernel needs memory for something else. Since having the cache page already read
C U S T O M E R (https://access.redhat.com/)
from disk can speed
P O up
R TAI/O,
L and since getting rid of a clean cache page is just as easy as allocating a free page, and since a free
page is doing nothing to help the system perform and function, there is no reason to turn a cache page into a free page. If
memory fills up with cache pages, the next time the kernel needs memory it will simply evict the least recently used clean cache
pages and re-purpose them.
Tags cache (/tags/cache) eap (/tags/eap) jboss (/tags/jboss) kernel (/tags/kernel) memory (/tags/memory) performance (/tags/performance)
rhel (/tags/rhel)
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have
created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be
presented in a raw and unedited form.
When JON reports free and used memory on a Linux platform resource it does not take into account cached and buffered
memory
C U S T O M E R (https://access.redhat.com/)
Amount of cached memory in free -m differs from amount in /proc/meminfo
P O R TA L
Why does my system utilize swap space instead of freeing up cache and buffer memory?
9 Comments
27 January 2012 11:10 AM (https://access.redhat.com/solutions/67610#comment-338123)
PRO
552 Above command is for local user. For root user below command can also be used.
Points
≤ Reply (/Ajax_comments/Reply/67610/338123)
13 September 2016 7:30 AM (https://access.redhat.com/solutions/67610#comment-1097261)
C U S T O M E R (https://access.redhat.com/)
UT unix team (/user/5212783)
P O R TA L
(/user/5212783)
Not releasing memory from cache as per deman from application. And application is facing memory issue
NEWBIE
5 Points
≤ Reply (/Ajax_comments/Reply/67610/1366311)
≤ Reply (/Ajax_comments/Reply/67610/1389331)
≤ Reply (/Ajax_comments/Reply/67610/1468941)