zram: free meta table in zram_meta_free
Subsystems (3)
PATCH v2 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().
---
v2: use zram->disksize to get num of pages - Sergey
--- drivers/block/zram/zram_drv.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/block/zram/zram_drv.c +16 -17
@@ -307,8 +307,21 @@ static inline int valid_io_request(struct zram *zram,return 1 ; } -static void zram_meta_free (struct zram_meta *meta) +static void zram_meta_free (struct zram_meta *meta,u64 disksize) { +size_t num_pages = disksize >>PAGE_SHIFT ; +size_t index; + +/* Free all pages that are still in this zram device */ +for (index =0 ; index < 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);
@@ -706,9 +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; -down_write (&zram->init_lock); zram->limit_pages =0 ;
@@ -718,20 +728,9 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)return ; } - 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); zram->max_comp_streams =1 ; - -zram_meta_free (zram->meta); +zram_meta_free (zram->meta, zram->disksize); zram->meta =NULL ;/* Reset stats */ memset (&zram->stats,0 ,sizeof (zram->stats));
@@ -803,7 +802,7 @@ out_destroy_comp:up_write (&zram->init_lock);zcomp_destroy (comp); out_free_meta: -zram_meta_free (meta); +zram_meta_free (meta, disksize);return err; }
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>
Quoted 8 lines · Ganesh Mahendran
zram_meta_alloc()andzram_meta_free()are a pair.
Inzram_meta_alloc(), meta table is allocated. So it it better to free it inzram_meta_free().Signed-off-by Ganesh Mahendran <[email protected]>Cc Nitin Gupta <[email protected]>Cc Minchan Kim <[email protected]>Cc Sergey Senozhatsky <[email protected]>
-ss
Quoted 77 lines
---
v2: usezram->disksizeto get num of pages - Sergey--- drivers/block/zram/zram_drv.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)drivers/block/zram/zram_drv.c +16
-17@@ -307,8 +307,21 @@ static inline int valid_io_request(struct zram *zram,return 1 ; } -static void zram_meta_free (struct zram_meta *meta) +static void zram_meta_free (struct zram_meta *meta,u64 disksize) { +size_t num_pages = disksize >>PAGE_SHIFT ; +size_t index; + +/* Free all pages that are still in this zram device */ +for (index =0 ; index < 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);@@ -706,9 +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; -down_write (&zram->init_lock); zram->limit_pages =0 ;@@ -718,20 +728,9 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)return ; } - 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); zram->max_comp_streams =1 ; - -zram_meta_free (zram->meta); +zram_meta_free (zram->meta, zram->disksize); zram->meta =NULL ;/* Reset stats */ memset (&zram->stats,0 ,sizeof (zram->stats));@@ -803,7 +802,7 @@ out_destroy_comp:up_write (&zram->init_lock);zcomp_destroy (comp); out_free_meta: -zram_meta_free (meta); +zram_meta_free (meta, disksize);return err; }Signature · 1 line
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>
Quoted 5 lines · Ganesh Mahendran
zram_meta_alloc()andzram_meta_free()are a pair.
Inzram_meta_alloc(), meta table is allocated. So it it better to free it inzram_meta_free().Signed-off-by Ganesh Mahendran <[email protected]>
Thanks.
Signature · 8 lines
Kind regards, Minchan Kim -- 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>