From: cgel.zte@gmail.com
To: viro@zeniv.linux.org.uk, hughd@google.com,
akpm@linux-foundation.org, hch@infradead.org,
hsiangkao@linux.alibaba.com
Cc: yang.yang29@zte.com.cn, axboe@kernel.dk, yangerkun@huawei.com,
johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Ran Xiaokai <ran.xiaokai@zte.com.cn>,
CGEL ZTE <cgel.zte@gmail.com>
Subject: [PATCH] fs: drop_caches: skip dropping pagecache which is always dirty
Date: Wed, 20 Jul 2022 02:21:19 +0000 [thread overview]
Message-ID: <20220720022118.1495752-1-yang.yang29@zte.com.cn> (raw)
From: Yang Yang <yang.yang29@zte.com.cn>
Pagecache of some kind of fs has PG_dirty bit set once it was
allocated, so it can't be dropped. These fs include ramfs and
tmpfs. This can make drop_pagecache_sb() more efficient.
Introduce a new fs flag to do this, and this new flag may be
used in other case in future.
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Signed-off-by: CGEL ZTE <cgel.zte@gmail.com>
---
fs/drop_caches.c | 7 +++++++
fs/ramfs/inode.c | 2 +-
include/linux/fs.h | 1 +
mm/shmem.c | 2 +-
4 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index e619c31b6bd9..16956d5d3922 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -19,6 +19,13 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
{
struct inode *inode, *toput_inode = NULL;
+ /*
+ * Pagecache of this kind of fs has PG_dirty bit set once it was
+ * allocated, so it can't be dropped.
+ */
+ if (sb->s_type->fs_flags & FS_ALWAYS_DIRTY)
+ return;
+
spin_lock(&sb->s_inode_list_lock);
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
spin_lock(&inode->i_lock);
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index bc66d0173e33..5fb62d37618f 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -289,7 +289,7 @@ static struct file_system_type ramfs_fs_type = {
.init_fs_context = ramfs_init_fs_context,
.parameters = ramfs_fs_parameters,
.kill_sb = ramfs_kill_sb,
- .fs_flags = FS_USERNS_MOUNT,
+ .fs_flags = FS_USERNS_MOUNT | FS_ALWAYS_DIRTY,
};
static int __init init_ramfs_fs(void)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e285bd9d6188..90cdd10d683e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2532,6 +2532,7 @@ struct file_system_type {
#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
#define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */
#define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */
+#define FS_ALWAYS_DIRTY 64 /* Pagecache is always dirty. */
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
int (*init_fs_context)(struct fs_context *);
const struct fs_parameter_spec *parameters;
diff --git a/mm/shmem.c b/mm/shmem.c
index 8baf26eda989..5d549f61735f 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3974,7 +3974,7 @@ static struct file_system_type shmem_fs_type = {
.parameters = shmem_fs_parameters,
#endif
.kill_sb = kill_litter_super,
- .fs_flags = FS_USERNS_MOUNT,
+ .fs_flags = FS_USERNS_MOUNT | FS_ALWAYS_DIRTY,
};
void __init shmem_init(void)
--
2.25.1
next reply other threads:[~2022-07-20 2:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 2:21 cgel.zte [this message]
2022-07-20 3:02 ` Matthew Wilcox
2022-07-20 6:02 ` CGEL
2022-07-20 6:04 ` Christoph Hellwig
2022-07-20 7:01 ` CGEL
2022-07-20 15:02 ` Matthew Wilcox
2022-07-21 1:00 ` CGEL
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=20220720022118.1495752-1-yang.yang29@zte.com.cn \
--to=cgel.zte@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=hsiangkao@linux.alibaba.com \
--cc=hughd@google.com \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ran.xiaokai@zte.com.cn \
--cc=viro@zeniv.linux.org.uk \
--cc=yang.yang29@zte.com.cn \
--cc=yangerkun@huawei.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