Skip to content

Commit 2500e28

Browse files
committed
Merge git://git.kvack.org/~bcrl/aio-next
Pull aio fix from Ben LaHaise: "Improve aio-nr counting on large SMP systems. It has been in linux-next for quite some time" * git://git.kvack.org/~bcrl/aio-next: fs: aio: fix the increment of aio-nr and counting against aio-max-nr
2 parents ae8ac6b + 2a8a986 commit 2500e28

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

fs/aio.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,9 @@ static const struct address_space_operations aio_ctx_aops = {
441441
#endif
442442
};
443443

444-
static int aio_setup_ring(struct kioctx *ctx)
444+
static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events)
445445
{
446446
struct aio_ring *ring;
447-
unsigned nr_events = ctx->max_reqs;
448447
struct mm_struct *mm = current->mm;
449448
unsigned long size, unused;
450449
int nr_pages;
@@ -706,6 +705,12 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
706705
struct kioctx *ctx;
707706
int err = -ENOMEM;
708707

708+
/*
709+
* Store the original nr_events -- what userspace passed to io_setup(),
710+
* for counting against the global limit -- before it changes.
711+
*/
712+
unsigned int max_reqs = nr_events;
713+
709714
/*
710715
* We keep track of the number of available ringbuffer slots, to prevent
711716
* overflow (reqs_available), and we also use percpu counters for this.
@@ -724,14 +729,14 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
724729
return ERR_PTR(-EINVAL);
725730
}
726731

727-
if (!nr_events || (unsigned long)nr_events > (aio_max_nr * 2UL))
732+
if (!nr_events || (unsigned long)max_reqs > aio_max_nr)
728733
return ERR_PTR(-EAGAIN);
729734

730735
ctx = kmem_cache_zalloc(kioctx_cachep, GFP_KERNEL);
731736
if (!ctx)
732737
return ERR_PTR(-ENOMEM);
733738

734-
ctx->max_reqs = nr_events;
739+
ctx->max_reqs = max_reqs;
735740

736741
spin_lock_init(&ctx->ctx_lock);
737742
spin_lock_init(&ctx->completion_lock);
@@ -753,7 +758,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
753758
if (!ctx->cpu)
754759
goto err;
755760

756-
err = aio_setup_ring(ctx);
761+
err = aio_setup_ring(ctx, nr_events);
757762
if (err < 0)
758763
goto err;
759764

@@ -764,8 +769,8 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
764769

765770
/* limit the number of system wide aios */
766771
spin_lock(&aio_nr_lock);
767-
if (aio_nr + nr_events > (aio_max_nr * 2UL) ||
768-
aio_nr + nr_events < aio_nr) {
772+
if (aio_nr + ctx->max_reqs > aio_max_nr ||
773+
aio_nr + ctx->max_reqs < aio_nr) {
769774
spin_unlock(&aio_nr_lock);
770775
err = -EAGAIN;
771776
goto err_ctx;

0 commit comments

Comments
 (0)