]> git.ipfire.org Git - thirdparty/linux.git/commit
mm: zsmalloc: return -ENOSPC rather than -EINVAL in zs_malloc while size is too large
authorBarry Song <21cnbao@gmail.com>
Thu, 28 Dec 2023 06:18:02 +0000 (19:18 +1300)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 5 Jan 2024 18:17:47 +0000 (10:17 -0800)
commitfc8580edbaa664b952063371805e4550afd7a139
tree7cdfa6446f4efca850012b0f6b65035133efd20a
parentc701123bd68bf1cc3bc167b4f597cb1f4995c39c
mm: zsmalloc: return -ENOSPC rather than -EINVAL in zs_malloc while size is too large

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>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>
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: 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