linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Josef Bacik <josef@toxicpanda.com>
Cc: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz,
	 brauner@kernel.org, linux-xfs@vger.kernel.org,
	linux-bcachefs@vger.kernel.org,  linux-btrfs@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v5 12/18] fanotify: disable readahead if we have pre-content watches
Date: Thu, 5 Sep 2024 10:12:32 +0200	[thread overview]
Message-ID: <CAOQ4uxjwU5g9hRXTyOY_2-KHSGR8eXv4unGrty4Gtj7JMkJffw@mail.gmail.com> (raw)
In-Reply-To: <5ce248ad6e7b551c6d566fd4580795f7a3495352.1725481503.git.josef@toxicpanda.com>

On Wed, Sep 4, 2024 at 10:29 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> 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>

Reviewed-by: Amir Goldstein <amir73il@gmail.com>


Thanks,
Amir.

> ---
>  mm/filemap.c   | 12 ++++++++++++
>  mm/readahead.c | 13 +++++++++++++
>  2 files changed, 25 insertions(+)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index ca8c8d889eef..8b1684b62177 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -3122,6 +3122,14 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)
>         unsigned long vm_flags = vmf->vma->vm_flags;
>         unsigned int mmap_miss;
>
> +       /*
> +        * If we have pre-content watches we need to disable readahead to make
> +        * sure that we don't populate our mapping with 0 filled pages that we
> +        * never emitted an event for.
> +        */
> +       if (fsnotify_file_has_pre_content_watches(file))
> +               return fpin;
> +
>  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>         /* Use the readahead code, even if readahead is disabled */
>         if ((vm_flags & VM_HUGEPAGE) && HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) {
> @@ -3190,6 +3198,10 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf,
>         struct file *fpin = NULL;
>         unsigned int mmap_miss;
>
> +       /* See comment in do_sync_mmap_readahead. */
> +       if (fsnotify_file_has_pre_content_watches(file))
> +               return fpin;
> +
>         /* If we don't want any read-ahead, don't bother */
>         if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages)
>                 return fpin;
> diff --git a/mm/readahead.c b/mm/readahead.c
> index 817b2a352d78..bc068d9218e3 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"
>
> @@ -674,6 +675,14 @@ void page_cache_sync_ra(struct readahead_control *ractl,
>  {
>         bool do_forced_ra = ractl->file && (ractl->file->f_mode & FMODE_RANDOM);
>
> +       /*
> +        * 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.
> +        */
> +       if (ractl->file && fsnotify_file_has_pre_content_watches(ractl->file))
> +               return;
> +
>         /*
>          * Even if readahead is disabled, issue this request as readahead
>          * as we'll need it to satisfy the requested range. The forced
> @@ -704,6 +713,10 @@ void page_cache_async_ra(struct readahead_control *ractl,
>         if (!ractl->ra->ra_pages)
>                 return;
>
> +       /* See the comment in page_cache_sync_ra. */
> +       if (ractl->file && fsnotify_file_has_pre_content_watches(ractl->file))
> +               return;
> +
>         /*
>          * Same bit is used for PG_readahead and PG_reclaim.
>          */
> --
> 2.43.0
>


  reply	other threads:[~2024-09-05  8:12 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-04 20:27 [PATCH v5 00/18] fanotify: add pre-content hooks Josef Bacik
2024-09-04 20:27 ` [PATCH v5 01/18] fanotify: don't skip extra event info if no info_mode is set Josef Bacik
2024-09-05  7:49   ` Amir Goldstein
2024-09-04 20:27 ` [PATCH v5 02/18] fsnotify: introduce pre-content permission event Josef Bacik
2024-09-04 20:27 ` [PATCH v5 03/18] fsnotify: generate pre-content permission event on open Josef Bacik
2024-10-24 13:06   ` Amir Goldstein
2024-09-04 20:27 ` [PATCH v5 04/18] fanotify: introduce FAN_PRE_ACCESS permission event Josef Bacik
2024-09-04 20:27 ` [PATCH v5 05/18] fanotify: introduce FAN_PRE_MODIFY " Josef Bacik
2024-09-04 20:27 ` [PATCH v5 06/18] fanotify: pass optional file access range in pre-content event Josef Bacik
2024-09-04 20:27 ` [PATCH v5 07/18] fanotify: rename a misnamed constant Josef Bacik
2024-09-04 20:27 ` [PATCH v5 08/18] fanotify: report file range info with pre-content events Josef Bacik
2024-09-04 20:27 ` [PATCH v5 09/18] fanotify: allow to set errno in FAN_DENY permission response Josef Bacik
2024-09-04 20:28 ` [PATCH v5 10/18] fs: add a flag to indicate the fs supports pre-content events Josef Bacik
2024-09-05  8:07   ` Amir Goldstein
2024-09-04 20:28 ` [PATCH v5 11/18] fanotify: add a helper to check for pre content events Josef Bacik
2024-09-05  8:09   ` Amir Goldstein
2024-09-04 20:28 ` [PATCH v5 12/18] fanotify: disable readahead if we have pre-content watches Josef Bacik
2024-09-05  8:12   ` Amir Goldstein [this message]
2024-09-04 20:28 ` [PATCH v5 13/18] mm: don't allow huge faults for files with pre content watches Josef Bacik
2024-09-05  8:14   ` Amir Goldstein
2024-09-04 20:28 ` [PATCH v5 14/18] fsnotify: generate pre-content permission event on page fault Josef Bacik
2024-09-04 20:28 ` [PATCH v5 15/18] bcachefs: add pre-content fsnotify hook to fault Josef Bacik
2024-09-04 20:28 ` [PATCH v5 16/18] xfs: add pre-content fsnotify hook for write faults Josef Bacik
2024-09-05  8:29   ` Amir Goldstein
2024-09-04 20:28 ` [PATCH v5 17/18] btrfs: disable defrag on pre-content watched files Josef Bacik
2024-09-05  8:23   ` Amir Goldstein
2024-09-04 20:28 ` [PATCH v5 18/18] fs: enable pre-content events on supported file systems Josef Bacik
2024-09-05  8:27   ` Amir Goldstein
2024-09-05 10:36     ` Jan Kara
2024-09-05 12:08 ` [PATCH v5 00/18] fanotify: add pre-content hooks Jan Kara
2024-09-05 19:29   ` Josef Bacik
     [not found] ` <CAOQ4uxikusW_q=zdqDKCHz8kGoTyUg1htWhPR1OFAFGHdj-vcQ@mail.gmail.com>
2024-09-05 10:32   ` Jan Kara
2024-09-05 19:30   ` Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOQ4uxjwU5g9hRXTyOY_2-KHSGR8eXv4unGrty4Gtj7JMkJffw@mail.gmail.com \
    --to=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox