Skip to contentSkip to conversation

aio: simplify exit_aio

PATCH New Mateusz Guzik 1 participant 1 message Feb 18, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 aio: simplify exit_aio

Since there are no other callers which can manipulate ioctx_table at this stage it is not necessary to reload table pointer each time nor to traverse it under rcu_read_lock

While here convert the loop to more readable for () and fix the comment (aio_free_ring -> kill_ioctx).

---
 fs/aio.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)
fs/aio.c +15 -18
index 062a5f6..0701181 100644
@@ -766,38 +766,35 @@ void exit_aio(struct mm_struct *mm)
 {
 	struct kioctx_table *table;
 	struct kioctx *ctx;
-	unsigned i = 0;
+	unsigned i;
 
-	while (1) {
-		rcu_read_lock();
-		table = rcu_dereference(mm->ioctx_table);
-
-		do {
-			if (!table || i >= table->nr) {
-				rcu_read_unlock();
-				rcu_assign_pointer(mm->ioctx_table, NULL);
-				if (table)
-					kfree(table);
-				return;
-			}
+	rcu_read_lock();
+	table = rcu_dereference(mm->ioctx_table);
+	rcu_read_unlock();
 
-			ctx = table->table[i++];
-		} while (!ctx);
+	if (!table)
+		return;
 
-		rcu_read_unlock();
+	for (i = 0; i < table->nr; i++) {
+		ctx = table->table[i];
+		if (!ctx)
+			continue;
 
 		/*
 		 * We don't need to bother with munmap() here -
 		 * exit_mmap(mm) is coming and it'll unmap everything.
-		 * Since aio_free_ring() uses non-zero ->mmap_size
+		 * Since kill_ioctx() uses non-zero ->mmap_size
 		 * as indicator that it needs to unmap the area,
-		 * just set it to 0; aio_free_ring() is the only
+		 * just set it to 0; kill_ioctx() is the only
 		 * place that uses ->mmap_size, so it's safe.
 		 */
 		ctx->mmap_size = 0;
 
 		kill_ioctx(mm, ctx);
 	}
+
+	rcu_assign_pointer(mm->ioctx_table, NULL);
+	kfree(table);
 }
 
 static void put_reqs_available(struct kioctx *ctx, unsigned nr)
Signature · 1 line
1.8.3.1