public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Luis Henriques <luis@igalia.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Bernd Schubert <bernd@bsbernd.com>,
	Laura Promberger <laura.promberger@cern.ch>,
	Dave Chinner <david@fromorbit.com>,
	Matt Harvey <mharvey@jumptrading.com>,
	linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com,
	linux-kernel@vger.kernel.org, Luis Henriques <luis@igalia.com>
Subject: [RFC PATCH v6 3/4] fuse: new work queue to invalidate dentries from old epochs
Date: Tue, 16 Sep 2025 14:53:09 +0100	[thread overview]
Message-ID: <20250916135310.51177-4-luis@igalia.com> (raw)
In-Reply-To: <20250916135310.51177-1-luis@igalia.com>

With the infrastructure introduced to periodically invalidate expired
dentries, it is now possible to add an extra work queue to invalidate
dentries when an epoch is incremented.  This work queue will only be
triggered when the 'inval_wq' parameter is set.

Signed-off-by: Luis Henriques <luis@igalia.com>
---
 fs/fuse/dev.c    |  7 ++++---
 fs/fuse/dir.c    | 21 +++++++++++++++++++++
 fs/fuse/fuse_i.h |  4 ++++
 fs/fuse/inode.c  |  2 ++
 4 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 5150aa25e64b..c24e78f86b50 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2033,13 +2033,14 @@ static int fuse_notify_resend(struct fuse_conn *fc)
 
 /*
  * Increments the fuse connection epoch.  This will result of dentries from
- * previous epochs to be invalidated.
- *
- * XXX optimization: add call to shrink_dcache_sb()?
+ * previous epochs to be invalidated.  Additionally, if inval_wq is set, a work
+ * queue is scheduled to trigger the invalidation.
  */
 static int fuse_notify_inc_epoch(struct fuse_conn *fc)
 {
 	atomic_inc(&fc->epoch);
+	if (inval_wq)
+		schedule_work(&fc->epoch_work);
 
 	return 0;
 }
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 3e88da803ba6..67e3340a443c 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -189,6 +189,27 @@ static void fuse_dentry_tree_work(struct work_struct *work)
 				      secs_to_jiffies(inval_wq));
 }
 
+void fuse_epoch_work(struct work_struct *work)
+{
+	struct fuse_conn *fc = container_of(work, struct fuse_conn,
+					    epoch_work);
+	struct fuse_mount *fm;
+	struct inode *inode;
+
+	down_read(&fc->killsb);
+
+	inode = fuse_ilookup(fc, FUSE_ROOT_ID, &fm);
+	iput(inode);
+
+	if (fm) {
+		/* Remove all possible active references to cached inodes */
+		shrink_dcache_sb(fm->sb);
+	} else
+		pr_warn("Failed to get root inode");
+
+	up_read(&fc->killsb);
+}
+
 void fuse_dentry_tree_init(void)
 {
 	int i;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index b34be6f95bbe..53ca87814ef3 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -649,6 +649,8 @@ struct fuse_conn {
 	/** Current epoch for up-to-date dentries */
 	atomic_t epoch;
 
+	struct work_struct epoch_work;
+
 	struct rcu_head rcu;
 
 	/** The user id for this mount */
@@ -1276,6 +1278,8 @@ void fuse_check_timeout(struct work_struct *work);
 void fuse_dentry_tree_init(void);
 void fuse_dentry_tree_cleanup(void);
 
+void fuse_epoch_work(struct work_struct *work);
+
 /**
  * Invalidate inode attributes
  */
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index db275a04021d..c054f02e661d 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -967,6 +967,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
 	refcount_set(&fc->count, 1);
 	atomic_set(&fc->dev_count, 1);
 	atomic_set(&fc->epoch, 1);
+	INIT_WORK(&fc->epoch_work, fuse_epoch_work);
 	init_waitqueue_head(&fc->blocked_waitq);
 	fuse_iqueue_init(&fc->iq, fiq_ops, fiq_priv);
 	INIT_LIST_HEAD(&fc->bg_queue);
@@ -1019,6 +1020,7 @@ void fuse_conn_put(struct fuse_conn *fc)
 			fuse_dax_conn_free(fc);
 		if (fc->timeout.req_timeout)
 			cancel_delayed_work_sync(&fc->timeout.work);
+		cancel_work_sync(&fc->epoch_work);
 		if (fiq->ops->release)
 			fiq->ops->release(fiq);
 		put_pid_ns(fc->pid_ns);

  parent reply	other threads:[~2025-09-16 13:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-16 13:53 [RFC PATCH v6 0/4] fuse: work queues to invalided dentries Luis Henriques
2025-09-16 13:53 ` [RFC PATCH v6 1/4] dcache: export shrink_dentry_list() and add new helper d_dispose_if_unused() Luis Henriques
2025-09-16 13:53 ` [RFC PATCH v6 2/4] fuse: new work queue to periodically invalidate expired dentries Luis Henriques
2025-09-16 13:53 ` Luis Henriques [this message]
2025-09-16 13:53 ` [RFC PATCH v6 4/4] fuse: refactor fuse_conn_put() to remove negative logic Luis Henriques
2025-10-20 13:17 ` [RFC PATCH v6 0/4] fuse: work queues to invalided dentries Luis Henriques
2025-11-13  9:02 ` Miklos Szeredi
2025-11-13  9:43   ` Luis Henriques

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=20250916135310.51177-4-luis@igalia.com \
    --to=luis@igalia.com \
    --cc=bernd@bsbernd.com \
    --cc=david@fromorbit.com \
    --cc=kernel-dev@igalia.com \
    --cc=laura.promberger@cern.ch \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mharvey@jumptrading.com \
    --cc=miklos@szeredi.hu \
    /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