Skip to contentSkip to conversation

fuse: add numa affinity for uring queues

PATCH In review Joanne Koong 2 participants 6 messages Mar 31, 2025 – Apr 1, 2025

Subsystems (3)
lore
Share & tools
lore

Joanne Koong

author maintainer
#0 lore raw

PATCH 1/1 fuse: add numa affinity for uring queues

There is a 1:1 mapping between cpus and queues. Allocate the queue on the numa node associated with the cpu to help reduce memory access latencies.

---
 fs/fuse/dev_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev_uring.c +1 -1
index accdce2977c5..0762d6229ac6 100644
@@ -256,7 +256,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring,
 	struct fuse_ring_queue *queue;
 	struct list_head *pq;
 
-	queue = kzalloc(sizeof(*queue), GFP_KERNEL_ACCOUNT);
+	queue = kzalloc_node(sizeof(*queue), GFP_KERNEL_ACCOUNT, cpu_to_node(qid));
 	if (!queue)
 		return NULL;
 	pq = kcalloc(FUSE_PQ_HASH_SIZE, sizeof(struct list_head), GFP_KERNEL);
Signature · 1 line
2.47.1
author maintainer
#1 lore raw
Quoted 15 lines · Joanne Koong

There is a 1:1 mapping between cpus and queues. Allocate the queue on the numa node associated with the cpu to help reduce memory access latencies.

---
 fs/fuse/dev_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev_uring.c +0 -0
index accdce2977c5..0762d6229ac6 100644

fs/fuse/dev_uring.c static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, · line 262

Quoted 8 lines
fs/fuse/dev_uring.c +1 -1
@@ -256,7 +256,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring,
        struct fuse_ring_queue *queue;
        struct list_head *pq;
 
-       queue = kzalloc(sizeof(*queue), GFP_KERNEL_ACCOUNT);
+       queue = kzalloc_node(sizeof(*queue), GFP_KERNEL_ACCOUNT, cpu_to_node(qid));
        if (!queue)
                return NULL;
        pq = kcalloc(FUSE_PQ_HASH_SIZE, sizeof(struct list_head), GFP_KERNEL);

On the same note I guess we should also allocate pq on the corresponding numa node too.

Quoted 3 lines

--
2.47.1

#2 lore raw
Quoted 19 lines · Joanne Koong
Quoted 18 lines · Joanne Koong

There is a 1:1 mapping between cpus and queues. Allocate the queue on the numa node associated with the cpu to help reduce memory access latencies.

---
 fs/fuse/dev_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev_uring.c +0 -0
index accdce2977c5..0762d6229ac6 100644
@@ -256,7 +256,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring,
        struct fuse_ring_queue *queue;
        struct list_head *pq;
 
Quoted 8 lines

fs/fuse/dev_uring.c static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, · line 262

Quoted 5 lines
fs/fuse/dev_uring.c +1 -1
-       queue = kzalloc(sizeof(*queue), GFP_KERNEL_ACCOUNT);
+       queue = kzalloc_node(sizeof(*queue), GFP_KERNEL_ACCOUNT, cpu_to_node(qid));
        if (!queue)
                return NULL;
        pq = kcalloc(FUSE_PQ_HASH_SIZE, sizeof(struct list_head), GFP_KERNEL);

On the same note I guess we should also allocate pq on the corresponding numa node too.

So this is supposed to be called from a thread that already runs on this numa node and then kmalloc will allocate anyway on the right node, afaik. Do you have a use case where this is called from another node? If you do, all allocations in this file should be changed.

Thanks,
Bernd

author maintainer
#3 lore raw
Quoted 30 lines · Bernd Schubert
Quoted 19 lines · Joanne Koong
Quoted 18 lines · Joanne Koong

There is a 1:1 mapping between cpus and queues. Allocate the queue on the numa node associated with the cpu to help reduce memory access latencies.

---
 fs/fuse/dev_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev_uring.c +0 -0
index accdce2977c5..0762d6229ac6 100644
@@ -256,7 +256,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring,
        struct fuse_ring_queue *queue;
        struct list_head *pq;
 
Quoted 8 lines

fs/fuse/dev_uring.c static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, · line 262

Quoted 5 lines
fs/fuse/dev_uring.c +1 -1
-       queue = kzalloc(sizeof(*queue), GFP_KERNEL_ACCOUNT);
+       queue = kzalloc_node(sizeof(*queue), GFP_KERNEL_ACCOUNT, cpu_to_node(qid));
        if (!queue)
                return NULL;
        pq = kcalloc(FUSE_PQ_HASH_SIZE, sizeof(struct list_head), GFP_KERNEL);

On the same note I guess we should also allocate pq on the corresponding numa node too.

Quoted 5 lines

So this is supposed to be called from a thread that already runs on this numa node and then kmalloc will allocate anyway on the right node, afaik. Do you have a use case where this is called from another node? If you do, all allocations in this file should be changed.

I don't have a use case I'm using but imo it seems hardier to ensure this at the kernel level for queue, pq, and ent allocations instead of assuming userspace will always submit the registration from the thread on the numa node corresponding to the qid it's registering. I don't feel strongly about this though so if you think the responsibility should be left to userspace, then that's fine with me.

Thanks,
Joanne

Quoted 3 lines

Thanks,
Bernd

author maintainer
#4 lore raw
Quoted 39 lines · Joanne Koong
Quoted 30 lines · Bernd Schubert
Quoted 19 lines · Joanne Koong
Quoted 18 lines · Joanne Koong

There is a 1:1 mapping between cpus and queues. Allocate the queue on the numa node associated with the cpu to help reduce memory access latencies.

---
 fs/fuse/dev_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev_uring.c +0 -0
index accdce2977c5..0762d6229ac6 100644
@@ -256,7 +256,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring,
        struct fuse_ring_queue *queue;
        struct list_head *pq;
 
Quoted 8 lines

fs/fuse/dev_uring.c static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, · line 262

Quoted 5 lines
fs/fuse/dev_uring.c +1 -1
-       queue = kzalloc(sizeof(*queue), GFP_KERNEL_ACCOUNT);
+       queue = kzalloc_node(sizeof(*queue), GFP_KERNEL_ACCOUNT, cpu_to_node(qid));
        if (!queue)
                return NULL;
        pq = kcalloc(FUSE_PQ_HASH_SIZE, sizeof(struct list_head), GFP_KERNEL);

On the same note I guess we should also allocate pq on the corresponding numa node too.

Quoted 5 lines

So this is supposed to be called from a thread that already runs on this numa node and then kmalloc will allocate anyway on the right node, afaik. Do you have a use case where this is called from another node? If you do, all allocations in this file should be changed.

Quoted 6 lines

I don't have a use case I'm using but imo it seems hardier to ensure this at the kernel level for queue, pq, and ent allocations instead of assuming userspace will always submit the registration from the thread on the numa node corresponding to the qid it's registering. I don't feel strongly about this though so if you think the responsibility should be left to userspace, then that's fine with me.

Thinking about this some more, if the responsibility for numa affinity should be left to userspace, then that should hold true too for configurable queues, no?

Thanks,
Joanne

Quoted 7 lines

Thanks,
Joanne

Quoted 3 lines

Thanks,
Bernd

#5 lore raw
In reply to Joanne Koong
Quoted 38 lines · Joanne Koong
Quoted 30 lines · Bernd Schubert
Quoted 19 lines · Joanne Koong
Quoted 18 lines · Joanne Koong

There is a 1:1 mapping between cpus and queues. Allocate the queue on the numa node associated with the cpu to help reduce memory access latencies.

---
 fs/fuse/dev_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev_uring.c +0 -0
index accdce2977c5..0762d6229ac6 100644
@@ -256,7 +256,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring,
        struct fuse_ring_queue *queue;
        struct list_head *pq;
 
Quoted 8 lines

fs/fuse/dev_uring.c static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, · line 262

Quoted 5 lines
fs/fuse/dev_uring.c +1 -1
-       queue = kzalloc(sizeof(*queue), GFP_KERNEL_ACCOUNT);
+       queue = kzalloc_node(sizeof(*queue), GFP_KERNEL_ACCOUNT, cpu_to_node(qid));
        if (!queue)
                return NULL;
        pq = kcalloc(FUSE_PQ_HASH_SIZE, sizeof(struct list_head), GFP_KERNEL);

On the same note I guess we should also allocate pq on the corresponding numa node too.

Quoted 5 lines

So this is supposed to be called from a thread that already runs on this numa node and then kmalloc will allocate anyway on the right node, afaik. Do you have a use case where this is called from another node? If you do, all allocations in this file should be changed.

Quoted 7 lines

I don't have a use case I'm using but imo it seems hardier to ensure this at the kernel level for queue, pq, and ent allocations instead of assuming userspace will always submit the registration from the thread on the numa node corresponding to the qid it's registering. I don't feel strongly about this though so if you think the responsibility should be left to userspace, then that's fine with me.

What I basically mean is that these threads are going to send the initial SQE, shouldn't it? Sounds a bit weird to me if the setup and sending the registration SQE are from different threads than the later handling.

Thanks,
Bernd