From: "Darrick J. Wong" <djwong@kernel.org>
To: Shiyang Ruan <ruansy.fnst@fujitsu.com>
Cc: linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org,
nvdimm@lists.linux.dev, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, dan.j.williams@intel.com,
david@fromorbit.com, hch@infradead.org, jane.chu@oracle.com
Subject: Re: [PATCH 2/3] fs: move drop_pagecache_sb() for others to use
Date: Wed, 14 Sep 2022 11:16:45 -0700 [thread overview]
Message-ID: <YyIajcWz/h1k3kvq@magnolia> (raw)
In-Reply-To: <1662114961-66-3-git-send-email-ruansy.fnst@fujitsu.com>
On Fri, Sep 02, 2022 at 10:36:00AM +0000, Shiyang Ruan wrote:
> xfs_notify_failure requires a method to invalidate all mappings.
> drop_pagecache_sb() can do this but it is a static function and only
> build with CONFIG_SYSCTL. Now, move it to super.c and make it available
> for others.
>
> Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com>
> ---
> fs/drop_caches.c | 33 ---------------------------------
> fs/super.c | 34 ++++++++++++++++++++++++++++++++++
> include/linux/fs.h | 1 +
> 3 files changed, 35 insertions(+), 33 deletions(-)
>
> diff --git a/fs/drop_caches.c b/fs/drop_caches.c
> index e619c31b6bd9..5c8406076f9b 100644
> --- a/fs/drop_caches.c
> +++ b/fs/drop_caches.c
> @@ -3,7 +3,6 @@
> * Implement the manual drop-all-pagecache function
> */
>
> -#include <linux/pagemap.h>
> #include <linux/kernel.h>
> #include <linux/mm.h>
> #include <linux/fs.h>
> @@ -15,38 +14,6 @@
> /* A global variable is a bit ugly, but it keeps the code simple */
> int sysctl_drop_caches;
>
> -static void drop_pagecache_sb(struct super_block *sb, void *unused)
> -{
> - struct inode *inode, *toput_inode = NULL;
> -
> - spin_lock(&sb->s_inode_list_lock);
> - list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
> - spin_lock(&inode->i_lock);
> - /*
> - * We must skip inodes in unusual state. We may also skip
> - * inodes without pages but we deliberately won't in case
> - * we need to reschedule to avoid softlockups.
> - */
> - if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) ||
> - (mapping_empty(inode->i_mapping) && !need_resched())) {
> - spin_unlock(&inode->i_lock);
> - continue;
> - }
> - __iget(inode);
> - spin_unlock(&inode->i_lock);
> - spin_unlock(&sb->s_inode_list_lock);
> -
> - invalidate_mapping_pages(inode->i_mapping, 0, -1);
> - iput(toput_inode);
> - toput_inode = inode;
> -
> - cond_resched();
> - spin_lock(&sb->s_inode_list_lock);
> - }
> - spin_unlock(&sb->s_inode_list_lock);
> - iput(toput_inode);
> -}
> -
> int drop_caches_sysctl_handler(struct ctl_table *table, int write,
> void *buffer, size_t *length, loff_t *ppos)
> {
> diff --git a/fs/super.c b/fs/super.c
> index 734ed584a946..bdf53dbe834c 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -36,6 +36,7 @@
> #include <linux/lockdep.h>
> #include <linux/user_namespace.h>
> #include <linux/fs_context.h>
> +#include <linux/pagemap.h>
> #include <uapi/linux/mount.h>
> #include "internal.h"
>
> @@ -677,6 +678,39 @@ void drop_super_exclusive(struct super_block *sb)
> }
> EXPORT_SYMBOL(drop_super_exclusive);
>
> +void drop_pagecache_sb(struct super_block *sb, void *unused)
> +{
> + struct inode *inode, *toput_inode = NULL;
> +
> + spin_lock(&sb->s_inode_list_lock);
> + list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
> + spin_lock(&inode->i_lock);
> + /*
> + * We must skip inodes in unusual state. We may also skip
> + * inodes without pages but we deliberately won't in case
> + * we need to reschedule to avoid softlockups.
> + */
> + if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) ||
> + (mapping_empty(inode->i_mapping) && !need_resched())) {
> + spin_unlock(&inode->i_lock);
> + continue;
> + }
> + __iget(inode);
> + spin_unlock(&inode->i_lock);
> + spin_unlock(&sb->s_inode_list_lock);
> +
> + invalidate_mapping_pages(inode->i_mapping, 0, -1);
> + iput(toput_inode);
> + toput_inode = inode;
> +
> + cond_resched();
> + spin_lock(&sb->s_inode_list_lock);
> + }
> + spin_unlock(&sb->s_inode_list_lock);
> + iput(toput_inode);
> +}
> +EXPORT_SYMBOL(drop_pagecache_sb);
You might want to rename this "super_drop_pagecache" to fit with the
other functions that all have "super" in the name somewhere.
--D
> +
> static void __iterate_supers(void (*f)(struct super_block *))
> {
> struct super_block *sb, *p = NULL;
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 9eced4cc286e..5ded28c0d2c9 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3292,6 +3292,7 @@ extern struct super_block *get_super(struct block_device *);
> extern struct super_block *get_active_super(struct block_device *bdev);
> extern void drop_super(struct super_block *sb);
> extern void drop_super_exclusive(struct super_block *sb);
> +void drop_pagecache_sb(struct super_block *sb, void *unused);
> extern void iterate_supers(void (*)(struct super_block *, void *), void *);
> extern void iterate_supers_type(struct file_system_type *,
> void (*)(struct super_block *, void *), void *);
> --
> 2.37.2
>
next prev parent reply other threads:[~2022-09-14 18:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 13:03 [PATCH v7] mm, pmem, xfs: Introduce MF_MEM_REMOVE for unbind Shiyang Ruan
2022-08-26 21:35 ` Dan Williams
2022-08-29 10:02 ` Shiyang Ruan
2022-08-29 14:49 ` Darrick J. Wong
2022-09-02 10:35 ` [PATCH v8 0/3] " Shiyang Ruan
2022-09-02 10:35 ` [PATCH 1/3] xfs: fix the calculation of length and end Shiyang Ruan
2022-09-14 18:13 ` Darrick J. Wong
2022-09-02 10:36 ` [PATCH 2/3] fs: move drop_pagecache_sb() for others to use Shiyang Ruan
2022-09-14 18:16 ` Darrick J. Wong [this message]
2022-09-02 10:36 ` [PATCH 3/3] mm, pmem, xfs: Introduce MF_MEM_REMOVE for unbind Shiyang Ruan
2022-09-14 18:15 ` Darrick J. Wong
2022-09-15 1:49 ` Shiyang Ruan
2022-09-20 2:45 ` Dave Chinner
2022-09-21 0:58 ` Darrick J. Wong
2022-09-07 9:46 ` [PATCH v8 0/3] " Shiyang Ruan
2022-09-14 18:09 ` Darrick J. Wong
2022-09-14 18:15 ` Darrick J. Wong
2022-09-15 2:56 ` Shiyang Ruan
2022-09-16 15:43 ` Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2022-09-25 13:33 [PATCH v9 " Shiyang Ruan
2022-09-25 13:33 ` [PATCH 2/3] fs: move drop_pagecache_sb() for others to use Shiyang Ruan
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=YyIajcWz/h1k3kvq@magnolia \
--to=djwong@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=david@fromorbit.com \
--cc=hch@infradead.org \
--cc=jane.chu@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=ruansy.fnst@fujitsu.com \
/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).