Cache is a very important part of the computer hardware to give superfast response time.
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:
To make it executable, run:
chmod +x cachestat
Finally run it:
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 firstname.lastname@example.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.