mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
linux/super: add tunable to request immediate reclaim of unused dentries
Traditionally, unused dentries would be cached in the dentry cache until the associated entry is no longer on disk. The cached dentry continues to hold an inode reference, causing the inode to be pinned (see previous commit). Here we implement the dentry op d_delete, which is roughly analogous to the drop_inode superblock op, and add a zfs_delete_dentry tunable to control its behaviour. By default it continues the traditional behaviour, but when the tunable is enabled, we signal that an unused dentry should be freed immediately, releasing its inode reference, and so allowing that inode to be deleted if no longer in use. Sponsored-by: Klara, Inc. Sponsored-by: Fastmail Pty Ltd Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com> Signed-off-by: Rob Norris <rob.norris@klarasystems.com> Closes #17746
This commit is contained in:
@@ -1521,6 +1521,12 @@ zfs_domount(struct super_block *sb, zfs_mnt_t *zm, int silent)
|
||||
sb->s_xattr = zpl_xattr_handlers;
|
||||
sb->s_export_op = &zpl_export_operations;
|
||||
|
||||
#ifdef HAVE_SET_DEFAULT_D_OP
|
||||
set_default_d_op(sb, &zpl_dentry_operations);
|
||||
#else
|
||||
sb->s_d_op = &zpl_dentry_operations;
|
||||
#endif
|
||||
|
||||
/* Set features for file system. */
|
||||
zfs_set_fuid_feature(zfsvfs);
|
||||
|
||||
|
||||
@@ -41,6 +41,14 @@
|
||||
*/
|
||||
int zfs_delete_inode = 0;
|
||||
|
||||
/*
|
||||
* What to do when the last reference to a dentry is released. If 0, the kernel
|
||||
* will cache it until the entry (file) is destroyed. If 1, the dentry will be
|
||||
* marked for cleanup, at which time its inode reference will be released. See
|
||||
* zpl_dentry_delete().
|
||||
*/
|
||||
int zfs_delete_dentry = 0;
|
||||
|
||||
static struct inode *
|
||||
zpl_inode_alloc(struct super_block *sb)
|
||||
{
|
||||
@@ -513,6 +521,35 @@ const struct super_operations zpl_super_operations = {
|
||||
.show_stats = NULL,
|
||||
};
|
||||
|
||||
/*
|
||||
* ->d_delete() is called when the last reference to a dentry is released. Its
|
||||
* return value indicates if the dentry should be destroyed immediately, or
|
||||
* retained in the dentry cache.
|
||||
*
|
||||
* By default (zfs_delete_dentry=0) the kernel will always cache unused
|
||||
* entries. Each dentry holds an inode reference, so cached dentries can hold
|
||||
* the final inode reference indefinitely, leading to the inode and its related
|
||||
* data being pinned (see zpl_drop_inode()).
|
||||
*
|
||||
* When set to 1, we signal that the dentry should be destroyed immediately and
|
||||
* never cached. This reduces memory usage, at the cost of higher overheads to
|
||||
* lookup a file, as the inode and its underlying data (dnode/dbuf) need to be
|
||||
* reloaded and reinflated.
|
||||
*
|
||||
* Note that userspace does not have direct control over dentry references and
|
||||
* reclaim; rather, this is part of the kernel's caching and reclaim subsystems
|
||||
* (eg vm.vfs_cache_pressure).
|
||||
*/
|
||||
static int
|
||||
zpl_dentry_delete(const struct dentry *dentry)
|
||||
{
|
||||
return (zfs_delete_dentry ? 1 : 0);
|
||||
}
|
||||
|
||||
const struct dentry_operations zpl_dentry_operations = {
|
||||
.d_delete = zpl_dentry_delete,
|
||||
};
|
||||
|
||||
struct file_system_type zpl_fs_type = {
|
||||
.owner = THIS_MODULE,
|
||||
.name = ZFS_DRIVER,
|
||||
@@ -527,3 +564,7 @@ struct file_system_type zpl_fs_type = {
|
||||
|
||||
ZFS_MODULE_PARAM(zfs, zfs_, delete_inode, INT, ZMOD_RW,
|
||||
"Delete inodes as soon as the last reference is released.");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs, zfs_, delete_dentry, INT, ZMOD_RW,
|
||||
"Delete dentries from dentry cache as soon as the last reference is "
|
||||
"released.");
|
||||
|
||||
Reference in New Issue
Block a user