All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz
Cc: linux-fsdevel@vger.kernel.org, Yafang Shao <laoar.shao@gmail.com>,
	Wangkai <wangkai86@huawei.com>,
	Colin Walters <walters@verbum.org>,
	Waiman Long <longman@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [RFC PATCH] fs: dcache: Delete the associated dentry when deleting a file
Date: Sat, 11 May 2024 10:27:29 +0800	[thread overview]
Message-ID: <20240511022729.35144-1-laoar.shao@gmail.com> (raw)

Our applications, built on Elasticsearch[0], frequently create and delete
files. These applications operate within containers, some with a memory
limit exceeding 100GB. Over prolonged periods, the accumulation of negative
dentries within these containers can amount to tens of gigabytes.

Upon container exit, directories are deleted. However, due to the numerous
associated dentries, this process can be time-consuming. Our users have
expressed frustration with this prolonged exit duration, which constitutes
our first issue.

Simultaneously, other processes may attempt to access the parent directory
of the Elasticsearch directories. Since the task responsible for deleting
the dentries holds the inode lock, processes attempting directory lookup
experience significant delays. This issue, our second problem, is easily
demonstrated:

  - Task 1 generates negative dentries: 
  $ pwd
  ~/test
  $ mkdir es && cd es/ && ./create_and_delete_files.sh

  [ After generating tens of GB dentries ]  

  $ cd ~/test && rm -rf es

  [ It will take a long duration to finish ]

  - Task 2 attempts to lookup the 'test/' directory
  $ pwd
  ~/test
  $ ls

  The 'ls' command in Task 2 experiences prolonged execution as Task 1
  is deleting the dentries.

We've devised a solution to address both issues by deleting associated
dentry when removing a file. Interestingly, we've noted that a similar
patch was proposed years ago[1], although it was rejected citing the
absence of tangible issues caused by negative dentries. Given our current
challenges, we're resubmitting the proposal. All relevant stakeholders from
previous discussions have been included for reference.

[0]. https://github.com/elastic/elasticsearch
[1]. https://patchwork.kernel.org/project/linux-fsdevel/patch/1502099673-31620-1-git-send-email-wangkai86@huawei.com

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: Wangkai <wangkai86@huawei.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Colin Walters <walters@verbum.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
---
 fs/dcache.c            | 4 ++++
 include/linux/dcache.h | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 71a8e943a0fa..4b97f60f0e64 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -701,6 +701,9 @@ static inline bool retain_dentry(struct dentry *dentry, bool locked)
 	if (unlikely(d_flags & DCACHE_DONTCACHE))
 		return false;
 
+	if (unlikely(dentry->d_flags & DCACHE_FILE_DELETED))
+		return false;
+
 	// At this point it looks like we ought to keep it.  We also might
 	// need to do something - put it on LRU if it wasn't there already
 	// and mark it referenced if it was on LRU, but not marked yet.
@@ -2392,6 +2395,7 @@ void d_delete(struct dentry * dentry)
 		spin_unlock(&dentry->d_lock);
 		spin_unlock(&inode->i_lock);
 	}
+	dentry->d_flags |= DCACHE_FILE_DELETED;
 }
 EXPORT_SYMBOL(d_delete);
 
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index bf53e3894aae..55a69682918c 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -210,7 +210,7 @@ struct dentry_operations {
 
 #define DCACHE_NOKEY_NAME		BIT(25) /* Encrypted name encoded without key */
 #define DCACHE_OP_REAL			BIT(26)
-
+#define DCACHE_FILE_DELETED		BIT(27) /* File is deleted */
 #define DCACHE_PAR_LOOKUP		BIT(28) /* being looked up (with parent locked shared) */
 #define DCACHE_DENTRY_CURSOR		BIT(29)
 #define DCACHE_NORCU			BIT(30) /* No RCU delay for freeing */
-- 
2.39.1


             reply	other threads:[~2024-05-11  2:28 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-11  2:27 Yafang Shao [this message]
2024-05-11  2:53 ` [RFC PATCH] fs: dcache: Delete the associated dentry when deleting a file Linus Torvalds
2024-05-11  3:35   ` Yafang Shao
2024-05-11  4:54     ` Waiman Long
2024-05-11 15:58       ` Matthew Wilcox
2024-05-11 16:07         ` Linus Torvalds
2024-05-11 16:13           ` Linus Torvalds
2024-05-11 18:05             ` Linus Torvalds
2024-05-11 18:26               ` [PATCH] vfs: move dentry shrinking outside the inode lock in 'rmdir()' Linus Torvalds
2024-05-11 18:42                 ` Linus Torvalds
2024-05-11 19:28                   ` Al Viro
2024-05-11 19:55                     ` Linus Torvalds
2024-05-11 20:31                       ` Al Viro
2024-05-11 21:17                         ` Al Viro
2024-05-12 15:45                     ` James Bottomley
2024-05-12 16:16                       ` Al Viro
2024-05-12 19:59                         ` Linus Torvalds
2024-05-12 20:29                           ` Linus Torvalds
2024-05-13  5:31                           ` Al Viro
2024-05-13 15:58                             ` Linus Torvalds
2024-05-13 16:33                               ` Al Viro
2024-05-13 16:44                                 ` Linus Torvalds
2024-05-23  7:18                                 ` Dave Chinner
2024-05-11 20:02                   ` [PATCH v2] " Linus Torvalds
2024-05-12  3:06                     ` Yafang Shao
2024-05-12  3:30                       ` Al Viro
2024-05-12  3:36                         ` Yafang Shao
2024-05-11 19:24                 ` [PATCH] " Al Viro
2024-05-15  2:18     ` [RFC PATCH] fs: dcache: Delete the associated dentry when deleting a file Yafang Shao
2024-05-15  2:36       ` Linus Torvalds
2024-05-15  9:17         ` [PATCH] vfs: " Yafang Shao
2024-05-15 16:05           ` Linus Torvalds
2024-05-16 13:44             ` Oliver Sang
2024-05-22  8:51             ` Oliver Sang
2024-05-23  2:21               ` Yafang Shao
2024-05-22  8:11           ` kernel test robot
2024-05-22 16:00             ` Linus Torvalds
2024-05-22 17:13               ` Matthew Wilcox
2024-05-22 18:11                 ` Linus Torvalds
2024-05-11  3:36   ` [RFC PATCH] fs: dcache: " Al Viro
2024-05-11  3:51     ` Yafang Shao
2024-05-11  5:18     ` Al Viro
2024-05-11  5:32     ` Linus Torvalds

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=20240511022729.35144-1-laoar.shao@gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=walters@verbum.org \
    --cc=wangkai86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.