* [PATCH] zram: keep the exact overcommited value in mem_used_max
@ 2015-09-24 9:51 Sergey Senozhatsky
2015-09-30 1:28 ` Minchan Kim
0 siblings, 1 reply; 2+ messages in thread
From: Sergey Senozhatsky @ 2015-09-24 9:51 UTC (permalink / raw)
To: Minchan Kim
Cc: Andrew Morton, linux-kernel, Sergey Senozhatsky, Sergey SENOZHATSKY
From: Sergey SENOZHATSKY <sergey.senozhatsky@gmail.com>
`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.
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
drivers/block/zram/zram_drv.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index cb478ca..6f04fb2 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -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)) {
--
2.5.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] zram: keep the exact overcommited value in mem_used_max
2015-09-24 9:51 [PATCH] zram: keep the exact overcommited value in mem_used_max Sergey Senozhatsky
@ 2015-09-30 1:28 ` Minchan Kim
0 siblings, 0 replies; 2+ messages in thread
From: Minchan Kim @ 2015-09-30 1:28 UTC (permalink / raw)
To: Sergey Senozhatsky; +Cc: Andrew Morton, linux-kernel, Sergey Senozhatsky
On Thu, Sep 24, 2015 at 06:51:52PM +0900, Sergey Senozhatsky wrote:
> From: Sergey SENOZHATSKY <sergey.senozhatsky@gmail.com>
>
> `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.
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
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.
Acked-by: Minchan Kim <minchan@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-30 1:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-24 9:51 [PATCH] zram: keep the exact overcommited value in mem_used_max Sergey Senozhatsky
2015-09-30 1:28 ` Minchan Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®