Operating System - Linux
1752378 Members
6509 Online
108788 Solutions
New Discussion юеВ

Re: how to clear cache memory in linux

 
SOLVED
Go to solution
bullz
Super Advisor

how to clear cache memory in linux

Hello Gurus,

I have a doubt on memory here.
As per the below details.

total used free shared buffers cached
Mem: 8046296 5224000 2822296 0 696388 2917184

Total memory usage is 5224000 which includes (actual usage + cached right)?
If thatтАЩs is the case so,

1) What is cached? ( as of I know, itтАЩs used for tmp usage as like swap ) Correct me if I am wrong.
2) Can I clear cache to make my memory usage better?
3) If so, how to clear cache memory.
4 REPLIES 4
Ivan Ferreira
Honored Contributor
Solution

Re: how to clear cache memory in linux

1) What is cached?

Information for recent/frecuently used data, as file system structures and data.

2) Can I clear cache to make my memory usage better?

The operating system handles that for you. You don't need to manually clear the cache. The OS is very efficient using memory.

Related information:

http://www.cyberciti.biz/faq/linux-kernel-tuning-virtual-memory-subsystem/

Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
P Muralidhar Kini
Honored Contributor

Re: how to clear cache memory in linux

Hi bullz,


>> 1) What is cached? ( as of I know, its used for tmp usage as like swap )
>> Correct me if I am wrong.
Files that are actively used on a system are cached.
i.e. when you access the file form the disk for the first time, it is fetched from
disk. This time it gets copied to cache also. Next time if the same file is
accessed the OS gives you the file from the cache itself. The IO to the disk is
avoided and hence you get performance improvement. Data is got by
accessing the main memory rather than the disk and hence the performance boost.

Generally most Cache's use the LRU mechanism to keep/remove data from
the cache. i.e. the file that gets most actively used will remain in the cache
for more time when compared to other files.

>> 2) Can I clear cache to make my memory usage better?
The OS does this for you. It does the complete cache management and hence
you dont have to worry about it.

However if there are any application that can thrash the cache then you have to
deal with those. By thrashing the cache i mean some bulk disk accessing
operation like backup of disk which would access the entire contents of the
disk and hence would get them in cache. But in doing so the data already in
cache gets knowcked out.

Hope this helps.

Regards,
Murali
Let There Be Rock - AC/DC
Goran┬аKoruga
Honored Contributor

Re: how to clear cache memory in linux

Hello.

From Documentation/sysctl/vm.txt:

drop_caches

Writing to this will cause 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_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, the
user should run `sync' first.

Regards,
Goran
bullz
Super Advisor

Re: how to clear cache memory in linux

Thanx all