All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jackie Liu <liuyun01@kylinos.cn>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, Jackie Liu <liuyun01@kylinos.cn>
Subject: [PATCH 1/3] io_uring: free memory immediately when io_mem_alloc failed
Date: Thu, 23 May 2019 09:59:45 +0800	[thread overview]
Message-ID: <1558576787-18310-1-git-send-email-liuyun01@kylinos.cn> (raw)

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





             reply	other threads:[~2019-05-23  2:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23  1:59 Jackie Liu [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1558576787-18310-1-git-send-email-liuyun01@kylinos.cn \
    --to=liuyun01@kylinos.cn \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.