* + mm-zsmalloc-return-enospc-rather-than-einval-in-zs_malloc-while-size-is-too-large.patch added to mm-unstable branch
@ 2023-12-28 19:12 Andrew Morton
2024-01-02 1:21 ` Sergey Senozhatsky
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Morton @ 2023-12-28 19:12 UTC (permalink / raw)
To: mm-commits, zhouchengming, yosryahmed, v-songbaohua, vitaly.wool,
sjenning, senozhatsky, nphamcs, minchan, hannes, ddstreet, chrisl,
21cnbao, akpm
The patch titled
Subject: mm: zsmalloc: return -ENOSPC rather than -EINVAL in zs_malloc while size is too large
has been added to the -mm mm-unstable branch. Its filename is
mm-zsmalloc-return-enospc-rather-than-einval-in-zs_malloc-while-size-is-too-large.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-zsmalloc-return-enospc-rather-than-einval-in-zs_malloc-while-size-is-too-large.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Barry Song <21cnbao@gmail.com>
Subject: mm: zsmalloc: return -ENOSPC rather than -EINVAL in zs_malloc while size is too large
Date: Thu, 28 Dec 2023 19:18:02 +1300
This is the case the "compressed" data is larger than the original data,
it is better to return -ENOSPC which can help zswap record a poor compr
rather than an invalid request. Then we get more friendly counting for
reject_compress_poor in debugfs.
bool zswap_store(struct folio *folio)
{
...
ret = zpool_malloc(zpool, dlen, gfp, &handle);
if (ret == -ENOSPC) {
zswap_reject_compress_poor++;
goto put_dstmem;
}
if (ret) {
zswap_reject_alloc_fail++;
goto put_dstmem;
}
...
}
Also, zbud_alloc() and z3fold_alloc() are returning ENOSPC in the same
case, eg
static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
unsigned long *handle)
{
...
if (!size || (gfp & __GFP_HIGHMEM))
return -EINVAL;
if (size > PAGE_SIZE)
return -ENOSPC;
...
}
Link: https://lkml.kernel.org/r/20231228061802.25280-1-v-songbaohua@oppo.com
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/zsmalloc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
--- a/mm/zsmalloc.c~mm-zsmalloc-return-enospc-rather-than-einval-in-zs_malloc-while-size-is-too-large
+++ a/mm/zsmalloc.c
@@ -1364,9 +1364,12 @@ unsigned long zs_malloc(struct zs_pool *
int newfg;
struct zspage *zspage;
- if (unlikely(!size || size > ZS_MAX_ALLOC_SIZE))
+ if (unlikely(!size))
return (unsigned long)ERR_PTR(-EINVAL);
+ if (unlikely(size > ZS_MAX_ALLOC_SIZE))
+ return (unsigned long)ERR_PTR(-ENOSPC);
+
handle = cache_alloc_handle(pool, gfp);
if (!handle)
return (unsigned long)ERR_PTR(-ENOMEM);
_
Patches currently in -mm which might be from 21cnbao@gmail.com are
mm-zsmalloc-return-enospc-rather-than-einval-in-zs_malloc-while-size-is-too-large.patch
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: + mm-zsmalloc-return-enospc-rather-than-einval-in-zs_malloc-while-size-is-too-large.patch added to mm-unstable branch
2023-12-28 19:12 + mm-zsmalloc-return-enospc-rather-than-einval-in-zs_malloc-while-size-is-too-large.patch added to mm-unstable branch Andrew Morton
@ 2024-01-02 1:21 ` Sergey Senozhatsky
0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2024-01-02 1:21 UTC (permalink / raw)
To: Andrew Morton
Cc: mm-commits, zhouchengming, yosryahmed, v-songbaohua, vitaly.wool,
sjenning, senozhatsky, nphamcs, minchan, hannes, ddstreet, chrisl,
21cnbao
On (23/12/28 11:12), Andrew Morton wrote:
> This is the case the "compressed" data is larger than the original data,
> it is better to return -ENOSPC which can help zswap record a poor compr
> rather than an invalid request. Then we get more friendly counting for
> reject_compress_poor in debugfs.
>
> bool zswap_store(struct folio *folio)
> {
> ...
> ret = zpool_malloc(zpool, dlen, gfp, &handle);
> if (ret == -ENOSPC) {
> zswap_reject_compress_poor++;
> goto put_dstmem;
> }
> if (ret) {
> zswap_reject_alloc_fail++;
> goto put_dstmem;
> }
> ...
> }
>
> Also, zbud_alloc() and z3fold_alloc() are returning ENOSPC in the same
> case, eg
>
> static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
> unsigned long *handle)
> {
> ...
> if (!size || (gfp & __GFP_HIGHMEM))
> return -EINVAL;
>
> if (size > PAGE_SIZE)
> return -ENOSPC;
> ...
> }
>
> Link: https://lkml.kernel.org/r/20231228061802.25280-1-v-songbaohua@oppo.com
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>
> Cc: Chris Li <chrisl@kernel.org>
> Cc: Dan Streetman <ddstreet@ieee.org>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: Nhat Pham <nphamcs@gmail.com>
> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
> Cc: Seth Jennings <sjenning@redhat.com>
> Cc: Vitaly Wool <vitaly.wool@konsulko.com>
> Cc: Yosry Ahmed <yosryahmed@google.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-02 1:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-28 19:12 + mm-zsmalloc-return-enospc-rather-than-einval-in-zs_malloc-while-size-is-too-large.patch added to mm-unstable branch Andrew Morton
2024-01-02 1:21 ` Sergey Senozhatsky
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.