Commit 2ebcf516 authored by Julius Plenz's avatar Julius Plenz

fdatasync() if fd is writable

parent ffcf68bb
default:
gcc -Wall -fPIC -c -o nocache.o nocache.c
gcc -Wall -fPIC -c -o fadv_dontneed.o fadv_dontneed.c
gcc -Wall -shared -Wl,-soname,nocache.so.1 -ldl -o nocache.so nocache.o fadv_dontneed.o
gcc -Wall -fPIC -c -o fcntl_helpers.o fcntl_helpers.c
gcc -Wall -shared -Wl,-soname,nocache.so.1 -ldl -o nocache.so nocache.o fcntl_helpers.o
#include <fcntl.h>
#include <unistd.h>
/* Since open() and close() are re-defined in nocache.c, it's not
* possible to include <fcntl.h> there. So we do it here. */
......@@ -7,3 +8,12 @@ int fadv_dontneed(int fd, off_t offset, off_t len)
{
return posix_fadvise(fd, offset, len, POSIX_FADV_DONTNEED);
}
void sync_if_writable(int fd)
{
int r;
if((r = fcntl(fd, F_GETFL, 0)) == -1)
return;
if(!(r & O_RDONLY))
fdatasync(fd);
}
......@@ -18,6 +18,7 @@ int close(int fd);
static void store_pageinfo(int fd);
static void free_unclaimed_pages(int fd);
extern int fadv_dontneed(int fd, off_t offset, off_t len);
extern void sync_if_writable(int fd);
#define _MAX_FDS 1024
......@@ -141,6 +142,8 @@ static void free_unclaimed_pages(int fd)
if(i == _MAX_FDS)
return; /* not found */
sync_if_writable(fd);
for(j = 0; j < fds[i].nr_pages; j++) {
if(!(fds[i].info[j] & 1)) {
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