All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] zram: free meta out of init_lock
@ 2015-01-23  5:58 ` Minchan Kim
  0 siblings, 0 replies; 60+ messages in thread
From: Minchan Kim @ 2015-01-23  5:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-mm, Nitin Gupta, Jerome Marchand,
	Sergey Senozhatsky, Minchan Kim

We don't need to call zram_meta_free, zcomp_destroy and zs_free
under init_lock. What we need to prevent race with init_lock
in reset is setting NULL into zram->meta (ie, init_done).
This patch does it.

Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 drivers/block/zram/zram_drv.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 9250b3f54a8f..0299d82275e7 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -708,6 +708,7 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
 {
 	size_t index;
 	struct zram_meta *meta;
+	struct zcomp *comp;
 
 	down_write(&zram->init_lock);
 
@@ -719,20 +720,10 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
 	}
 
 	meta = zram->meta;
-	/* Free all pages that are still in this zram device */
-	for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) {
-		unsigned long handle = meta->table[index].handle;
-		if (!handle)
-			continue;
-
-		zs_free(meta->mem_pool, handle);
-	}
-
-	zcomp_destroy(zram->comp);
+	comp = zram->comp;
+	zram->meta = NULL;
 	zram->max_comp_streams = 1;
 
-	zram_meta_free(zram->meta);
-	zram->meta = NULL;
 	/* Reset stats */
 	memset(&zram->stats, 0, sizeof(zram->stats));
 
@@ -742,6 +733,19 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
 
 	up_write(&zram->init_lock);
 
+	/* Free all pages that are still in this zram device */
+	for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) {
+		unsigned long handle = meta->table[index].handle;
+
+		if (!handle)
+			continue;
+
+		zs_free(meta->mem_pool, handle);
+	}
+
+	zcomp_destroy(comp);
+	zram_meta_free(meta);
+
 	/*
 	 * Revalidate disk out of the init_lock to avoid lockdep splat.
 	 * It's okay because disk's capacity is protected by init_lock
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2015-01-28  6:11 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23  5:58 [PATCH 1/2] zram: free meta out of init_lock Minchan Kim
2015-01-23  5:58 ` Minchan Kim
2015-01-23  5:58 ` [PATCH 2/2] zram: protect zram->stat race with init_lock Minchan Kim
2015-01-23  5:58   ` Minchan Kim
2015-01-23 13:45   ` Jerome Marchand
2015-01-23 14:38   ` Sergey Senozhatsky
2015-01-23 14:38     ` Sergey Senozhatsky
2015-01-24 13:17     ` Ganesh Mahendran
2015-01-24 13:17       ` Ganesh Mahendran
2015-01-25 14:38       ` Sergey Senozhatsky
2015-01-25 14:38         ` Sergey Senozhatsky
2015-01-23 13:07 ` [PATCH 1/2] zram: free meta out of init_lock Jerome Marchand
2015-01-23 14:24 ` Sergey Senozhatsky
2015-01-23 14:24   ` Sergey Senozhatsky
2015-01-23 14:48   ` Jerome Marchand
2015-01-23 15:47     ` Sergey Senozhatsky
2015-01-23 15:47       ` Sergey Senozhatsky
2015-01-26  1:33       ` Minchan Kim
2015-01-26  1:33         ` Minchan Kim
2015-01-26 14:17         ` Sergey Senozhatsky
2015-01-26 14:17           ` Sergey Senozhatsky
2015-01-26 16:00           ` Minchan Kim
2015-01-26 16:00             ` Minchan Kim
2015-01-27  2:17             ` Sergey Senozhatsky
2015-01-27  2:17               ` Sergey Senozhatsky
2015-01-27  3:18               ` Minchan Kim
2015-01-27  3:18                 ` Minchan Kim
2015-01-27  4:03                 ` Sergey Senozhatsky
2015-01-27  4:03                   ` Sergey Senozhatsky
2015-01-28  0:15                   ` Minchan Kim
2015-01-28  0:15                     ` Minchan Kim
2015-01-28  0:22                     ` Minchan Kim
2015-01-28  0:22                       ` Minchan Kim
2015-01-28  2:07                       ` Sergey Senozhatsky
2015-01-28  2:07                         ` Sergey Senozhatsky
2015-01-28  2:57                         ` Minchan Kim
2015-01-28  2:57                           ` Minchan Kim
2015-01-28  3:53                           ` Sergey Senozhatsky
2015-01-28  3:53                             ` Sergey Senozhatsky
2015-01-28  4:07                             ` Sergey Senozhatsky
2015-01-28  4:07                               ` Sergey Senozhatsky
2015-01-28  4:50                               ` Sergey Senozhatsky
2015-01-28  4:50                                 ` Sergey Senozhatsky
2015-01-28  4:58                                 ` Minchan Kim
2015-01-28  4:58                                   ` Minchan Kim
2015-01-28  5:35                                   ` Minchan Kim
2015-01-28  5:35                                     ` Minchan Kim
2015-01-28  6:08                                     ` Sergey Senozhatsky
2015-01-28  6:08                                       ` Sergey Senozhatsky
2015-01-28  6:10                                       ` Sergey Senozhatsky
2015-01-28  6:10                                         ` Sergey Senozhatsky
2015-01-28  4:55                             ` Minchan Kim
2015-01-28  4:55                               ` Minchan Kim
2015-01-28  0:24                     ` Sergey Senozhatsky
2015-01-28  0:24                       ` Sergey Senozhatsky
2015-01-28  0:59                       ` Minchan Kim
2015-01-28  0:59                         ` Minchan Kim
2015-01-26 14:34         ` Jerome Marchand
2015-01-26 15:52           ` Minchan Kim
2015-01-26 15:52             ` Minchan Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.