How to Purge Disk I/O Caches on Linux

How to purge disk I/O caches on Linux?

Sounds like you want the sync command, or the sync() function.

If you want disk cache flushing: echo 3 | sudo tee /proc/sys/vm/drop_caches

How to stop page cache for disk I/O in my linux system?

I'm not sure that changing something will affect overall performance.

Maybe you might use posix_fadvise(2) and sync_file_range(2) in your program (and more rarely fsync(2) or fdatasync(2) or sync(2) or syncfs(2), ...). Also look at madvise(2), mlock(2) and munlock(2), and of course mmap(2) and munmap(2). Perhaps ionice(1) could help.

In the reader process, you might perhaps use readhahead(2) (perhaps in a separate thread).

Upgrading your kernel (to a 3.6 or better) could certainly help: Linux has improved significantly on these points since 2.6.32 which is really old.

Disabling disk cache in linux

You need root access to do this. You can run hdparm -W 0 /dev/sda command to disable write caching, where you have to replace /dev/sda with device for your drive:

#include <stdlib.h>
...
system("hdparm -W 0 /dev/sda1");

You can also selectively disable write caching to individual partitions like this: hdparm -W 0 /dev/sda1.

To reenable caching again just use the -W 1 argument.

man hdparm, man system

Linux memory management (caching)

In linux two caches were distinct: Files were in the page cache, disk blocks were in the buffer cache. Given that most files are represented by a filesystem on a disk, data was represented twice, once in each of the caches. Many Unix systems follow a similar pattern.

The buffer cache remains, however, as the kernel still needs to perform block I/O in terms of blocks, not pages. As most blocks represent file data, most of the buffer cache is represented by the page cache. But a small amount of block data isn't file backed—metadata and raw block I/O for example—and thus is solely represented by the buffer cache.

How to clean caches used by the Linux kernel

You may want to increase vfs_cache_pressure as well as set swappiness to 0.

Doing that will make the kernel reclaim cache faster, while giving processes equal or more favor when deciding what gets paged out.

You may only want to do this if processes you care about do very little disk I/O.

If a network I/O bound process has to swap in to serve requests, that's a problem and the real solution is to put it on a less competitive server.

With the default swappiness setting, the kernel is almost always going to favour keeping FS related cache in real memory.

As such, if you increase the cache pressure, be sure to equally adjust swappiness.

Clear file cache to repeat performance testing

Use SysInternal's RAMMap app.

rammap empty standby

The Empty / Empty Standby List menu option will clear the Windows file cache.



Related Topics



Leave a reply



Submit