From patchwork Sat Feb 17 05:36:42 2024 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: 13561246 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 B9FBCC48BC3 for ; Sat, 17 Feb 2024 05:37:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 140A76B009B; Sat, 17 Feb 2024 00:37:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F1AC6B009C; Sat, 17 Feb 2024 00:37:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFB026B009D; Sat, 17 Feb 2024 00:37:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E18F36B009B for ; Sat, 17 Feb 2024 00:37:00 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A9DB11C0090 for ; Sat, 17 Feb 2024 05:37:00 +0000 (UTC) X-FDA: 81800187000.27.15DC0FC Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf27.hostedemail.com (Postfix) with ESMTP id E7B5640002 for ; Sat, 17 Feb 2024 05:36:57 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dYhLn8Ge; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708148218; 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=lCLVx9kxWQaFnG1OpMOPtJ5A7Khl6+OxNkxfvJDWGlc=; b=rWYp0wgVksQgLG6JimSZZW9MQ3To+p4BqI2f92IyznM7LvjqwSKNY4W3lYk3823UaF/sIW kgLQPwss3YXCyJXVug7whPEQNxci3YmUqykyl/aik2F4pAIGEz0drGTKABjv4124dopGIj uO9EP2cnrRR47+d3jSspXhZB746oTB4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708148218; a=rsa-sha256; cv=none; b=XHMBCr6nwsTSKQv6FDBzrm4eDQlGKtFflAq/UCYdvStif8wum1x3JitJYLKIWZT0VNy45c 0v3rd+HAcA7Rai9bO0qrkJ4z0LmU88mog0xHUdGvdzbynRdEKuaeV3hvZaoSySCZ5aZ7TG 4EOtT2Ipr6sP+uiK+bC9+FIwoBk1uXA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dYhLn8Ge; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d7858a469aso23625305ad.2 for ; Fri, 16 Feb 2024 21:36:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708148217; x=1708753017; 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=lCLVx9kxWQaFnG1OpMOPtJ5A7Khl6+OxNkxfvJDWGlc=; b=dYhLn8GeBmqW3g4e/QvybL2wDLKy+qwOk8qkxoMy8GmPBwLM5SmKGpIttohSsaWYK4 auVmWPZKs/dFXwv13Lx+XCms3fj4kc+Nlf3/6r+Vtb66zxqgrN9FfieTEqJL9dly2Rz9 OFXDpHeb3/8hXuPjh8sPEQx2y71RI9Ef65UDb2HdfTWh4Na++ZJe9I+PSPFdN4Na5fOl jksmXR0ZIKiHbdrU5PAxsI40eAbvzE9IncMG5z5xLb0+7+jb2WgS2QzskQE1zmK152So wryozk/yBD+78itrEhDfx5Z77anfRxKFK8Jks1panOUQj9CzQtM+Wqf6faWrj5dRWRrF UsQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708148217; x=1708753017; 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=lCLVx9kxWQaFnG1OpMOPtJ5A7Khl6+OxNkxfvJDWGlc=; b=FO3QXNG7s/rQ+E8UTTwmvosBPg4pbjYq9+r3XI/viOkgsEGT+mlpAQkrJ4vwGztJbZ e+EEo4l+HxvdMFlhleXeRQjRXEpcH1FI9AnYdvkBEiWNHtM640kd454AyXSidx3CKqPr Ks9sRXyyrUvNHb9QDkj+8bUpSX00ZvqhYu1FY2j0DF2Vt61POb3c+qc9TS0rGVmcJH+Y +X34nbTbds3YCyaVhSnkEgemTbcbLkColS/sNvWvmedbQS7t4w04pMy1UkaM1CDhNiKZ PfnhaObSsD3C9fJEn4X89+OGal4PBcOP9cwZ2V8HG6uH2mxiGN5Y6ySrlMnzhQOBYeTL zb7w== X-Forwarded-Encrypted: i=1; AJvYcCXXsfAiK8xEoz4kKZX4NUoU3a1Lgaqtg/qLeHrNn19/O7Mb35MuoNeSoK9DR/OU+qVeIBmNA7t8swIvCZ+M8/5X7ik= X-Gm-Message-State: AOJu0YzY/e7AnoDlEQNGIFYHgYt32/ljiG0rjuyDHKKQKAhhdtJEIAvW VHpbMs53daBfic2PNmTv+/h/5dxgDTA4SoHX0Xx8ITaIaPPZPnp/ X-Google-Smtp-Source: AGHT+IH5+jSNUQZJD7pveaLpbnf27JozpiZW+iIpVps6y29SNJKVQ4jrWmBgLkB5IZKAir6i+qLx2g== X-Received: by 2002:a17:902:ea0d:b0:1d9:5f11:d018 with SMTP id s13-20020a170902ea0d00b001d95f11d018mr8459194plg.1.1708148216595; Fri, 16 Feb 2024 21:36:56 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:e82e:22f2:1bdb:989f]) by smtp.gmail.com with ESMTPSA id w3-20020a170903310300b001db3d365082sm694251plc.265.2024.02.16.21.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 21:36:56 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, hannes@cmpxchg.org, linux-mm@kvack.org Cc: nphamcs@gmail.com, zhouchengming@bytedance.com, senozhatsky@chromium.org, linux-kernel@vger.kernel.org, Barry Song Subject: [PATCH v2] mm: zswap: increase reject_compress_poor but not reject_compress_fail if compression returns ENOSPC Date: Sat, 17 Feb 2024 18:36:42 +1300 Message-Id: <20240217053642.79558-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: E7B5640002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ixmw489zjdfxd8oce3ip99sgzt5rxfax X-HE-Tag: 1708148217-654358 X-HE-Meta: U2FsdGVkX1+3EJFKZjrDFx/rN4r6JK05f3eBbmn3QAnWenRqxP8LDj9tL/NFwPVjd35+72yB7wjw7FbnpfnvB1R2m4TOW9CyoSTNJvtWNm8otHiQnaD53IhFTBkYT3gzdlBswYDXRdHq4bH0EcavmdTJBSFbdoBVuefVQkMpcgKMPlWtSvEH0pEVTVDppJj/6tFX62iY9faFsOXK9ZVq0XH3Sw1qVxojqWTEr3X/LCSLk9N9vD+05iAPMFepT7O3F9mQbPlfMryEMWJxB23ufSPJ1lZivZpDs9HoFtFlfRSjUh7uhpM/ocYH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Y1XAcv5VNmxqYDkmgVDsWeiKPqkJQvWKWIexgHq2ZRDiXCtpe4o8Wv5s3kG1osvmRHyP3wLE+gQGTIYD5BzvDsKItHb0ZLA0DM643d+PWgatNBi0S8sPbfri0WLp/wWgLDZJOwXl7ljcVWOEg6jHNySHzs5NDgLI9sQejdA0KQEM8nWuhPgbAo6frjPoEpHpb02ENPI59V1OMCdjlI8H8ZKuQBpMNzF2CoRt8ekLC/Dc/GlYKTy2lJNghACWWkL/tErmKvt2KY/oFkC7k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Barry Song We used to rely on the returned -ENOSPC of zpool_malloc() to increase reject_compress_poor. But the code wouldn't get to there after commit 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") as the new code will goto out immediately after the special compression case happens. So there might be no longer a chance to execute zpool_malloc now. We are incorrectly increasing zswap_reject_compress_fail instead. Thus, we need to fix the counters handling right after compressions return ENOSPC. This patch also centralizes the counters handling for all of compress_poor, compress_fail and alloc_fail. Fixes: 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") Cc: Chengming Zhou Cc: Nhat Pham Cc: Sergey Senozhatsky Signed-off-by: Barry Song Reviewed-by: Nhat Pham Acked-by: Yosry Ahmed Reviewed-by: Chengming Zhou --- -v2: * correct the fixes target according to Yosry, Chengming, Nhat's comments; * centralize the counters handling according to Yosry's comment mm/zswap.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 350dd2fc8159..47cf07d56362 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1498,6 +1498,7 @@ bool zswap_store(struct folio *folio) struct zswap_tree *tree = zswap_trees[type]; struct zswap_entry *entry, *dupentry; struct scatterlist input, output; + int comp_ret = 0, alloc_ret = 0; struct crypto_acomp_ctx *acomp_ctx; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; @@ -1508,7 +1509,6 @@ bool zswap_store(struct folio *folio) char *buf; u8 *src, *dst; gfp_t gfp; - int ret; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1621,28 +1621,20 @@ bool zswap_store(struct folio *folio) * but in different threads running on different cpu, we have different * acomp instance, so multiple threads can do (de)compression in parallel. */ - ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait); + comp_ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait); dlen = acomp_ctx->req->dlen; - if (ret) { - zswap_reject_compress_fail++; + if (comp_ret) goto put_dstmem; - } /* store */ zpool = zswap_find_zpool(entry); gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; if (zpool_malloc_support_movable(zpool)) gfp |= __GFP_HIGHMEM | __GFP_MOVABLE; - ret = zpool_malloc(zpool, dlen, gfp, &handle); - if (ret == -ENOSPC) { - zswap_reject_compress_poor++; - goto put_dstmem; - } - if (ret) { - zswap_reject_alloc_fail++; + alloc_ret = zpool_malloc(zpool, dlen, gfp, &handle); + if (alloc_ret) goto put_dstmem; - } buf = zpool_map_handle(zpool, handle, ZPOOL_MM_WO); memcpy(buf, dst, dlen); zpool_unmap_handle(zpool, handle); @@ -1689,6 +1681,13 @@ bool zswap_store(struct folio *folio) return true; put_dstmem: + if (comp_ret == -ENOSPC || alloc_ret == -ENOSPC) + zswap_reject_compress_poor++; + else if (comp_ret) + zswap_reject_compress_fail++; + else if (alloc_ret) + zswap_reject_alloc_fail++; + mutex_unlock(&acomp_ctx->mutex); put_pool: zswap_pool_put(entry->pool);