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.
The Empty / Empty Standby List menu option will clear the Windows file cache.
Related Topics
Mechanism of Clipboard of Xwindow
Install Marklogic Centos Virtualbox Vm
How to Configure Bash to Handle Crlf Shell Scripts
Cmake Auto Header File Dependency
Matlab Mex Socket Wrapper Library
Linux, Where Are the Return Codes Stored of System Daemons and Other Processes
Embedding the Password in the Bash Script
Determining the Path That a Yum Package Installed To
How to Tar Certain File Types in All Subdirectories
Recursively Find Files with a Specific Extension
How Does Ngrok Work Behind a Firewall
Logo Programming Language Implementations
How to Pass a File Argument to My Bash Script Using a Terminal Command in Linux
Selecting Text in Terminal Without Using the Mouse
Is There Any Method to Run Perf Under Wsl
How to Export Database Schema in Oracle to a Dump File
How to Use Sed to Remove the Last N Lines of a File
How to Prepend a Directory the Library Path When Loading a Core File in Gdb on Linux