All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] io_uring: free memory immediately when io_mem_alloc failed
@ 2019-05-23  1:59 Jackie Liu
  2019-05-23  1:59 ` [PATCH 2/3] io_uring: no need to reap event repeatedly Jackie Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jackie Liu @ 2019-05-23  1:59 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, Jackie Liu

In extreme cases, memory may not be available. so we should
be clean up memory.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 fs/io_uring.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 310f8d1..4430429 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2951,6 +2951,7 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx,
 	struct io_sq_ring *sq_ring;
 	struct io_cq_ring *cq_ring;
 	size_t size;
+	int ret;
 
 	sq_ring = io_mem_alloc(struct_size(sq_ring, array, p->sq_entries));
 	if (!sq_ring)
@@ -2963,16 +2964,22 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx,
 	ctx->sq_entries = sq_ring->ring_entries;
 
 	size = array_size(sizeof(struct io_uring_sqe), p->sq_entries);
-	if (size == SIZE_MAX)
-		return -EOVERFLOW;
+	if (size == SIZE_MAX) {
+		ret = -EOVERFLOW;
+		goto err;
+	}
 
 	ctx->sq_sqes = io_mem_alloc(size);
-	if (!ctx->sq_sqes)
-		return -ENOMEM;
+	if (!ctx->sq_sqes) {
+		ret = -ENOMEM;
+		goto err;
+	}
 
 	cq_ring = io_mem_alloc(struct_size(cq_ring, cqes, p->cq_entries));
-	if (!cq_ring)
-		return -ENOMEM;
+	if (!cq_ring) {
+		ret = -ENOMEM;
+		goto err1;
+	}
 
 	ctx->cq_ring = cq_ring;
 	cq_ring->ring_mask = p->cq_entries - 1;
@@ -2980,6 +2987,12 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx,
 	ctx->cq_mask = cq_ring->ring_mask;
 	ctx->cq_entries = cq_ring->ring_entries;
 	return 0;
+
+err1:
+	io_mem_free(ctx->sq_sqes);
+err:
+	io_mem_free(ctx->sq_ring);
+	return ret;
 }
 
 /*
-- 
2.7.4





^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-05-23  3:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-23  1:59 [PATCH 1/3] io_uring: free memory immediately when io_mem_alloc failed Jackie Liu
2019-05-23  1:59 ` [PATCH 2/3] io_uring: no need to reap event repeatedly Jackie Liu
2019-05-23  1:59 ` [PATCH 3/3] io_uring: adjust the code logic when an error occurs Jackie Liu
2019-05-23  3:15 ` [PATCH 1/3] io_uring: free memory immediately when io_mem_alloc failed Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.