Skip to content

Commit 432c799

Browse files
Christoph Hellwigaxboe
authored andcommitted
aio: separate out ring reservation from req allocation
This is in preparation for certain types of IO not needing a ring reserveration. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent bc9bff6 commit 432c799

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

fs/aio.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ static void put_reqs_available(struct kioctx *ctx, unsigned nr)
902902
local_irq_restore(flags);
903903
}
904904

905-
static bool get_reqs_available(struct kioctx *ctx)
905+
static bool __get_reqs_available(struct kioctx *ctx)
906906
{
907907
struct kioctx_cpu *kcpu;
908908
bool ret = false;
@@ -994,6 +994,14 @@ static void user_refill_reqs_available(struct kioctx *ctx)
994994
spin_unlock_irq(&ctx->completion_lock);
995995
}
996996

997+
static bool get_reqs_available(struct kioctx *ctx)
998+
{
999+
if (__get_reqs_available(ctx))
1000+
return true;
1001+
user_refill_reqs_available(ctx);
1002+
return __get_reqs_available(ctx);
1003+
}
1004+
9971005
/* aio_get_req
9981006
* Allocate a slot for an aio request.
9991007
* Returns NULL if no requests are free.
@@ -1002,24 +1010,15 @@ static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx)
10021010
{
10031011
struct aio_kiocb *req;
10041012

1005-
if (!get_reqs_available(ctx)) {
1006-
user_refill_reqs_available(ctx);
1007-
if (!get_reqs_available(ctx))
1008-
return NULL;
1009-
}
1010-
10111013
req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL|__GFP_ZERO);
10121014
if (unlikely(!req))
1013-
goto out_put;
1015+
return NULL;
10141016

10151017
percpu_ref_get(&ctx->reqs);
10161018
INIT_LIST_HEAD(&req->ki_list);
10171019
refcount_set(&req->ki_refcnt, 0);
10181020
req->ki_ctx = ctx;
10191021
return req;
1020-
out_put:
1021-
put_reqs_available(ctx, 1);
1022-
return NULL;
10231022
}
10241023

10251024
static struct kioctx *lookup_ioctx(unsigned long ctx_id)
@@ -1807,9 +1806,13 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
18071806
return -EINVAL;
18081807
}
18091808

1809+
if (!get_reqs_available(ctx))
1810+
return -EAGAIN;
1811+
1812+
ret = -EAGAIN;
18101813
req = aio_get_req(ctx);
18111814
if (unlikely(!req))
1812-
return -EAGAIN;
1815+
goto out_put_reqs_available;
18131816

18141817
if (iocb.aio_flags & IOCB_FLAG_RESFD) {
18151818
/*
@@ -1872,11 +1875,12 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
18721875
goto out_put_req;
18731876
return 0;
18741877
out_put_req:
1875-
put_reqs_available(ctx, 1);
18761878
percpu_ref_put(&ctx->reqs);
18771879
if (req->ki_eventfd)
18781880
eventfd_ctx_put(req->ki_eventfd);
18791881
kmem_cache_free(kiocb_cachep, req);
1882+
out_put_reqs_available:
1883+
put_reqs_available(ctx, 1);
18801884
return ret;
18811885
}
18821886

0 commit comments

Comments
 (0)