Linux buffer cache state

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.

~ by panoskrt on October 27, 2009.

One Response to “Linux buffer cache state”

  1. [...] Linux buffer cache state « : | : vortex of false deceit : | : panoskrt.wordpress.com/2009/10/27/linux-buffer-cache-state – view page – cached 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… (Read more)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. (Read less) — From the page [...]

Leave a Reply