mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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/20241119072057.3440039-1-senozhatsky@chromium.org 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/20241218063513.297475-1-senozhatsky@chromium.org Link: https://lkml.kernel.org/r/20241218063513.297475-2-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									6769183166
								
							
						
					
					
						commit
						71268035f5
					
				
					 1 changed files with 5 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -1649,6 +1649,11 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
 | 
			
		|||
	unsigned long element = 0;
 | 
			
		||||
	enum zram_pageflags flags = 0;
 | 
			
		||||
 | 
			
		||||
	/* First, free memory allocated to this slot (if any) */
 | 
			
		||||
	zram_slot_lock(zram, index);
 | 
			
		||||
	zram_free_page(zram, index);
 | 
			
		||||
	zram_slot_unlock(zram, index);
 | 
			
		||||
 | 
			
		||||
	mem = kmap_local_page(page);
 | 
			
		||||
	if (page_same_filled(mem, &element)) {
 | 
			
		||||
		kunmap_local(mem);
 | 
			
		||||
| 
						 | 
				
			
			@ -1737,13 +1742,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
 | 
			
		|||
	zs_unmap_object(zram->mem_pool, handle);
 | 
			
		||||
	atomic64_add(comp_len, &zram->stats.compr_data_size);
 | 
			
		||||
out:
 | 
			
		||||
	/*
 | 
			
		||||
	 * Free memory associated with this sector
 | 
			
		||||
	 * before overwriting unused sectors.
 | 
			
		||||
	 */
 | 
			
		||||
	zram_slot_lock(zram, index);
 | 
			
		||||
	zram_free_page(zram, index);
 | 
			
		||||
 | 
			
		||||
	if (comp_len == PAGE_SIZE) {
 | 
			
		||||
		zram_set_flag(zram, index, ZRAM_HUGE);
 | 
			
		||||
		atomic64_inc(&zram->stats.huge_pages);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue