vfs: Add a sysctl for automated deletion of dentry
Subsystems (2)
PATCH v2 1/1 vfs: Add a sysctl for automated deletion of dentry
Commit 681ce8623567 ("vfs: Delete the associated dentry when deleting a file") introduced an unconditional deletion of the associated dentry when a file is removed. However, this led to performance regressions in specific benchmarks, such as ilebench.sum_operations/s [0], prompting a revert in commit 4a4be1ad3a6e ("Revert "vfs: Delete the associated dentry when deleting a file"").
This patch seeks to reintroduce the concept conditionally, where the associated dentry is deleted only when the user explicitly opts for it during file removal. A new sysctl fs.automated_deletion_of_dentry is added for this purpose. Its default value is set to 0.
There are practical use cases for this proactive dentry reclamation. Besides the Elasticsearch use case mentioned in commit 681ce8623567, additional examples have surfaced in our production environment. For instance, in video rendering services that continuously generate temporary files, upload them to persistent storage servers, and then delete them, a large number of negative dentries—serving no useful purpose—accumulate. Users in such cases would benefit from proactively reclaiming these negative dentries.
--- Documentation/admin-guide/sysctl/fs.rst | 5 +++++ fs/dcache.c | 12 ++++++++++++ 2 files changed, 17 insertions(+)
---
v2: Add doc for this new sysctl
Documentation/admin-guide/sysctl/fs.rst +5 -0
@@ -38,6 +38,11 @@ requests. ``aio-max-nr`` allows you to change the maximum value ``aio-max-nr`` does not result in the pre-allocation or re-sizing of any kernel data structures. +automated_deletion_of_dentry +---------------------------- + +Deletes the associated dentry when a file is removed. Set to 1 to enable +this behavior, and 0 to disable it. By default, this behavior is disabled. dentry-state ------------
fs/dcache.c +12 -0
@@ -135,6 +135,7 @@ struct dentry_stat_t { static DEFINE_PER_CPU(long, nr_dentry); static DEFINE_PER_CPU(long, nr_dentry_unused); static DEFINE_PER_CPU(long, nr_dentry_negative); +static int automated_deletion_of_dentry;#if defined(CONFIG_SYSCTL ) && defined(CONFIG_PROC_FS )/* Statistics gathering. */
@@ -199,6 +200,15 @@ static struct ctl_table fs_dcache_sysctls[] = { .mode = 0444, .proc_handler = proc_nr_dentry, }, + { + .procname = "automated_deletion_of_dentry", + .data = &automated_deletion_of_dentry, + .maxlen = sizeof(automated_deletion_of_dentry), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, };static int __init init_fs_dcache_sysctls (void )
@@ -2401,6 +2411,8 @@ void d_delete(struct dentry * dentry)* Are we the only user? */ if (dentry->d_lockref.count ==1 ) { +if (automated_deletion_of_dentry) +__d_drop (dentry); dentry->d_flags &= ~DCACHE_CANT_MOUNT ;dentry_unlink_inode (dentry); }else {
Signature · 1 line
2.43.5
Quoted 5 lines · Yafang Shao
This patch seeks to reintroduce the concept conditionally, where the associated dentry is deleted only when the user explicitly opts for it during file removal. A new sysctl fs.automated_deletion_of_dentry is added for this purpose. Its default value is set to 0.
I look at this patch, and part of me goes "I think we should make it a mount option", but at the same time I'm not sure it's worth the extra complexity, since this is such a special case.
So Ack. While I'm not convinced a sysctl is the way to go, I also don't think it's worth bikeshedding any further, at least until we have other cases that care.
Christian, I assume this will come through you? Or should I just pick it up directly?
Linus
Christian Brauner
maintainerQuoted 11 lines · Linus Torvalds
Quoted 5 lines · Yafang Shao
This patch seeks to reintroduce the concept conditionally, where the associated dentry is deleted only when the user explicitly opts for it during file removal. A new sysctl fs.automated_deletion_of_dentry is added for this purpose. Its default value is set to 0.
I look at this patch, and part of me goes "I think we should make it a mount option", but at the same time I'm not sure it's worth the extra complexity, since this is such a special case.
Quoted 6 lines
So Ack. While I'm not convinced a sysctl is the way to go, I also don't think it's worth bikeshedding any further, at least until we have other cases that care.
Christian, I assume this will come through you? Or should I just pick it up directly?
Yes. I'm just digging myself out from the mail avalance since coming back from Vienna. I'll get to it today.