Skip to contentSkip to conversation

zram: free meta table in zram_meta_free

PATCH Superseded Ganesh Mahendran 2 participants 3 messages Jan 24, 2015 – Jan 27, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zram: free meta table in zram_meta_free

zram_meta_alloc() and zram_meta_free() are a pair.
In zram_meta_alloc(), meta table is allocated. So it it better to free it in zram_meta_free().

---
 drivers/block/zram/zram_drv.c |   28 ++++++++++++++--------------
 drivers/block/zram/zram_drv.h |    1 +
 2 files changed, 15 insertions(+), 14 deletions(-)
drivers/block/zram/zram_drv.c +14 -14
index 9bbc302..52fef1b 100644
@@ -309,6 +309,18 @@ static inline int valid_io_request(struct zram *zram,
 
 static void zram_meta_free(struct zram_meta *meta)
 {
+	size_t index;
+
+	/* Free all pages that are still in this zram device */
+	for (index = 0; index < meta->num_pages; index++) {
+		unsigned long handle = meta->table[index].handle;
+
+		if (!handle)
+			continue;
+
+		zs_free(meta->mem_pool, handle);
+	}
+
 	zs_destroy_pool(meta->mem_pool);
 	vfree(meta->table);
 	kfree(meta);
@@ -316,14 +328,13 @@ static void zram_meta_free(struct zram_meta *meta)
 
 static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
 {
-	size_t num_pages;
 	char pool_name[8];
 	struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
 	if (!meta)
 		goto out;
 
-	num_pages = disksize >> PAGE_SHIFT;
-	meta->table = vzalloc(num_pages * sizeof(*meta->table));
+	meta->num_pages = disksize >> PAGE_SHIFT;
+	meta->table = vzalloc(meta->num_pages * sizeof(*meta->table));
 	if (!meta->table) {
 		pr_err("Error allocating zram address table\n");
 		goto free_meta;
@@ -708,7 +719,6 @@ static void zram_bio_discard(struct zram *zram, u32 index,
 
 static void zram_reset_device(struct zram *zram, bool reset_capacity)
 {
-	size_t index;
 	struct zram_meta *meta;
 	struct zcomp *comp;
 
@@ -735,16 +745,6 @@ 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);
 
drivers/block/zram/zram_drv.h +1 -0
index b05a816..e492f6b 100644
@@ -96,6 +96,7 @@ struct zram_stats {
 struct zram_meta {
 	struct zram_table_entry *table;
 	struct zs_pool *mem_pool;
+	size_t num_pages;
 };
 
 struct zram {
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw

Hello,

Quoted 7 lines · Ganesh Mahendran

zram_meta_alloc() and zram_meta_free() are a pair.
In zram_meta_alloc(), meta table is allocated. So it it better to free it in zram_meta_free().

Looks good to me but it seems the patch is based on my recent work "zram: free meta out of init_lock".
Please resend it on recent mmotm because I will respin my patch and your patch is orthogonal with mine.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Hello, Minchan

2015-01-26 23:45 GMT+08:00 Minchan Kim <[email protected]>:

Quoted 7 lines

Hello,

Quoted 4 lines · Ganesh Mahendran

zram_meta_alloc() and zram_meta_free() are a pair.
In zram_meta_alloc(), meta table is allocated. So it it better to free it in zram_meta_free().

Quoted 8 lines
Quoted 3 lines

Looks good to me but it seems the patch is based on my recent work "zram: free meta out of init_lock".
Please resend it on recent mmotm because I will respin my patch and your patch is orthogonal with mine.

OK, I will resend the patch. Thanks.

Quoted 2 lines

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>