From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Jan Kara <jack@suse.cz>
Cc: linux-xfs@vger.kernel.org, linux-mm@kvack.org,
Amir Goldstein <amir73il@gmail.com>,
Boaz Harrosh <boaz@plexistor.com>,
linux-fsdevel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/3] mm: Handle MADV_WILLNEED through vfs_fadvise()
Date: Thu, 29 Aug 2019 08:49:37 -0700 [thread overview]
Message-ID: <20190829154937.GC5354@magnolia> (raw)
In-Reply-To: <20190829131034.10563-2-jack@suse.cz>
On Thu, Aug 29, 2019 at 03:10:32PM +0200, Jan Kara wrote:
> Currently handling of MADV_WILLNEED hint calls directly into readahead
> code. Handle it by calling vfs_fadvise() instead so that filesystem can
> use its ->fadvise() callback to acquire necessary locks or otherwise
> prepare for the request.
>
> Suggested-by: Amir Goldstein <amir73il@gmail.com>
> Reviewed-by: Boaz Harrosh <boazh@netapp.com>
> CC: stable@vger.kernel.org
> Signed-off-by: Jan Kara <jack@suse.cz>
Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
> mm/madvise.c | 22 ++++++++++++++++------
> 1 file changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 968df3aa069f..bac973b9f2cc 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -14,6 +14,7 @@
> #include <linux/userfaultfd_k.h>
> #include <linux/hugetlb.h>
> #include <linux/falloc.h>
> +#include <linux/fadvise.h>
> #include <linux/sched.h>
> #include <linux/ksm.h>
> #include <linux/fs.h>
> @@ -275,6 +276,7 @@ static long madvise_willneed(struct vm_area_struct *vma,
> unsigned long start, unsigned long end)
> {
> struct file *file = vma->vm_file;
> + loff_t offset;
>
> *prev = vma;
> #ifdef CONFIG_SWAP
> @@ -298,12 +300,20 @@ static long madvise_willneed(struct vm_area_struct *vma,
> return 0;
> }
>
> - start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
> - if (end > vma->vm_end)
> - 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);
> + /*
> + * Filesystem's fadvise may need to take various locks. We need to
> + * explicitly grab a reference because the vma (and hence the
> + * vma's reference to the file) can go away as soon as we drop
> + * mmap_sem.
> + */
> + *prev = NULL; /* tell sys_madvise we drop mmap_sem */
> + get_file(file);
> + up_read(¤t->mm->mmap_sem);
> + offset = (loff_t)(start - vma->vm_start)
> + + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
> + vfs_fadvise(file, offset, end - start, POSIX_FADV_WILLNEED);
> + fput(file);
> + down_read(¤t->mm->mmap_sem);
> return 0;
> }
>
> --
> 2.16.4
>
next prev parent reply other threads:[~2019-08-29 15:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 13:10 [PATCH 0/3 v2] xfs: Fix races between readahead and hole punching Jan Kara
2019-08-29 13:10 ` [PATCH 1/3] mm: Handle MADV_WILLNEED through vfs_fadvise() Jan Kara
2019-08-29 15:49 ` Darrick J. Wong [this message]
2019-08-29 13:10 ` [PATCH 2/3] fs: Export generic_fadvise() Jan Kara
2019-08-29 13:10 ` [PATCH 3/3] xfs: Fix stale data exposure when readahead races with hole punch Jan Kara
2019-08-29 15:52 ` Darrick J. Wong
2019-08-30 15:24 ` Jan Kara
2019-08-30 16:02 ` Darrick J. Wong
2019-09-18 12:31 ` Jan Kara
2019-09-18 16:07 ` Darrick J. Wong
2019-09-23 12:33 ` Boaz Harrosh
2019-09-24 15:23 ` Jan Kara
2019-09-24 15:45 ` Boaz Harrosh
2020-01-17 10:50 ` [PATCH 0/3 v2] xfs: Fix races between readahead and hole punching Amir Goldstein
2020-01-19 8:35 ` Amir Goldstein
2020-01-20 11:47 ` Jan Kara
2020-01-20 12:03 ` Jan Kara
2020-01-20 13:54 ` Amir Goldstein
2020-01-20 16:58 ` Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2019-07-11 14:00 [PATCH 0/3] " Jan Kara
2019-07-11 14:00 ` [PATCH 1/3] mm: Handle MADV_WILLNEED through vfs_fadvise() Jan Kara
2019-07-12 17:50 ` Darrick J. Wong
2019-07-23 3:08 ` Boaz Harrosh
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=20190829154937.GC5354@magnolia \
--to=darrick.wong@oracle.com \
--cc=amir73il@gmail.com \
--cc=boaz@plexistor.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=stable@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;
as well as URLs for NNTP newsgroup(s).