Following Faidon’s comment on an earlier post, I came across this informative site concerning Linux’s buffer cache state. In a nutshell, the following code will release all the cached data of a specified file.
#define _XOPEN_SOURCE 600 #include <unistd.h> #include <fcntl.h> int main(int argc, char *argv[]) { int fd; fd = open(argv[1], O_RDONLY); fdatasync(fd); posix_fadvise(fd, 0,0,POSIX_FADV_DONTNEED); close(fd); return 0; }
There are some useful samples and examples on the mentioned web page. posix_fadvise description here.
Pingback: Twitter Trackbacks for Linux buffer cache state « : | : vortex of false deceit : | : [panoskrt.wordpress.com] on Topsy.com