[PATCH] mm: Support madvise_willneed override by Filesystems

From: Boaz Harrosh
Date: Thu May 16 2019 - 13:02:14 EST


In the patchset:
[b833a3660394] ovl: add ovl_fadvise()
[3d8f7615319b] vfs: implement readahead(2) using POSIX_FADV_WILLNEED
[45cd0faae371] vfs: add the fadvise() file operation

Amir Goldstein introduced a way for filesystems to overide fadvise.
Well madvise_willneed is exactly as fadvise_willneed except it always
returns 0.

In this patch we call the FS vector if it exists.

NOTE: I called vfs_fadvise(..,POSIX_FADV_WILLNEED);
(Which is my artistic preference)

I could also selectively call
if (file->f_op->fadvise)
return file->f_op->fadvise(..., POSIX_FADV_WILLNEED);
If we fear theoretical side effects. I don't mind either way.

CC: Amir Goldstein <amir73il@xxxxxxxxx>
CC: Miklos Szeredi <mszeredi@xxxxxxxxxx>
Signed-off-by: Boaz Harrosh <boazh@xxxxxxxxxx>
---
mm/madvise.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 6cb1ca93e290..6b84ddcaaaf2 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -24,6 +24,7 @@
#include <linux/swapops.h>
#include <linux/shmem_fs.h>
#include <linux/mmu_notifier.h>
+#include <linux/fadvise.h>

#include <asm/tlb.h>

@@ -303,7 +304,8 @@ static long madvise_willneed(struct vm_area_struct *vma,
end = vma->vm_end;
end = ((end - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;

- force_page_cache_readahead(file->f_mapping, file, start, end - start);
+ vfs_fadvise(file, start << PAGE_SHIFT, (end - start) << PAGE_SHIFT,
+ POSIX_FADV_WILLNEED);
return 0;
}

--
2.20.1