mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] aio: simplify exit_aio
@ 2014-02-18 15:35 Mateusz Guzik
  0 siblings, 0 replies; only message in thread
From: Mateusz Guzik @ 2014-02-18 15:35 UTC (permalink / raw)
  To: linux-aio; +Cc: linux-kernel

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).

Signed-off-by: Mateusz Guzik <mguzik@redhat.com>
---
 fs/aio.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 062a5f6..0701181 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -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)
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-02-18 15:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-18 15:35 [PATCH] aio: simplify exit_aio Mateusz Guzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®