Skip to contentSkip to conversation

zram: keep the exact overcommited value in mem_used_max

PATCH In review Sergey Senozhatsky 2 participants 2 messages Sep 24, 2015 – Sep 30, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zram: keep the exact overcommited value in mem_used_max

From: Sergey SENOZHATSKY <[email protected]>

`mem_used_max' is designed to store the max amount of memory zram consumed to store the data. However, it does not represent the actual 'overcommited' (max) value. The existing code goes to -ENOMEM overcommited case before it updates ->stats.max_used_pages', which hides the reason we went to -ENOMEM in the first place -- we actually used more memory than ->limit_pages':

        alloced_pages = zs_get_total_pages(meta->mem_pool);
        if (zram->limit_pages && alloced_pages > zram->limit_pages) {
                zs_free(meta->mem_pool, handle);
                ret = -ENOMEM;
                goto out;
        }

        update_used_max(zram, alloced_pages);

Which is misleading. User will see -ENOMEM, check ->limit_pages', check ->stats.max_used_pages', which will keep the value BEFORE zram passed `->limit_pages', and see:

	`->stats.max_used_pages' < `->limit_pages'

Move update_used_max() before we do `->limit_pages' check, so that user will see:

	`->stats.max_used_pages' > `->limit_pages'

should the overcommit and -ENOMEM happen.

---
 drivers/block/zram/zram_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/zram/zram_drv.c +2 -2
index cb478ca..6f04fb2 100644
@@ -738,14 +738,14 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 	}
 
 	alloced_pages = zs_get_total_pages(meta->mem_pool);
+	update_used_max(zram, alloced_pages);
+
 	if (zram->limit_pages && alloced_pages > zram->limit_pages) {
 		zs_free(meta->mem_pool, handle);
 		ret = -ENOMEM;
 		goto out;
 	}
 
-	update_used_max(zram, alloced_pages);
-
 	cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO);
 
 	if ((clen == PAGE_SIZE) && !is_partial_io(bvec)) {
Signature · 1 line
2.5.3
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · Sergey Senozhatsky

From: Sergey SENOZHATSKY <[email protected]>

`mem_used_max' is designed to store the max amount of memory zram consumed to store the data. However, it does not represent the actual 'overcommited' (max) value. The existing code goes to -ENOMEM overcommited case before it updates ->stats.max_used_pages', which hides the reason we went to -ENOMEM in the first place -- we actually used more memory than ->limit_pages':

        alloced_pages = zs_get_total_pages(meta->mem_pool);
        if (zram->limit_pages && alloced_pages > zram->limit_pages) {
                zs_free(meta->mem_pool, handle);
                ret = -ENOMEM;
                goto out;
        }

        update_used_max(zram, alloced_pages);

Which is misleading. User will see -ENOMEM, check ->limit_pages', check ->stats.max_used_pages', which will keep the value BEFORE zram passed `->limit_pages', and see:

Quoted 8 lines
	`->stats.max_used_pages' < `->limit_pages'

Move update_used_max() before we do `->limit_pages' check, so that user will see:

	`->stats.max_used_pages' > `->limit_pages'

should the overcommit and -ENOMEM happen.

It was intent.

IOW, I want that max_mem_used is never higher than mem_limit but I realized you are right because user doesn't have way to detect where -ENOMEM is coming from.
For example, it could come from mem_limit or real memory alloc fail.

Thanks, Sergey.