Skip to contentSkip to conversation

io_uring: only call kfree() for a non-zero pointer

PATCH New Jens Axboe 1 participant 1 message Jul 8, 2020

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring: only call kfree() for a non-zero pointer

It's safe to call kfree() with a NULL pointer, but it's also pointless. Most of the time we don't have any data to free, and at millions of requests per second, the redundant function call adds noticeable overhead (about 1.3% of the runtime).

---

Kinda silly, this is 100% reproducible. Actually somewhat baffled that kfree() isn't a inline, to avoid a function call if the pointer is NULL.

fs/io_uring.c +2 -1
index 14168fbc7d79..51ff88330f9a 100644
@@ -1519,7 +1519,8 @@ static void io_dismantle_req(struct io_kiocb *req)
 	if (req->flags & REQ_F_NEED_CLEANUP)
 		io_cleanup_req(req);
 
-	kfree(req->io);
+	if (req->io)
+		kfree(req->io);
 	if (req->file)
 		io_put_file(req, req->file, (req->flags & REQ_F_FIXED_FILE));
 	__io_put_req_task(req);
Signature · 1 line
Jens Axboe