From patchwork Thu Dec 28 06:18:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13505609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E700C3DA6E for ; Thu, 28 Dec 2023 06:18:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 675D76B008C; Thu, 28 Dec 2023 01:18:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FEE66B0092; Thu, 28 Dec 2023 01:18:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 478226B0093; Thu, 28 Dec 2023 01:18:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 322CA6B008C for ; Thu, 28 Dec 2023 01:18:35 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E2829140877 for ; Thu, 28 Dec 2023 06:18:34 +0000 (UTC) X-FDA: 81615222948.24.EDC55E7 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by imf14.hostedemail.com (Postfix) with ESMTP id 34BAA100003 for ; Thu, 28 Dec 2023 06:18:33 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Vau4ZtLI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.54 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703744313; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=rxIMVwBZrQhRU3eW4BYKC5oEBepRYtQLNSUTCCv8Ceg=; b=SHHuOXLhAoG/yOJFDrT78vRPLmpVbdf/BcI9ELOSY6RfGZ0O55HnClWjTksBjgrSffyXk8 gbaZ4mRU5fTGdkBvqxuW0wW6PISc74qmuDZiB0/EkVsRMgajSK6wkjPwzEUEeVeaXnC5A4 xbUof5qdDYlK8sl0mwvCsRM82oUrL7k= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Vau4ZtLI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.54 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703744313; a=rsa-sha256; cv=none; b=QxalC1pEFVO2fM2EL3CescCdRvEHqaGBwL3Dx1pi/HAkVZtDDuJ/IHlrjjHB9ZQDjr8gYP 4cdEKuZNyTsORUP7Vvx+l5FDBQ9P2aFupjp75+yTgjdSTRtiXGYCPgmtyoB6WOL2u41C6t 4HaOI5nLKeDbimSWg5C+xaJgOZ06jkU= Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6dbaf9b1674so3424402a34.2 for ; Wed, 27 Dec 2023 22:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703744312; x=1704349112; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rxIMVwBZrQhRU3eW4BYKC5oEBepRYtQLNSUTCCv8Ceg=; b=Vau4ZtLINZzVIdGWstan3L60DZxq8niBpQcOl5J2lghhp1J99RAeFR2qSeFR3+OgY+ 4gEvJ+CeJrw+I7iGMQjkKX7StTlXXstUBTKh0Yo4IelM+uwq95wy76w9QQ6m8qmbTDhk /cI/2uFIHlw8VI/COuSWGfh3TIpnVXLXoOw0qIbxjYMpZG3AnUp7zchIjKMs+2xeSv69 T1Qt8HiSYuPe9dETZ/uTt1F+sf4Qv773aPjo9aMIN72IXJo+Cf7y9QUXDawMIS0+fEUW /EHErglR1RdyfmLQOxFAU1adUPXAdPraHDFUfV2wlEYj5AbFOv8VFeH01t0jV3/mMDwG QikA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703744312; x=1704349112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rxIMVwBZrQhRU3eW4BYKC5oEBepRYtQLNSUTCCv8Ceg=; b=pTeutvdhd5a0kxXJFPcSSImMpXsRLt/eFYdo/KBTeDzwzLnsEClPTksoEhDytdshgl JoYzGQ68kQEP9wT4KEcaVm35SAqWR+Yiunho8ddR8E/QnSTR8syuhCaUAn8HMdlp7/a9 GfI5vRPdIA684gHVB/cD4vLhsOFFBtOp3c+gQ5E1L0qwUlPj8fg/FyhQIHMDJVws37ey G/4ZmF6DHifeox6hbAIn5uvMxO7WMlys/Rg+3eFtc2hfGDdElOwYXa5HyIP4r5YVxzXm RJFp4MD4gM66wV38P0gbW2WI2rbuUJEat/CTWndo7WcN/sBILZzfuNsUKXn4OOPiyfQG 7UBg== X-Gm-Message-State: AOJu0Yws9riILfpPldMwT8yWjlEHfTbWyAjxq4X/VS133+U/4GqrM0xz n0ECnpRK1EwXGJ/CXYn5EVg= X-Google-Smtp-Source: AGHT+IG+tTX6f1WO1cX43T6fpNmhAI3s17KwA+gQJPqBhzslegV4HyvyiGw2dLxLWXGZIUxSLVgzyA== X-Received: by 2002:a05:6358:99a8:b0:173:227:39bb with SMTP id j40-20020a05635899a800b00173022739bbmr10415388rwb.0.1703744311997; Wed, 27 Dec 2023 22:18:31 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:29f3:58d2:d37b:3e03]) by smtp.gmail.com with ESMTPSA id le6-20020a056a004fc600b006da0f15b31csm1611011pfb.97.2023.12.27.22.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 22:18:31 -0800 (PST) From: Barry Song <21cnbao@gmail.com> X-Google-Original-From: Barry Song To: minchan@kernel.org, senozhatsky@chromium.org, akpm@linux-foundation.org, linux-mm@kvack.org, ddstreet@ieee.org, sjenning@redhat.com, vitaly.wool@konsulko.com Cc: linux-kernel@vger.kernel.org, chriscli@google.com, chrisl@kernel.org, hannes@cmpxchg.org, yosryahmed@google.com, zhouchengming@bytedance.com, nphamcs@gmail.com, Barry Song Subject: [PATCH] mm: zsmalloc: return -ENOSPC rather than -EINVAL in zs_malloc while size is too large Date: Thu, 28 Dec 2023 19:18:02 +1300 Message-Id: <20231228061802.25280-1-v-songbaohua@oppo.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: iut5ycg5di55itd4tj7eerwg5weexc9x X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 34BAA100003 X-HE-Tag: 1703744313-739734 X-HE-Meta: U2FsdGVkX1+yZgir27iS7yK84UY4KyfEYDBX2D2lqoj2HKFKx99AXAfhVgyJ8dTZ6kh5AyoY3ZQqLmoyYfyPZxcsmmqdgD20WA6nDlRGDl2WzpZ13fIriHX8Zpp/R2wIetGs+H/pJdFImcE7alOPC5Qy/dvMu365usxogeeGXu3lx82ZaSiZicw62pcdl61TbR7l4pauQxHUVRY4bfXb98rf+aF/d+wBwr3XHZwdUoVDLhL8AoFvcC4XfIjpwlgXvML8PFBIYLy3QAtv8THxrdq4uNroCODBT72sVA15a3jckQxeqYntDrWHVaGTnzriGdL0z5jGL8xLorIU2B42C/XX2nwQYm5rEQLOsfba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YmNciwpGuZmkEggeViZTlrS4L0GjqBEL1rbiSo/M4tKvwUDeunlQek2zd/ytsj1M7oxgIUhcKNLiYw3fVP8JJyBtGvHms73/cS3w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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; ... } Signed-off-by: Barry Song Reviewed-by: Chengming Zhou Reviewed-by: Nhat Pham --- mm/zsmalloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b1c0dad7f4cf..c937635e0ad1 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1364,9 +1364,12 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) 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);