Skip to content

Commit 7126803

Browse files
sergey-senozhatskyakpm00
authored andcommitted
zram: free slot memory early during write
Patch series "zram: split page type read/write handling", v2. This is a subset of [1] series which contains only fixes and improvements (no new features, as ZRAM_HUGE split is still under consideration). The motivation for factoring out is that zram_write_page() gets more and more complex all the time, because it tries to handle too many scenarios: ZRAM_SAME store, ZRAM_HUGE store, compress page store with zs_malloc allocation slowpath and conditional recompression, etc. Factor those out and make things easier to handle. Addition of cond_resched() is simply a fix, I can trigger watchdog from zram writeback(). And early slot free is just a reasonable thing to do. [1] https://lore.kernel.org/linux-kernel/[email protected] This patch (of 7): In the current implementation entry's previously allocated memory is released in the very last moment, when we already have allocated a new memory for new data. This, basically, temporarily increases memory usage for no good reason. For example, consider the case when both old (stale) and new entry data are incompressible so such entry will temporarily use two physical pages - one for stale (old) data and one for new data. We can release old memory as soon as we get a write request for entry. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sergey Senozhatsky <[email protected]> Cc: Minchan Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6769183 commit 7126803

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,11 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
16491649
unsigned long element = 0;
16501650
enum zram_pageflags flags = 0;
16511651

1652+
/* First, free memory allocated to this slot (if any) */
1653+
zram_slot_lock(zram, index);
1654+
zram_free_page(zram, index);
1655+
zram_slot_unlock(zram, index);
1656+
16521657
mem = kmap_local_page(page);
16531658
if (page_same_filled(mem, &element)) {
16541659
kunmap_local(mem);
@@ -1737,13 +1742,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
17371742
zs_unmap_object(zram->mem_pool, handle);
17381743
atomic64_add(comp_len, &zram->stats.compr_data_size);
17391744
out:
1740-
/*
1741-
* Free memory associated with this sector
1742-
* before overwriting unused sectors.
1743-
*/
17441745
zram_slot_lock(zram, index);
1745-
zram_free_page(zram, index);
1746-
17471746
if (comp_len == PAGE_SIZE) {
17481747
zram_set_flag(zram, index, ZRAM_HUGE);
17491748
atomic64_inc(&zram->stats.huge_pages);

0 commit comments

Comments
 (0)