Commit db0b9fb1 authored by Julius Plenz's avatar Julius Plenz

fadvise NOREUSE and fadvise DONTNEED *twice*

There is a promising patch that adds POSIX_FADV_NOREUSE heuristics, see http://article.gmane.org/gmane.linux.kernel.mm/65564 > This will mean that there is no way currently to > remove a particular file from the cache on linux. Correct. There's not a way to do this for a single file (except running POSIX_FADV_DONTNEED twice...). If only one fadvise64 syscall is performed, the *first* previously unsused page will somehow not be forgotten.
parent 43c71e1a
...@@ -9,6 +9,11 @@ int fadv_dontneed(int fd, off_t offset, off_t len) ...@@ -9,6 +9,11 @@ int fadv_dontneed(int fd, off_t offset, off_t len)
return posix_fadvise(fd, offset, len, POSIX_FADV_DONTNEED); return posix_fadvise(fd, offset, len, POSIX_FADV_DONTNEED);
} }
int fadv_noreuse(int fd, off_t offset, off_t len)
{
return posix_fadvise(fd, offset, len, POSIX_FADV_NOREUSE);
}
void sync_if_writable(int fd) void sync_if_writable(int fd)
{ {
int r; int r;
......
...@@ -19,6 +19,7 @@ int close(int fd); ...@@ -19,6 +19,7 @@ int close(int fd);
static void store_pageinfo(int fd); static void store_pageinfo(int fd);
static void free_unclaimed_pages(int fd); static void free_unclaimed_pages(int fd);
extern int fadv_dontneed(int fd, off_t offset, off_t len); extern int fadv_dontneed(int fd, off_t offset, off_t len);
extern int fadv_noreuse(int fd, off_t offset, off_t len);
extern void sync_if_writable(int fd); extern void sync_if_writable(int fd);
#define _MAX_FDS 1024 #define _MAX_FDS 1024
...@@ -51,6 +52,7 @@ int open(const char *pathname, int flags, mode_t mode) ...@@ -51,6 +52,7 @@ int open(const char *pathname, int flags, mode_t mode)
if((fd = _original_open(pathname, flags, mode)) != -1) { if((fd = _original_open(pathname, flags, mode)) != -1) {
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
store_pageinfo(fd); store_pageinfo(fd);
fadv_noreuse(fd, 0, 0);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
} }
return fd; return fd;
...@@ -155,6 +157,7 @@ static void free_unclaimed_pages(int fd) ...@@ -155,6 +157,7 @@ static void free_unclaimed_pages(int fd)
for(j = 0; j < fds[i].nr_pages; j++) { for(j = 0; j < fds[i].nr_pages; j++) {
if(!(fds[i].info[j] & 1)) { if(!(fds[i].info[j] & 1)) {
fadv_dontneed(fd, j*PAGESIZE, PAGESIZE); fadv_dontneed(fd, j*PAGESIZE, PAGESIZE);
fadv_dontneed(fd, j*PAGESIZE, PAGESIZE);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment