block: use eBPF to redirect IO completion
Subsystems (8)
cover block: use eBPF to redirect IO completion
For network stack, RPS, namely Receive Packet Steering, is used to distribute network protocol processing from hardware-interrupted CPU to specific CPUs and alleviating soft-irq load of the interrupted CPU.
For block layer, soft-irq (for single queue device) or hard-irq (for multiple queue device) is used to handle IO completion, so RPS will be useful when the soft-irq load or the hard-irq load of a specific CPU is too high, or a specific CPU set is required to handle IO completion.
Instead of setting the CPU set used for handling IO completion through sysfs or procfs, we can attach an eBPF program to the request-queue, provide some useful info (e.g., the CPU which submits the request) to the program, and let the program decides the proper CPU for IO completion handling.
In order to demonostrate the effect of IO completion redirection, a test programm is built to redirect the IO completion handling to all online CPUs or a specific CPU set:
./test_blkdev_ccpu -d /dev/vda
or
./test_blkdev_ccpu -d /dev/nvme0n1 -s 4,8,10-13
However I am still trying to find out a killer scenario for the eBPF redirection, so suggestions and comments are welcome.
Regards,
Tao
Hou Tao (2):
block: add support for redirecting IO completion through eBPF selftests/bpf: add test program for redirecting IO completion CPU
block/Makefile | 2 +- block/blk-bpf.c | 127 +++++++++ block/blk-mq.c | 22 +- block/blk-softirq.c | 27 +- include/linux/blkdev.h | 3 + include/linux/bpf_blkdev.h | 9 + include/linux/bpf_types.h | 1 + include/uapi/linux/bpf.h | 2 + kernel/bpf/syscall.c | 9 + tools/include/uapi/linux/bpf.h | 2 + tools/lib/bpf/libbpf.c | 1 + tools/lib/bpf/libbpf_probes.c | 1 + tools/testing/selftests/bpf/Makefile | 1 + .../selftests/bpf/progs/blkdev_ccpu_rr.c | 66 +++++ .../testing/selftests/bpf/test_blkdev_ccpu.c | 246 ++++++++++++++++++ 15 files changed, 507 insertions(+), 12 deletions(-) create mode 100644 block/blk-bpf.c create mode 100644 include/linux/bpf_blkdev.h create mode 100644 tools/testing/selftests/bpf/progs/blkdev_ccpu_rr.c create mode 100644 tools/testing/selftests/bpf/test_blkdev_ccpu.c
Signature · 1 line
2.22.0
RFC PATCH 1/2 block: add support for redirecting IO completion through eBPF
For network stack, RPS, namely Receive Packet Steering, is used to distribute network protocol processing from hardware-interrupted CPU to specific CPUs and alleviating soft-irq load of the interrupted CPU.
For block layer, soft-irq (for single queue device) or hard-irq (for multiple queue device) is used to handle IO completion, so RPS will be useful when the soft-irq load or the hard-irq load of a specific CPU is too high, or a specific CPU set is required to handle IO completion.
Instead of setting the CPU set used for handling IO completion through sysfs or procfs, we can attach an eBPF program to the request-queue, provide some useful info (e.g., the CPU which submits the request) to the program, and let the program decides the proper CPU for IO completion handling.
--- block/Makefile | 2 +- block/blk-bpf.c | 127 +++++++++++++++++++++++++++++++++++++ block/blk-mq.c | 22 +++++-- block/blk-softirq.c | 27 ++++++-- include/linux/blkdev.h | 3 + include/linux/bpf_blkdev.h | 9 +++ include/linux/bpf_types.h | 1 + include/uapi/linux/bpf.h | 2 + kernel/bpf/syscall.c | 9 +++ 9 files changed, 190 insertions(+), 12 deletions(-) create mode 100644 block/blk-bpf.c create mode 100644 include/linux/bpf_blkdev.h
block/Makefile +1 -1
@@ -9,7 +9,7 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-sysfs.o \ blk-lib.o blk-mq.o blk-mq-tag.o blk-stat.o \ blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \ genhd.o partition-generic.o ioprio.o \ - badblocks.o partitions/ blk-rq-qos.o + badblocks.o partitions/ blk-rq-qos.o blk-bpf.o obj-$(CONFIG_BOUNCE) += bounce.o obj-$(CONFIG_BLK_SCSI_REQUEST) += scsi_ioctl.o
block/blk-bpf.c new file +127 -0
127 lines not on this page · raw message
block/blk-mq.c +18 -4
@@ -26,6 +26,7 @@#include <linux/delay.h> #include <linux/crash_dump.h> #include <linux/prefetch.h> +#include <linux/filter.h> #include <trace/events/block.h>
@@ -584,6 +585,9 @@ static void __blk_mq_complete_request(struct request *rq)struct request_queue *q = rq->q;bool shared = false;int cpu; +int ccpu; +int bpf_ccpu =-1 ; +struct bpf_prog *prog;WRITE_ONCE (rq->state,MQ_RQ_COMPLETE );/*
@@ -610,15 +614,25 @@ static void __blk_mq_complete_request(struct request *rq)return ; } +rcu_read_lock (); + prog =rcu_dereference_protected (q->prog,1 ); +if (prog) + bpf_ccpu =BPF_PROG_RUN (q->prog,NULL ); +rcu_read_unlock (); + cpu =get_cpu (); -if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) - shared =cpus_share_cache (cpu, ctx->cpu); +if (bpf_ccpu <0 || !cpu_online (bpf_ccpu)) { + ccpu = ctx->cpu; +if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) + shared =cpus_share_cache (cpu, ctx->cpu); + }else + ccpu = bpf_ccpu; -if (cpu != ctx->cpu && !shared &&cpu_online (ctx->cpu)) { +if (cpu != ccpu && !shared &&cpu_online (ccpu)) { rq->csd.func = __blk_mq_complete_request_remote; rq->csd.info = rq; rq->csd.flags =0 ; -smp_call_function_single_async (ctx->cpu, &rq->csd); +smp_call_function_single_async (ccpu, &rq->csd); }else { q->mq_ops->complete (rq); }
block/blk-softirq.c +20 -7
@@ -11,6 +11,7 @@#include <linux/cpu.h> #include <linux/sched.h> #include <linux/sched/topology.h> +#include <linux/filter.h> #include "blk.h"
@@ -101,20 +102,32 @@ void __blk_complete_request(struct request *req)int cpu, ccpu = req->mq_ctx->cpu;unsigned long flags;bool shared = false; +int bpf_ccpu =-1 ; +struct bpf_prog *prog;BUG_ON (!q->mq_ops->complete); -local_irq_save (flags); - cpu =smp_processor_id (); +rcu_read_lock (); + prog =rcu_dereference_protected (q->prog,1 ); +if (prog) + bpf_ccpu =BPF_PROG_RUN (q->prog,NULL ); +rcu_read_unlock ();/* -* Select completion CPU +* Select completion CPU. +* If a valid CPU number is returned by eBPF program, use it directly. */ -if (test_bit (QUEUE_FLAG_SAME_COMP , &q->queue_flags) && ccpu !=-1 ) { -if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) - shared =cpus_share_cache (cpu, ccpu); +local_irq_save (flags); + cpu =smp_processor_id (); +if (bpf_ccpu <0 || !cpu_online (bpf_ccpu)) { +if (test_bit (QUEUE_FLAG_SAME_COMP , &q->queue_flags) && + ccpu !=-1 ) { +if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) + shared =cpus_share_cache (cpu, ccpu); + }else + ccpu = cpu; }else - ccpu = cpu; + ccpu = bpf_ccpu;/* * If current CPU and requested CPU share a cache, run the softirq on
include/linux/blkdev.h +3 -0
@@ -397,6 +397,8 @@ static inline int blkdev_reset_zones_ioctl(struct block_device *bdev,#endif /* CONFIG_BLK_DEV_ZONED */ +struct bpf_prog ; +struct request_queue {struct request *last_merge;struct elevator_queue *elevator;
@@ -590,6 +592,7 @@ struct request_queue {#define BLK_MAX_WRITE_HINTS 5u64 write_hints[BLK_MAX_WRITE_HINTS ]; +struct bpf_prog __rcu *prog; };#define QUEUE_FLAG_STOPPED 0/* queue is stopped */
include/linux/bpf_blkdev.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __BPF_BLKDEV_H__ +#define __BPF_BLKDEV_H__ + +extern int blkdev_bpf_prog_attach (const union bpf_attr *attr, +enum bpf_prog_type ptype,struct bpf_prog *prog); +extern int blkdev_bpf_prog_detach (const union bpf_attr *attr); + +#endif /* !__BPF_BLKDEV_H__ */
include/linux/bpf_types.h +1 -0
@@ -38,6 +38,7 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_LIRC_MODE2, lirc_mode2)#ifdef CONFIG_INET BPF_PROG_TYPE(BPF_PROG_TYPE_SK_REUSEPORT, sk_reuseport)#endif +BPF_PROG_TYPE(BPF_PROG_TYPE_BLKDEV, blkdev) BPF_MAP_TYPE(BPF_MAP_TYPE_ARRAY, array_map_ops)BPF_MAP_TYPE (BPF_MAP_TYPE_PERCPU_ARRAY , percpu_array_map_ops)
include/uapi/linux/bpf.h +2 -0
@@ -173,6 +173,7 @@ enum bpf_prog_type {BPF_PROG_TYPE_CGROUP_SYSCTL ,BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE ,BPF_PROG_TYPE_CGROUP_SOCKOPT , + BPF_PROG_TYPE_BLKDEV, }; enum bpf_attach_type {
@@ -199,6 +200,7 @@ enum bpf_attach_type {BPF_CGROUP_UDP6_RECVMSG ,BPF_CGROUP_GETSOCKOPT ,BPF_CGROUP_SETSOCKOPT , +BPF_BLKDEV_IOC_CPU , __MAX_BPF_ATTACH_TYPE };
kernel/bpf/syscall.c +9 -0
@@ -4,6 +4,7 @@#include <linux/bpf.h> #include <linux/bpf_trace.h> #include <linux/bpf_lirc.h> +#include <linux/bpf_blkdev.h> #include <linux/btf.h> #include <linux/syscalls.h> #include <linux/slab.h>
@@ -1942,6 +1943,9 @@ static int bpf_prog_attach(const union bpf_attr *attr)case BPF_CGROUP_SETSOCKOPT : ptype =BPF_PROG_TYPE_CGROUP_SOCKOPT ;break ; +case BPF_BLKDEV_IOC_CPU : + ptype =BPF_PROG_TYPE_BLKDEV ; +break ;default :return -EINVAL ; }
@@ -1966,6 +1970,9 @@ static int bpf_prog_attach(const union bpf_attr *attr)case BPF_PROG_TYPE_FLOW_DISSECTOR : ret =skb_flow_dissector_bpf_prog_attach (attr, prog);break ; +case BPF_PROG_TYPE_BLKDEV : + ret =blkdev_bpf_prog_attach (attr, ptype, prog); +break ;default : ret =cgroup_bpf_prog_attach (attr, ptype, prog); }
@@ -2029,6 +2036,8 @@ static int bpf_prog_detach(const union bpf_attr *attr)case BPF_CGROUP_SETSOCKOPT : ptype =BPF_PROG_TYPE_CGROUP_SOCKOPT ;break ; +case BPF_BLKDEV_IOC_CPU : +return blkdev_bpf_prog_detach (attr);default :return -EINVAL ; }
Signature · 1 line
2.22.0
Re: [RFC PATCH 1/2] block: add support for redirecting IO completion through eBPF
Quoted 18 lines · Hou Tao
For network stack, RPS, namely Receive Packet Steering, is used to distribute network protocol processing from hardware-interrupted CPU to specific CPUs and alleviating soft-irq load of the interrupted CPU.
For block layer, soft-irq (for single queue device) or hard-irq (for multiple queue device) is used to handle IO completion, so RPS will be useful when the soft-irq load or the hard-irq load of a specific CPU is too high, or a specific CPU set is required to handle IO completion.
Instead of setting the CPU set used for handling IO completion through sysfs or procfs, we can attach an eBPF program to the request-queue, provide some useful info (e.g., the CPU which submits the request) to the program, and let the program decides the proper CPU for IO completion handling.
Signed-off-by Hou Tao <[email protected]>
...
Quoted 14 lines
block/blk-mq.c +10
-2+rcu_read_lock (); + prog =rcu_dereference_protected (q->prog,1 ); +if (prog) + bpf_ccpu =BPF_PROG_RUN (q->prog,NULL ); +rcu_read_unlock (); + cpu =get_cpu (); -if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) - shared =cpus_share_cache (cpu, ctx->cpu); +if (bpf_ccpu <0 || !cpu_online (bpf_ccpu)) { + ccpu = ctx->cpu; +if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) + shared =cpus_share_cache (cpu, ctx->cpu);
block/blk-mq.c static void __blk_mq_complete_request(struct request *rq) · line 635
Quoted 10 lines
block/blk-mq.c +4
-2+ }else + ccpu = bpf_ccpu; -if (cpu != ctx->cpu && !shared &&cpu_online (ctx->cpu)) { +if (cpu != ccpu && !shared &&cpu_online (ccpu)) { rq->csd.func = __blk_mq_complete_request_remote; rq->csd.info = rq; rq->csd.flags =0 ; -smp_call_function_single_async (ctx->cpu, &rq->csd); +smp_call_function_single_async (ccpu, &rq->csd);
Interesting idea.
Not sure whether such programability makes sense from block layer point of view.
From bpf side having a program with NULL input context is
a bit odd. We never had such things in the past, so this patchset won't work as-is.
Also no-input means that the program choices are quite limited. Other than round robin and random I cannot come up with other cpu selection ideas.
I suggest to do writable tracepoint here instead.
Take a look at trace_nbd_send_request.
BPF prog can write into 'request'.
For your use case it will be able to write into 'bpf_ccpu' local variable. If you keep it as raw tracepoint and don't add the actual tracepoint with TP_STRUCT__entry and TP_fast_assign then it won't be abi and you can change it later or remove it altogether.
Re: [RFC PATCH 1/2] block: add support for redirecting IO completion through eBPF
Quoted 49 lines · Alexei Starovoitov
Quoted 18 lines · Hou Tao
For network stack, RPS, namely Receive Packet Steering, is used to distribute network protocol processing from hardware-interrupted CPU to specific CPUs and alleviating soft-irq load of the interrupted CPU.
For block layer, soft-irq (for single queue device) or hard-irq (for multiple queue device) is used to handle IO completion, so RPS will be useful when the soft-irq load or the hard-irq load of a specific CPU is too high, or a specific CPU set is required to handle IO completion.
Instead of setting the CPU set used for handling IO completion through sysfs or procfs, we can attach an eBPF program to the request-queue, provide some useful info (e.g., the CPU which submits the request) to the program, and let the program decides the proper CPU for IO completion handling.
Signed-off-by Hou Tao <[email protected]>...
Quoted 14 lines
block/blk-mq.c +10
-2+rcu_read_lock (); + prog =rcu_dereference_protected (q->prog,1 ); +if (prog) + bpf_ccpu =BPF_PROG_RUN (q->prog,NULL ); +rcu_read_unlock (); + cpu =get_cpu (); -if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) - shared =cpus_share_cache (cpu, ctx->cpu); +if (bpf_ccpu <0 || !cpu_online (bpf_ccpu)) { + ccpu = ctx->cpu; +if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) + shared =cpus_share_cache (cpu, ctx->cpu);block/blk-mq.c static void __blk_mq_complete_request(struct request *rq) · line 635
Quoted 10 lines
block/blk-mq.c +4
-2+ }else + ccpu = bpf_ccpu; -if (cpu != ctx->cpu && !shared &&cpu_online (ctx->cpu)) { +if (cpu != ccpu && !shared &&cpu_online (ccpu)) { rq->csd.func = __blk_mq_complete_request_remote; rq->csd.info = rq; rq->csd.flags =0 ; -smp_call_function_single_async (ctx->cpu, &rq->csd); +smp_call_function_single_async (ccpu, &rq->csd);Interesting idea.
Not sure whether such programability makes sense from block layer point of view.
Quoted 14 lines
From bpf side having a program with NULL input context is
a bit odd. We never had such things in the past, so this patchset won't work as-is.
Also no-input means that the program choices are quite limited. Other than round robin and random I cannot come up with other cpu selection ideas.
I suggest to do writable tracepoint here instead.
Take a look attrace_nbd_send_request.
BPF prog can write into 'request'.
For your use case it will be able to write into 'bpf_ccpu' local variable. If you keep it as raw tracepoint and don't add the actual tracepoint withTP_STRUCT__entryandTP_fast_assignthen it won't be abi and you can change it later or remove it altogether.
That basically was my idea, too.
Actually I was coming from a different angle, namely trying to figure out how we could do generic error injection in the block layer. eBPF would be one way of doing it, kprobes another.
But writable trace events ... I'll have to check if we can leverage that here, too.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 247165 (AG München), GF: Felix Imendörffer
Re: [RFC PATCH 1/2] block: add support for redirecting IO completion through eBPF
In reply to Alexei StarovoitovHi,
Quoted 45 lines · Alexei Starovoitov
Quoted 18 lines · Hou Tao
For network stack, RPS, namely Receive Packet Steering, is used to distribute network protocol processing from hardware-interrupted CPU to specific CPUs and alleviating soft-irq load of the interrupted CPU.
For block layer, soft-irq (for single queue device) or hard-irq (for multiple queue device) is used to handle IO completion, so RPS will be useful when the soft-irq load or the hard-irq load of a specific CPU is too high, or a specific CPU set is required to handle IO completion.
Instead of setting the CPU set used for handling IO completion through sysfs or procfs, we can attach an eBPF program to the request-queue, provide some useful info (e.g., the CPU which submits the request) to the program, and let the program decides the proper CPU for IO completion handling.
Signed-off-by Hou Tao <[email protected]>...
Quoted 14 lines
block/blk-mq.c +10
-2+rcu_read_lock (); + prog =rcu_dereference_protected (q->prog,1 ); +if (prog) + bpf_ccpu =BPF_PROG_RUN (q->prog,NULL ); +rcu_read_unlock (); + cpu =get_cpu (); -if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) - shared =cpus_share_cache (cpu, ctx->cpu); +if (bpf_ccpu <0 || !cpu_online (bpf_ccpu)) { + ccpu = ctx->cpu; +if (!test_bit (QUEUE_FLAG_SAME_FORCE , &q->queue_flags)) + shared =cpus_share_cache (cpu, ctx->cpu);block/blk-mq.c static void __blk_mq_complete_request(struct request *rq) · line 635
Quoted 10 lines
block/blk-mq.c +4
-2+ }else + ccpu = bpf_ccpu; -if (cpu != ctx->cpu && !shared &&cpu_online (ctx->cpu)) { +if (cpu != ccpu && !shared &&cpu_online (ccpu)) { rq->csd.func = __blk_mq_complete_request_remote; rq->csd.info = rq; rq->csd.flags =0 ; -smp_call_function_single_async (ctx->cpu, &rq->csd); +smp_call_function_single_async (ccpu, &rq->csd);
Quoted 7 lines
Interesting idea.
Not sure whether such programability makes sense from block layer point of view.Quoted 1 line
From bpf side having a program with NULL input context is
a bit odd. We never had such things in the past, so this patchset won't work as-is.
No, it just works.
Quoted 10 lines
Also no-input means that the program choices are quite limited. Other than round robin and random I cannot come up with other cpu selection idea> I suggest to do writable tracepoint here instead. Take a look at
trace_nbd_send_request.
BPF prog can write into 'request'.
For your use case it will be able to write into 'bpf_ccpu' local variable. If you keep it as raw tracepoint and don't add the actual tracepoint withTP_STRUCT__entryandTP_fast_assignthen it won't be abi and you can change it later or remove it altogether.
Your suggestion is much simpler, so there will be no need for adding a new program type, and all things need to be done are adding a raw tracepoint, moving bpf_ccpu into struct request, and letting a BPF program to modify it.
I will try and thanks for your suggestions.
Regards,
Tao
Quoted 2 lines
.
Re: [RFC PATCH 1/2] block: add support for redirecting IO completion through eBPF
Quoted 3 lines · Hou Tao
Your suggestion is much simpler, so there will be no need for adding a new program type, and all things need to be done are adding a raw tracepoint, moving
bpf_ccpuinto struct request, and letting a BPF program to modify it.
blk-mq already supports processing completions on the CPU that submitted a request so it's not clear to me why any changes in the block layer are being proposed for redirecting I/O completions?
Thanks,
Bart.
Jens Axboe
maintainerRe: [RFC PATCH 1/2] block: add support for redirecting IO completion through eBPF
Quoted 8 lines · Bart Van Assche
Quoted 3 lines · Hou Tao
Your suggestion is much simpler, so there will be no need for adding a new program type, and all things need to be done are adding a raw tracepoint, moving
bpf_ccpuinto struct request, and letting a BPF program to modify it.blk-mq already supports processing completions on the CPU that submitted a request so it's not clear to me why any changes in the block layer are being proposed for redirecting I/O completions?
That's where I'm getting confused as well. I'm not against adding BPF functionality to the block layer, but this one seems a bit contrived.
Signature · 1 line
Jens Axboe
RFC PATCH 2/2 selftests/bpf: add test program for redirecting IO completion CPU
In reply to Hou TaoA simple round-robin strategy is implemented to redirect the IO completion handling to all online CPUs or specific CPU set cyclically.
Using the following command to distribute the IO completion of vda to all online CPUs:
./test_blkdev_ccpu -d /dev/vda
And the following command to distribute the IO completion of nvme0n1 to a specific CPU set:
./test_blkdev_ccpu -d /dev/nvme0n1 -s 4,8,10-13
--- tools/include/uapi/linux/bpf.h | 2 + tools/lib/bpf/libbpf.c | 1 + tools/lib/bpf/libbpf_probes.c | 1 + tools/testing/selftests/bpf/Makefile | 1 + .../selftests/bpf/progs/blkdev_ccpu_rr.c | 66 +++++ .../testing/selftests/bpf/test_blkdev_ccpu.c | 246 ++++++++++++++++++ 6 files changed, 317 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/blkdev_ccpu_rr.c create mode 100644 tools/testing/selftests/bpf/test_blkdev_ccpu.c
tools/include/uapi/linux/bpf.h +2 -0
@@ -173,6 +173,7 @@ enum bpf_prog_type {BPF_PROG_TYPE_CGROUP_SYSCTL ,BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE ,BPF_PROG_TYPE_CGROUP_SOCKOPT , + BPF_PROG_TYPE_BLKDEV, }; enum bpf_attach_type {
@@ -199,6 +200,7 @@ enum bpf_attach_type {BPF_CGROUP_UDP6_RECVMSG ,BPF_CGROUP_GETSOCKOPT ,BPF_CGROUP_SETSOCKOPT , +BPF_BLKDEV_IOC_CPU , __MAX_BPF_ATTACH_TYPE };
tools/lib/bpf/libbpf.c +1 -0
@@ -3579,6 +3579,7 @@ static bool bpf_prog_type__needs_kver(enum bpf_prog_type type)case BPF_PROG_TYPE_PERF_EVENT :case BPF_PROG_TYPE_CGROUP_SYSCTL :case BPF_PROG_TYPE_CGROUP_SOCKOPT : +case BPF_PROG_TYPE_BLKDEV :return false;case BPF_PROG_TYPE_KPROBE :default :
tools/lib/bpf/libbpf_probes.c +1 -0
@@ -102,6 +102,7 @@ probe_load(enum bpf_prog_type prog_type, const struct bpf_insn *insns,case BPF_PROG_TYPE_FLOW_DISSECTOR :case BPF_PROG_TYPE_CGROUP_SYSCTL :case BPF_PROG_TYPE_CGROUP_SOCKOPT : +case BPF_PROG_TYPE_BLKDEV :default :break ; }
tools/testing/selftests/bpf/Makefile +1 -0
@@ -30,6 +30,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test test_cgroup_storage test_select_reuseport test_section_names \ test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \ test_btf_dump test_cgroup_attach xdping +TEST_GEN_PROGS += test_blkdev_ccpu BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c))) TEST_GEN_FILES = $(BPF_OBJ_FILES)
tools/testing/selftests/bpf/progs/blkdev_ccpu_rr.c new file +66 -0
66 lines not on this page · raw message
tools/testing/selftests/bpf/test_blkdev_ccpu.c new file +246 -0
246 lines not on this page · raw message
Signature · 1 line
2.22.0
Quoted 10 lines · Hou Tao
For network stack, RPS, namely Receive Packet Steering, is used to distribute network protocol processing from hardware-interrupted CPU to specific CPUs and alleviating soft-irq load of the interrupted CPU.
For block layer, soft-irq (for single queue device) or hard-irq (for multiple queue device) is used to handle IO completion, so RPS will be useful when the soft-irq load or the hard-irq load of a specific CPU is too high, or a specific CPU set is required to handle IO completion.
Quoted 6 lines
Instead of setting the CPU set used for handling IO completion through sysfs or procfs, we can attach an eBPF program to the request-queue, provide some useful info (e.g., the CPU which submits the request) to the program, and let the program decides the proper CPU for IO completion handling.
But it looks like there isn't any benefit than through sysfs/procfs?
Quoted 9 lines
In order to demonostrate the effect of IO completion redirection, a test programm is built to redirect the IO completion handling to all online CPUs or a specific CPU set:
./test_blkdev_ccpu -d
/dev/vda
or./test_blkdev_ccpu -d /dev/nvme0n1 -s 4,8,10-13However I am still trying to find out a killer scenario for
Speaking about scenario, perhaps attaching a filter could be useful? So that the data can be processed the first place.
-
Bob
Quoted 30 lines
the eBPF redirection, so suggestions and comments are welcome.
Regards,
TaoHou Tao (2):
block: add support for redirecting IO completion through eBPF selftests/bpf: add test program for redirecting IO completion CPUblock/Makefile | 2 +- block/blk-bpf.c | 127 +++++++++ block/blk-mq.c | 22 +- block/blk-softirq.c | 27 +- include/linux/blkdev.h | 3 + include/linux/bpf_blkdev.h | 9 + include/linux/bpf_types.h | 1 + include/uapi/linux/bpf.h | 2 + kernel/bpf/syscall.c | 9 + tools/include/uapi/linux/bpf.h | 2 + tools/lib/bpf/libbpf.c | 1 + tools/lib/bpf/libbpf_probes.c | 1 + tools/testing/selftests/bpf/Makefile | 1 + .../selftests/bpf/progs/blkdev_ccpu_rr.c | 66 +++++ .../testing/selftests/bpf/test_blkdev_ccpu.c | 246 ++++++++++++++++++ 15 files changed, 507 insertions(+), 12 deletions(-) create mode 100644 block/blk-bpf.c create mode 100644 include/linux/bpf_blkdev.h create mode 100644 tools/testing/selftests/bpf/progs/blkdev_ccpu_rr.c create mode 100644 tools/testing/selftests/bpf/test_blkdev_ccpu.c