How to see cache statistics in Linux?

Cache is a very important part of the computer hardware to give superfast response time.

Cache Performance
When the processor needs to read or write a location in main memory, it first checks for a corresponding entry in the cache.

If the processor finds that the memory location is in the cache, a cache hit has occurred and data is read from cache
If the processor does not find the memory location in the cache, a cache miss has occurred. For a cache miss, the cache allocates a new entry and copies in data from main memory, then the request is fulfilled from the contents of the cache.



The performance of cache memory is frequently measured in terms of a quantity called Hit ratio.

Hit ratio = hit / (hit + miss) =  no. of hits/total accesses

To monitor the performance of your cache, linux provides some excellent library: Cachestat.

Cachestat is not directly available, it is deprecated by linux.
Cachestat uses the perf tools, which is a part of linux-tools library.

To install perf-tools, open terminal and run:

sudo apt-get install linux-tools-common linux-tools-generic

Then, to install cachestat, run:

wget https://raw.githubusercontent.com/brendangregg/perf-tools/master/fs/cachestat

To make it executable, run:

chmod +x cachestat

Finally run it:

sudo ./cachestat

If you get a lot of misses, you should probably run diagnostics.

This article is contributed by Suprotik Dey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.