Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+12 -7
+12 -7
fs/aio.c
··· 441 441 #endif 442 442 }; 443 443 444 - static int aio_setup_ring(struct kioctx *ctx) 444 + static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) 445 445 { 446 446 struct aio_ring *ring; 447 - unsigned nr_events = ctx->max_reqs; 448 447 struct mm_struct *mm = current->mm; 449 448 unsigned long size, unused; 450 449 int nr_pages; ··· 706 707 int err = -ENOMEM; 707 708 708 709 /* 710 + * Store the original nr_events -- what userspace passed to io_setup(), 711 + * for counting against the global limit -- before it changes. 712 + */ 713 + unsigned int max_reqs = nr_events; 714 + 715 + /* 709 716 * We keep track of the number of available ringbuffer slots, to prevent 710 717 * overflow (reqs_available), and we also use percpu counters for this. 711 718 * ··· 729 724 return ERR_PTR(-EINVAL); 730 725 } 731 726 732 - if (!nr_events || (unsigned long)nr_events > (aio_max_nr * 2UL)) 727 + if (!nr_events || (unsigned long)max_reqs > aio_max_nr) 733 728 return ERR_PTR(-EAGAIN); 734 729 735 730 ctx = kmem_cache_zalloc(kioctx_cachep, GFP_KERNEL); 736 731 if (!ctx) 737 732 return ERR_PTR(-ENOMEM); 738 733 739 - ctx->max_reqs = nr_events; 734 + ctx->max_reqs = max_reqs; 740 735 741 736 spin_lock_init(&ctx->ctx_lock); 742 737 spin_lock_init(&ctx->completion_lock); ··· 758 753 if (!ctx->cpu) 759 754 goto err; 760 755 761 - err = aio_setup_ring(ctx); 756 + err = aio_setup_ring(ctx, nr_events); 762 757 if (err < 0) 763 758 goto err; 764 759 ··· 769 764 770 765 /* limit the number of system wide aios */ 771 766 spin_lock(&aio_nr_lock); 772 - if (aio_nr + nr_events > (aio_max_nr * 2UL) || 773 - aio_nr + nr_events < aio_nr) { 767 + if (aio_nr + ctx->max_reqs > aio_max_nr || 768 + aio_nr + ctx->max_reqs < aio_nr) { 774 769 spin_unlock(&aio_nr_lock); 775 770 err = -EAGAIN; 776 771 goto err_ctx;