From: Ye Bin <yebin@huaweicloud.com>
To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, yebin10@huawei.com,
zhangxiaoxu5@huawei.com
Subject: [PATCH 2/3] sysctl: add support for drop_caches for individual filesystem
Date: Thu, 10 Oct 2024 19:25:42 +0800 [thread overview]
Message-ID: <20241010112543.1609648-3-yebin@huaweicloud.com> (raw)
In-Reply-To: <20241010112543.1609648-1-yebin@huaweicloud.com>
From: Ye Bin <yebin10@huawei.com>
In order to better analyze the issue of file system uninstallation caused
by kernel module opening files, it is necessary to perform dentry recycling
on a single file system. But now, apart from global dentry recycling, it is
not supported to do dentry recycling on a single file system separately.
This feature has usage scenarios in problem localization scenarios.At the
same time, it also provides users with a slightly fine-grained
pagecache/entry recycling mechanism.
This patch supports the recycling of pagecache/entry for individual file
systems.
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
fs/drop_caches.c | 43 +++++++++++++++++++++++++++++++++++++++++++
include/linux/mm.h | 2 ++
kernel/sysctl.c | 9 +++++++++
3 files changed, 54 insertions(+)
diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index d45ef541d848..99d412cf3e52 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -77,3 +77,46 @@ int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
}
return 0;
}
+
+int drop_fs_caches_sysctl_handler(const struct ctl_table *table, int write,
+ void *buffer, size_t *length, loff_t *ppos)
+{
+ unsigned int major, minor;
+ unsigned int ctl;
+ struct super_block *sb;
+ static int stfu;
+
+ if (!write)
+ return 0;
+
+ if (sscanf(buffer, "%u:%u:%u", &major, &minor, &ctl) != 3)
+ return -EINVAL;
+
+ if (ctl < *((int *)table->extra1) || ctl > *((int *)table->extra2))
+ return -EINVAL;
+
+ sb = user_get_super(MKDEV(major, minor), false);
+ if (!sb)
+ return -EINVAL;
+
+ if (ctl & 1) {
+ lru_add_drain_all();
+ drop_pagecache_sb(sb, NULL);
+ count_vm_event(DROP_PAGECACHE);
+ }
+
+ if (ctl & 2) {
+ shrink_dcache_sb(sb);
+ shrink_icache_sb(sb);
+ count_vm_event(DROP_SLAB);
+ }
+
+ drop_super(sb);
+
+ if (!stfu)
+ pr_info("%s (%d): drop_fs_caches: %u:%u:%d\n", current->comm,
+ task_pid_nr(current), major, minor, ctl);
+ stfu |= ctl & 4;
+
+ return 0;
+}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 344541f8cba0..43079478296f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3788,6 +3788,8 @@ extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
extern int sysctl_drop_caches;
int drop_caches_sysctl_handler(const struct ctl_table *, int, void *, size_t *,
loff_t *);
+int drop_fs_caches_sysctl_handler(const struct ctl_table *table, int write,
+ void *buffer, size_t *length, loff_t *ppos);
#endif
void drop_slab(void);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 79e6cb1d5c48..d434cbe10e47 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2101,6 +2101,15 @@ static struct ctl_table vm_table[] = {
.extra1 = SYSCTL_ONE,
.extra2 = SYSCTL_FOUR,
},
+ {
+ .procname = "drop_fs_caches",
+ .data = NULL,
+ .maxlen = 256,
+ .mode = 0200,
+ .proc_handler = drop_fs_caches_sysctl_handler,
+ .extra1 = SYSCTL_ONE,
+ .extra2 = SYSCTL_FOUR,
+ },
{
.procname = "page_lock_unfairness",
.data = &sysctl_page_lock_unfairness,
--
2.31.1
next prev parent reply other threads:[~2024-10-10 11:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 11:25 [PATCH 0/3] add support for drop_caches for individual filesystem Ye Bin
2024-10-10 11:25 ` [PATCH 1/3] vfs: introduce shrink_icache_sb() helper Ye Bin
2024-10-10 12:07 ` Jan Kara
2024-10-10 11:25 ` Ye Bin [this message]
2024-10-10 12:16 ` [PATCH 2/3] sysctl: add support for drop_caches for individual filesystem Jan Kara
2024-10-10 12:44 ` yebin (H)
2024-10-10 13:35 ` Benjamin Coddington
2024-10-10 17:04 ` Jan Kara
2024-10-11 11:44 ` Amir Goldstein
2024-10-14 11:24 ` Jan Kara
2024-10-10 13:48 ` Thomas Weißschuh
2024-10-10 17:17 ` Al Viro
2024-10-10 11:25 ` [PATCH 3/3] Documentation: add instructions for using 'drop_fs_caches sysctl' sysctl Ye Bin
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=20241010112543.1609648-3-yebin@huaweicloud.com \
--to=yebin@huaweicloud.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yebin10@huawei.com \
--cc=zhangxiaoxu5@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;
as well as URLs for NNTP newsgroup(s).