From: Bernd Schubert <bschubert@ddn.com>
To: "Miklos Szeredi" <miklos@szeredi.hu>,
"Vivek Goyal" <vgoyal@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>
Cc: linux-fsdevel@vger.kernel.org,
Joanne Koong <joannelkoong@gmail.com>,
Josef Bacik <josef@toxicpanda.com>,
Bernd Schubert <bschubert@ddn.com>
Subject: [PATCH 1/4] fuse: Make the fuse_send_one request counter atomic
Date: Wed, 02 Apr 2025 19:40:51 +0200 [thread overview]
Message-ID: <20250402-fuse-io-uring-trace-points-v1-1-11b0211fa658@ddn.com> (raw)
In-Reply-To: <20250402-fuse-io-uring-trace-points-v1-0-11b0211fa658@ddn.com>
No need to take lock, we can have that in atomic way.
fuse-io-uring and virtiofs especially benefit from it
as they don't need the fiq lock at all.
Signed-off-by: Bernd Schubert <bschubert@ddn.com>
---
fs/fuse/dev.c | 24 +++---------------------
fs/fuse/fuse_dev_i.h | 4 ----
fs/fuse/fuse_i.h | 18 +++++++++++++-----
3 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 51e31df4c54613280a9c295f530b18e1d461a974..e9592ab092b948bacb5034018bd1f32c917d5c9f 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -204,24 +204,6 @@ unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args)
}
EXPORT_SYMBOL_GPL(fuse_len_args);
-static u64 fuse_get_unique_locked(struct fuse_iqueue *fiq)
-{
- fiq->reqctr += FUSE_REQ_ID_STEP;
- return fiq->reqctr;
-}
-
-u64 fuse_get_unique(struct fuse_iqueue *fiq)
-{
- u64 ret;
-
- spin_lock(&fiq->lock);
- ret = fuse_get_unique_locked(fiq);
- spin_unlock(&fiq->lock);
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(fuse_get_unique);
-
unsigned int fuse_req_hash(u64 unique)
{
return hash_long(unique & ~FUSE_INT_REQ_BIT, FUSE_PQ_HASH_BITS);
@@ -278,7 +260,7 @@ static void fuse_dev_queue_req(struct fuse_iqueue *fiq, struct fuse_req *req)
spin_lock(&fiq->lock);
if (fiq->connected) {
if (req->in.h.opcode != FUSE_NOTIFY_REPLY)
- req->in.h.unique = fuse_get_unique_locked(fiq);
+ req->in.h.unique = fuse_get_unique(fiq);
list_add_tail(&req->list, &fiq->pending);
fuse_dev_wake_and_unlock(fiq);
} else {
@@ -1177,7 +1159,7 @@ __releases(fiq->lock)
struct fuse_in_header ih = {
.opcode = FUSE_FORGET,
.nodeid = forget->forget_one.nodeid,
- .unique = fuse_get_unique_locked(fiq),
+ .unique = fuse_get_unique(fiq),
.len = sizeof(ih) + sizeof(arg),
};
@@ -1208,7 +1190,7 @@ __releases(fiq->lock)
struct fuse_batch_forget_in arg = { .count = 0 };
struct fuse_in_header ih = {
.opcode = FUSE_BATCH_FORGET,
- .unique = fuse_get_unique_locked(fiq),
+ .unique = fuse_get_unique(fiq),
.len = sizeof(ih) + sizeof(arg),
};
diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h
index 3b2bfe1248d3573abe3b144a6d4bf6a502f56a40..e0afd837a8024450bab77312c7eebdcc7a39bd36 100644
--- a/fs/fuse/fuse_dev_i.h
+++ b/fs/fuse/fuse_dev_i.h
@@ -8,10 +8,6 @@
#include <linux/types.h>
-/* Ordinary requests have even IDs, while interrupts IDs are odd */
-#define FUSE_INT_REQ_BIT (1ULL << 0)
-#define FUSE_REQ_ID_STEP (1ULL << 1)
-
struct fuse_arg;
struct fuse_args;
struct fuse_pqueue;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index fee96fe7887b30cd57b8a6bbda11447a228cf446..8aea23ffaf2fa44b284d4efef1e009fb1ca876a0 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -44,6 +44,10 @@
/** Number of dentries for each connection in the control filesystem */
#define FUSE_CTL_NUM_DENTRIES 5
+/* Ordinary requests have even IDs, while interrupts IDs are odd */
+#define FUSE_INT_REQ_BIT (1ULL << 0)
+#define FUSE_REQ_ID_STEP (1ULL << 1)
+
/** Maximum of max_pages received in init_out */
extern unsigned int fuse_max_pages_limit;
@@ -490,7 +494,7 @@ struct fuse_iqueue {
wait_queue_head_t waitq;
/** The next unique request id */
- u64 reqctr;
+ atomic64_t reqctr;
/** The list of pending requests */
struct list_head pending;
@@ -1065,6 +1069,14 @@ static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket)
rcu_read_unlock();
}
+/**
+ * Get the next unique ID for a request
+ */
+static inline u64 fuse_get_unique(struct fuse_iqueue *fiq)
+{
+ return atomic64_add_return(FUSE_REQ_ID_STEP, &fiq->reqctr);
+}
+
/** Device operations */
extern const struct file_operations fuse_dev_operations;
@@ -1415,10 +1427,6 @@ int fuse_readdir(struct file *file, struct dir_context *ctx);
*/
unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
-/**
- * Get the next unique ID for a request
- */
-u64 fuse_get_unique(struct fuse_iqueue *fiq);
void fuse_free_conn(struct fuse_conn *fc);
/* dax.c */
--
2.43.0
next prev parent reply other threads:[~2025-04-02 18:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 17:40 [PATCH 0/4] fuse: Improve ftraces, atomic req unique and code dup removal Bernd Schubert
2025-04-02 17:40 ` Bernd Schubert [this message]
2025-04-02 18:29 ` [PATCH 1/4] fuse: Make the fuse_send_one request counter atomic Miklos Szeredi
2025-04-03 9:16 ` Bernd Schubert
2025-04-03 12:15 ` Miklos Szeredi
2025-04-03 13:06 ` Bernd Schubert
2025-04-02 17:40 ` [PATCH RFC 2/4] fuse: Set request unique on allocation Bernd Schubert
2025-04-02 18:33 ` Miklos Szeredi
2025-04-03 13:08 ` Bernd Schubert
2025-04-02 17:40 ` [PATCH 3/4] fuse: {io-uring} Avoid _send code dup Bernd Schubert
2025-04-02 17:40 ` [PATCH 4/4] fuse: fine-grained request ftraces Bernd Schubert
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=20250402-fuse-io-uring-trace-points-v1-1-11b0211fa658@ddn.com \
--to=bschubert@ddn.com \
--cc=eperezma@redhat.com \
--cc=joannelkoong@gmail.com \
--cc=josef@toxicpanda.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=stefanha@redhat.com \
--cc=vgoyal@redhat.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).