What data is cached by operation system

In a former post, we know that with the help of defrag_mem we can clean up buffers / cached memory to gain more real “free” memory. Defrag_mem works like common windows memory optimizer, it asks for as much memory as possible, and then free them all. This way is not suggested on productive servers unless you have no other choices. On linux, the ram is more efficiently used compared to Windows, most of the free RAM would be used for system cache.

This post will also show a way to free your memory, and it’s more efficient than defrag_mem.

Let’s go back to the topic of this post:
Is there any ways to find out how much data of a file is cached by a running operation system?
Absolutly the answer is yes, we can do it simply by fincore.

fincore is a command that shows which pages (blocks) of a file are in core memory. It is particularly useful for determining the contents of the buffer-cache. Fincore means “File IN CORE”, it’s a perl script created by Dave Plonka at 2007, running well on Linux, both kernel-2.4 and kernel-2.6.

After finished the installation, let’s start a quick test here:

Here is a sample output:

[admon@maxpace bdb]$ ls |grep '.db$' | ~admon/fincore --stdin --justsummarize
page size: 4096 bytes
158360 pages, 618.6 Mbytes in core for 256 files; 618.59 pages, 2.4 Mbytes per file.
[admon@maxpace bdb]$ du -sh .
8.2G    .

From the above commands, we can see that, there’re 8.2GB BDB files in total, while only 618.6MB data are cached by core memory. For each file, it uses 618.59 memory pages, eats 2.4MB system cache.

Another sample testing:

[admon@maxpace bdb]$ ls abc.db | ~admon/fincore --stdin --justsummarize
page size: 4096 bytes
546 pages, 2.1 Mbytes in core for 1 file; 546.00 pages, 2.1 Mbytes per file.
[admon@maxpace bdb]$ cat abc.db >/dev/null
[admon@maxpace bdb]$ ls -sh abc.db
34M abc.db
[admon@maxpace bdb]$ ls abc.db | ~admon/fincore --stdin --justsummarize
page size: 4096 bytes
8722 pages, 34.1 Mbytes in core for 1 file; 8722.00 pages, 34.1 Mbytes per file.

From the commands above, the output is pretty clear!
By using “cat abc.db > /dev/null”, we force the core system momory caches the whole file. The result is pretty fine!
For more details about finecore, please check this link.

Now, another question may come! It’s easy to find out cache status for a specified file, how can I remove the cached data smoothly without rebooting system?
Dave Plonka created another script named fadvise for doing so, it’s as smart as fincore, which doing the things quite well as expected.

Here is a sample output:

[admon@maxpace bdb]$ ls abc.db | ~admon/fincore --stdin --justsummarize
page size: 4096 bytes
8722 pages, 34.1 Mbytes in core for 1 file; 8722.00 pages, 34.1 Mbytes per file.
[admon@maxpace bdb]$ ~admon/fadvise --verbose --dontneed abc.db 
page size: 4096
abc.db: no incore pages.
[admon@maxpace bdb]$ ls abc.db | ~admon/fincore --stdin --justsummarize
page size: 4096 bytes
0 pages, 0.0  bytes in core for 1 file; 0.00 pages, 0.0  bytes per file.

Which the help of these two scripts, you may save a lot of system I/O operations by carefully tweaking cached files.
The manual for fadvise is available here at net.doit.wise.edu.

5 thoughts on “What data is cached by operation system

  1. Just found your planet page its great, best site I seen for ages. This is a wonderful wealth of information, it looks like you folks do great service keep up the good work. Thanks :-D. Edwina.

  2. Thanks very much for sharing this interesting post. I am just starting up my own blog and this has given me inspiration to what I can achieve.

  3. I don’t agree with everything in this blog, but you do make some very good points. Im very interested in this topic and I myself do alot of research as well.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.