Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 292337
b: refs/heads/master
c: 2dd542b
h: refs/heads/master
i:
  292335: 7f0802c
v: v3
  • Loading branch information
Al Viro committed Mar 21, 2012
1 parent 1d1f4e4 commit 53f3414
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e23754f880f10124f0a2848f9d17e361a295378e
refs/heads/master: 2dd542b7aeb1c222273cf0593a718d9b44998d9f
42 changes: 14 additions & 28 deletions trunk/fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,7 @@ static int aio_setup_ring(struct kioctx *ctx)
static void ctx_rcu_free(struct rcu_head *head)
{
struct kioctx *ctx = container_of(head, struct kioctx, rcu_head);
unsigned nr_events = ctx->max_reqs;

kmem_cache_free(kioctx_cachep, ctx);

if (nr_events) {
spin_lock(&aio_nr_lock);
BUG_ON(aio_nr - nr_events > aio_nr);
aio_nr -= nr_events;
spin_unlock(&aio_nr_lock);
}
}

/* __put_ioctx
Expand All @@ -217,13 +208,20 @@ static void ctx_rcu_free(struct rcu_head *head)
*/
static void __put_ioctx(struct kioctx *ctx)
{
unsigned nr_events = ctx->max_reqs;
BUG_ON(ctx->reqs_active);

cancel_delayed_work(&ctx->wq);
cancel_work_sync(&ctx->wq.work);
aio_free_ring(ctx);
mmdrop(ctx->mm);
ctx->mm = NULL;
if (nr_events) {
spin_lock(&aio_nr_lock);
BUG_ON(aio_nr - nr_events > aio_nr);
aio_nr -= nr_events;
spin_unlock(&aio_nr_lock);
}
pr_debug("__put_ioctx: freeing %p\n", ctx);
call_rcu(&ctx->rcu_head, ctx_rcu_free);
}
Expand All @@ -247,7 +245,6 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
{
struct mm_struct *mm;
struct kioctx *ctx;
int did_sync = 0;
int err = -ENOMEM;

/* Prevent overflows */
Expand All @@ -257,7 +254,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
return ERR_PTR(-EINVAL);
}

if ((unsigned long)nr_events > aio_max_nr)
if (!nr_events || (unsigned long)nr_events > aio_max_nr)
return ERR_PTR(-EAGAIN);

ctx = kmem_cache_zalloc(kioctx_cachep, GFP_KERNEL);
Expand All @@ -281,25 +278,14 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
goto out_freectx;

/* limit the number of system wide aios */
do {
spin_lock_bh(&aio_nr_lock);
if (aio_nr + nr_events > aio_max_nr ||
aio_nr + nr_events < aio_nr)
ctx->max_reqs = 0;
else
aio_nr += ctx->max_reqs;
spin_lock_bh(&aio_nr_lock);
if (aio_nr + nr_events > aio_max_nr ||
aio_nr + nr_events < aio_nr) {
spin_unlock_bh(&aio_nr_lock);
if (ctx->max_reqs || did_sync)
break;

/* wait for rcu callbacks to have completed before giving up */
synchronize_rcu();
did_sync = 1;
ctx->max_reqs = nr_events;
} while (1);

if (ctx->max_reqs == 0)
goto out_cleanup;
}
aio_nr += ctx->max_reqs;
spin_unlock_bh(&aio_nr_lock);

/* now link into global list. */
spin_lock(&mm->ioctx_lock);
Expand Down

0 comments on commit 53f3414

Please sign in to comment.