diff options
author | Josef Bacik <josef@toxicpanda.com> | 2024-11-15 10:30:27 -0500 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2024-12-10 12:03:17 +0100 |
commit | fac84846a28c0950d4433118b3dffd44306df62d (patch) | |
tree | a5f4e5ac49665b0aabdf8c00ac0881d2f2380340 /mm/readahead.c | |
parent | b4b2ff4f61ded819bfa22e50fdec7693f51cbbee (diff) |
fanotify: disable readahead if we have pre-content watches
With page faults we can trigger readahead on the file, and then
subsequent faults can find these pages and insert them into the file
without emitting an fanotify event. To avoid this case, disable
readahead if we have pre-content watches on the file. This way we are
guaranteed to get an event for every range we attempt to access on a
pre-content watched file.
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/70a54e859f555e54bc7a47b32fe5aca92b085615.1731684329.git.josef@toxicpanda.com
Diffstat (limited to 'mm/readahead.c')
-rw-r--r-- | mm/readahead.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/mm/readahead.c b/mm/readahead.c index 8f1cf599b572..1fa4710bdf89 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -128,6 +128,7 @@ #include <linux/blk-cgroup.h> #include <linux/fadvise.h> #include <linux/sched/mm.h> +#include <linux/fsnotify.h> #include "internal.h" @@ -550,6 +551,15 @@ void page_cache_sync_ra(struct readahead_control *ractl, pgoff_t prev_index, miss; /* + * If we have pre-content watches we need to disable readahead to make + * sure that we don't find 0 filled pages in cache that we never emitted + * events for. Filesystems supporting HSM must make sure to not call + * this function with ractl->file unset for files handled by HSM. + */ + if (ractl->file && unlikely(FMODE_FSNOTIFY_HSM(ractl->file->f_mode))) + return; + + /* * Even if readahead is disabled, issue this request as readahead * as we'll need it to satisfy the requested range. The forced * readahead will do the right thing and limit the read to just the @@ -627,6 +637,10 @@ void page_cache_async_ra(struct readahead_control *ractl, if (!ra->ra_pages) return; + /* See the comment in page_cache_sync_ra. */ + if (ractl->file && unlikely(FMODE_FSNOTIFY_HSM(ractl->file->f_mode))) + return; + /* * Same bit is used for PG_readahead and PG_reclaim. */ |