aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-04-30 13:02:48 -0400
committerBenjamin LaHaise <bcrl@kvack.org>2014-06-24 18:10:24 -0400
commit4b70ac5fd9b58bfaa5f25b4ea48f528aefbf3308 (patch)
treeef245ebab7daea1b368d20faa3314ab99a799022
parentedfbbf388f293d70bf4b7c0bc38774d05e6f711a (diff)
aio: change exit_aio() to load mm->ioctx_table once and avoid rcu_read_lock()
On 04/30, Benjamin LaHaise wrote: > > > - ctx->mmap_size = 0; > > - > > - kill_ioctx(mm, ctx, NULL); > > + if (ctx) { > > + ctx->mmap_size = 0; > > + kill_ioctx(mm, ctx, NULL); > > + } > > Rather than indenting and moving the two lines changing mmap_size and the > kill_ioctx() call, why not just do "if (!ctx) ... continue;"? That reduces > the number of lines changed and avoid excessive indentation. OK. To me the code looks better/simpler with "if (ctx)", but this is subjective of course, I won't argue. The patch still removes the empty line between mmap_size = 0 and kill_ioctx(), we reset mmap_size only for kill_ioctx(). But feel free to remove this change. ------------------------------------------------------------------------------- Subject: [PATCH v3 1/2] aio: change exit_aio() to load mm->ioctx_table once and avoid rcu_read_lock() 1. We can read ->ioctx_table only once and we do not read rcu_read_lock() or even rcu_dereference(). This mm has no users, nobody else can play with ->ioctx_table. Otherwise the code is buggy anyway, if we need rcu_read_lock() in a loop because ->ioctx_table can be updated then kfree(table) is obviously wrong. 2. Update the comment. "exit_mmap(mm) is coming" is the good reason to avoid munmap(), but another reason is that we simply can't do vm_munmap() unless current->mm == mm and this is not true in general, the caller is mmput(). 3. We do not really need to nullify mm->ioctx_table before return, probably the current code does this to catch the potential problems. But in this case RCU_INIT_POINTER(NULL) looks better. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
-rw-r--r--fs/aio.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/fs/aio.c b/fs/aio.c
index 955947ef3e02..b6696462e345 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -791,40 +791,30 @@ EXPORT_SYMBOL(wait_on_sync_kiocb);
791 */ 791 */
792void exit_aio(struct mm_struct *mm) 792void exit_aio(struct mm_struct *mm)
793{ 793{
794 struct kioctx_table *table; 794 struct kioctx_table *table = rcu_dereference_raw(mm->ioctx_table);
795 struct kioctx *ctx; 795 int i;
796 unsigned i = 0;
797
798 while (1) {
799 rcu_read_lock();
800 table = rcu_dereference(mm->ioctx_table);
801
802 do {
803 if (!table || i >= table->nr) {
804 rcu_read_unlock();
805 rcu_assign_pointer(mm->ioctx_table, NULL);
806 if (table)
807 kfree(table);
808 return;
809 }
810 796
811 ctx = table->table[i++]; 797 if (!table)
812 } while (!ctx); 798 return;
813 799
814 rcu_read_unlock(); 800 for (i = 0; i < table->nr; ++i) {
801 struct kioctx *ctx = table->table[i];
815 802
803 if (!ctx)
804 continue;
816 /* 805 /*
817 * We don't need to bother with munmap() here - 806 * We don't need to bother with munmap() here - exit_mmap(mm)
818 * exit_mmap(mm) is coming and it'll unmap everything. 807 * is coming and it'll unmap everything. And we simply can't,
819 * Since aio_free_ring() uses non-zero ->mmap_size 808 * this is not necessarily our ->mm.
820 * as indicator that it needs to unmap the area, 809 * Since kill_ioctx() uses non-zero ->mmap_size as indicator
821 * just set it to 0; aio_free_ring() is the only 810 * that it needs to unmap the area, just set it to 0.
822 * place that uses ->mmap_size, so it's safe.
823 */ 811 */
824 ctx->mmap_size = 0; 812 ctx->mmap_size = 0;
825
826 kill_ioctx(mm, ctx, NULL); 813 kill_ioctx(mm, ctx, NULL);
827 } 814 }
815
816 RCU_INIT_POINTER(mm->ioctx_table, NULL);
817 kfree(table);
828} 818}
829 819
830static void put_reqs_available(struct kioctx *ctx, unsigned nr) 820static void put_reqs_available(struct kioctx *ctx, unsigned nr)