Commit 5e6c065f authored by Julius Plenz's avatar Julius Plenz

fadvise maximum possible range, not just pages

Also, fadv_dontneed will do the double syscall now.
parent db0b9fb1
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
int fadv_dontneed(int fd, off_t offset, off_t len) int fadv_dontneed(int fd, off_t offset, off_t len)
{ {
if(posix_fadvise(fd, offset, len, POSIX_FADV_DONTNEED) == -1)
return -1;
return posix_fadvise(fd, offset, len, POSIX_FADV_DONTNEED); return posix_fadvise(fd, offset, len, POSIX_FADV_DONTNEED);
} }
......
...@@ -154,15 +154,19 @@ static void free_unclaimed_pages(int fd) ...@@ -154,15 +154,19 @@ static void free_unclaimed_pages(int fd)
sync_if_writable(fd); sync_if_writable(fd);
for(j = 0; j < fds[i].nr_pages; j++) { int start;
if(!(fds[i].info[j] & 1)) { start = j = 0;
fadv_dontneed(fd, j*PAGESIZE, PAGESIZE); while(j < fds[i].nr_pages) {
fadv_dontneed(fd, j*PAGESIZE, PAGESIZE); if(fds[i].info[j] & 1) {
if(start < j)
fadv_dontneed(fd, start*PAGESIZE, (j - start) * PAGESIZE);
start = j + 1;
} }
j++;
} }
/* forget written contents that go beyond previous file size */ /* forget written contents that go beyond previous file size */
fadv_dontneed(fd, fds[i].size, 0); fadv_dontneed(fd, start < j ? start*PAGESIZE : fds[i].size, 0);
if(fds[i].info) if(fds[i].info)
free(fds[i].info); free(fds[i].info);
......
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