Use io_uring_register_ring_fd() to skip fd operations
PATCH v3 1/1 Use io_uring_register_ring_fd() to skip fd operations
Linux recently added a new io_uring(7) optimization API that QEMU doesn't take advantage of yet. The liburing library that QEMU uses has added a corresponding new API calling io_uring_register_ring_fd(). When this API is called after creating the ring, the io_uring_submit() library function passes a flag to the io_uring_enter(2) syscall allowing it to skip the ring file descriptor fdget()/fdput() operations. This saves some CPU cycles.
--- block/io_uring.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
block/io_uring.c +9 -1
@@ -435,8 +435,16 @@ LuringState *luring_init(Error **errp) }ioq_init (&s->io_q); -return s; +if (io_uring_register_ring_fd (&s->ring) <0 ) { +/* +* Only warn about this error: we will fallback to the non-optimized +* io_uring operations. +*/ +error_setg_errno (errp, errno, +"failed to register linux io_uring ring file descriptor" ); + } +return s; }void luring_cleanup (LuringState *s)
Signature · 1 line
2.35.1
Quoted 22 lines · Sam Li
Linux recently added a new
io_uring(7)optimization API that QEMU doesn't take advantage of yet. The liburing library that QEMU uses has added a corresponding new API callingio_uring_register_ring_fd(). When this API is called after creating the ring, theio_uring_submit()library function passes a flag to theio_uring_enter(2)syscall allowing it to skip the ring file descriptor fdget()/fdput() operations. This saves some CPU cycles.Signed-off-by Sam Li <[email protected]>--- block/io_uring.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)block/io_uring.c +0
-1@@ -435,8 +435,16 @@ LuringState *luring_init(Error **errp) }ioq_init (&s->io_q); -return s;
block/io_uring.c LuringState *luring_init(Error **errp) · line 447
Quoted 10 lines
block/io_uring.c +9
-0+if (io_uring_register_ring_fd (&s->ring) <0 ) { +/* +* Only warn about this error: we will fallback to the non-optimized +* io_uring operations. +*/ +error_setg_errno (errp, errno, +"failed to register linux io_uring ring file descriptor" ); + } +return s;
As a general convention, I don't think the errp is going to get proper handling by the callers, if non-NULL is returned like here. IOW a matching error_free is never called and this is memory leak?
I guess error_report is better?
Fam
Quoted 7 lines
block/io_uring.c +0
-0}void luring_cleanup (LuringState *s)Signature · 1 line
2.35.1
Hi Fam,
I've missed out freeing error object and error_report would be a better case indeed.
Thanks for pointing out the problem. I'll fix that in no time.
Best regards,
Sam
Quoted 54 lines · Fam Zheng <[email protected]> 于2022年4月21日周四 21:36写道:
Quoted 18 lines · Sam Li
Linux recently added a new
io_uring(7)optimization API that QEMU doesn't take advantage of yet. The liburing library that QEMU uses has added a corresponding new API callingio_uring_register_ring_fd(). When this API is called after creating the ring, theio_uring_submit()library function passes a flag to theio_uring_enter(2)syscall allowing it to skip the ring file descriptor fdget()/fdput() operations. This saves some CPU cycles.Signed-off-by Sam Li <[email protected]>--- block/io_uring.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)block/io_uring.c +0
-0block/io_uring.c LuringState *luring_init(Error **errp) · line 440
Quoted 7 lines
block/io_uring.c +3
-1@@ -435,8 +435,16 @@ LuringState *luring_init(Error **errp) }ioq_init (&s->io_q); -return s; +if (io_uring_register_ring_fd (&s->ring) <0 ) { +/* +* Only warn about this error: we will fallback to the non-optimized
block/io_uring.c LuringState *luring_init(Error **errp)
Quoted 4 lines
block/io_uring.c +4
-0+* io_uring operations. +*/ + error_setg_errno(errp, errno, + "failed to register linux io_uring ring filedescriptor");
block/io_uring.c LuringState *luring_init(Error **errp) · line 447
Quoted 3 lines
block/io_uring.c +2
-0+ } +return s;As a general convention, I don't think the errp is going to get proper handling
by the callers, if non-NULL is returned like here. IOW a matchingerror_freeis
never called and this is memory leak?I guess
error_reportis better?Fam
Quoted 7 lines
block/io_uring.c +0
-1}void luring_cleanup (LuringState *s) --2.35.1