From patchwork Mon Feb 19 21:19:35 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: 13563110 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 E259AC48BC3 for ; Mon, 19 Feb 2024 21:20:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 131BB6B0071; Mon, 19 Feb 2024 16:20:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E2226B0072; Mon, 19 Feb 2024 16:20:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC49F6B0074; Mon, 19 Feb 2024 16:20:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D759A6B0071 for ; Mon, 19 Feb 2024 16:20:04 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7C9B4404C0 for ; Mon, 19 Feb 2024 21:20:04 +0000 (UTC) X-FDA: 81809821128.16.862A0FA Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf26.hostedemail.com (Postfix) with ESMTP id 97DB114001B for ; Mon, 19 Feb 2024 21:20:02 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QBvc9fC1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.181 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=1708377602; 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=wxEqpQi/TVfPO8koWPr1g27ez4NagydW/9mU4Hd8GmM=; b=sbeGhgA7QTTzwFjpt7x6e/C74ccjonBxSfeht/anOf55Xgnzt0UbSYnV33HLJdTPdJ0ECl TqUi/SrjXDTMSgX0db9E7jebh6yAybQz1p3nF0j/0sMDFu8WTo1uPbEA9ZTs3iXX/2ijeo GlevzXHxg5SVjCgSmzVFnheSEfVHmkk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QBvc9fC1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708377602; a=rsa-sha256; cv=none; b=cmysmp/0PzJRn8fuwroqmR1HHtJjGUvVSCO2zAV6KJOldB+MhZbNej1qnAF8qdW3WT6JG+ uG5HWJ2HLZPDrJDUUBpdfUWg8RuIhJfP7eXsTRsstJmBVOf7Tf2BzgqUD6k6Fm3DEWJCh5 I/nY5OBMuM4DL46/rzAiny8rZPvmEv0= Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-5ce9555d42eso3710621a12.2 for ; Mon, 19 Feb 2024 13:20:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708377601; x=1708982401; 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=wxEqpQi/TVfPO8koWPr1g27ez4NagydW/9mU4Hd8GmM=; b=QBvc9fC1FpJBRipO49UvCdK5Lwbip/QWB5CYz5YwuivaP9FKoOypPdO1MDyMeou06O TsJ3gMG9s9CJKQ6K2kt+/TNvouKQb/+M/K4QJJqQtR2/+dEOtGYJL4o06F4qsZ9NS8Dm 4zSKriOtiqf9jVsiq7zoFLzaZw85AS7Iu2olMiFnslboQnHWFG31KLQIsPNi5UjZ1Fnw Zhqd5X6nPHq4FFkQ6pPhKrMJjfqKgJcgdwSNRpMJIsudzVNKj8HZkKWOdYezL9TDEUxu pVfJwuEOPNZpW0j+7uluig6YktF11XhPiSkewaEeot2zF8m2s7w0bofl4kpyaOnSQxgc 3ibQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708377601; x=1708982401; 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=wxEqpQi/TVfPO8koWPr1g27ez4NagydW/9mU4Hd8GmM=; b=E+trdd++yP1qmg4qUcsJjY/1Vx0hQmOFb7dgg5mjJLfSnQEdCVfdlVzTiZh3afrfIM TC7NMkRp1RAenSsjLYLY5db/8OnHI18uZ/vMGJVdCuj6PHRQK2/RRedFB+KhrxpyeVgv 5G0DxBbuRwxwpx6VcKJrchppAvqzV0cioJ7TXV2jewJ3vBeNfjdIozr1G5Wdg8gnfcJ0 ctARVT6Wl4M945vTxtNBQ7lXr0C3qCALVWW7k/ZswzFSkhpRDpkSTDnn5O7UXDfbgdvO Pv/QplX3gGxKgYd/x64zUCHP+fgPYVwEHpsyH5FtHHqd3zHPKrMSfVCfoXdg0T9XM3lg BRQg== X-Forwarded-Encrypted: i=1; AJvYcCX0Xg+RBn5DYei8V2lA47XvjLoaifkVNgHorXC/aKxEnQLltJNzjOUdRUgZCMccidicWsrZb/J31JoCGIoRQdzUSYg= X-Gm-Message-State: AOJu0Yyhq/ncjG8euur+TyqBdtDRP9wJMPtKz/sJdh3dy3vxko4cy+Ws we13Ena9fRZg/ZO+JuFc35VikV/q2Lrp5unIergQGVmJCXboGl+z X-Google-Smtp-Source: AGHT+IG0ivqZcyUbHYdBD0UEK+njjVj6pKBuqsBlmG/eq0/vJGhEObBt2x788f5FBxVjAaZoCKNIuA== X-Received: by 2002:a17:902:ec90:b0:1db:c564:5938 with SMTP id x16-20020a170902ec9000b001dbc5645938mr10379108plg.60.1708377601099; Mon, 19 Feb 2024 13:20:01 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:dd49:f5c6:f613:4a7e]) by smtp.gmail.com with ESMTPSA id p3-20020a170902c70300b001d92a2b258esm4834386plp.118.2024.02.19.13.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 13:20:00 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, hannes@cmpxchg.org, linux-mm@kvack.org, nphamcs@gmail.com, senozhatsky@chromium.org, zhouchengming@bytedance.com, yosryahmed@google.com Cc: linux-kernel@vger.kernel.org, v-songbaohua@oppo.com Subject: [PATCH v3] mm: zswap: increase reject_compress_poor but not reject_compress_fail if compression returns ENOSPC Date: Tue, 20 Feb 2024 10:19:35 +1300 Message-Id: <20240219211935.72394-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 97DB114001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: wyg1w3qtj5qpq4zb8jewsfcooy8e7cop X-HE-Tag: 1708377602-469670 X-HE-Meta: U2FsdGVkX1+bsVsFTl0uSn+9c/9rRn/ztObcCDBGOx7pqiSppI+IfnCBbjYp+tnodUvhVGIZN2326Spq9j2s9cIHDGD9kSEfDqk23DxA+sQUTsAjmypWwATk+vLcLASGfuBIA3GQ63JE6NqNAFK+lW2M24TM3ij1PtWPsgQxddOYHJdFRdWS85OaIp24e7XrS51KFwdsrb95sroxM54CoRTQEEFS58tE2FMIdNBYkPfyDz/zDJbEf3wQ1eo23kEBz97c+1NqrDtNDoL1XjRuyqBrFrGwa3yPo5ztm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9i07a7vGFiC9d3o0m0PZuA4ydRPfy5CLmU/uNI9CDuaKNlZsZynGVlPMpFHvB3gGz3e9Ut/tLP3PNJ/aot86FTtIy9OCC6odD6EuLHhGEKLsCU+CXlHPKSf1x8BEnfQFRAHZaFQP4sW05qKGjbDPQphwXy/vWXWSvMHP3wu4DyB+Pvu4v8AcEJCL5kFwpgUYMp4iQ2p5CZWP37LyLclRvj6dquRXJVDZL++V6miR7GXhuXim3AKozCwV3IsSMxqzXWkxw0q3C31T2mj0JMmIXUB+FS0+ueNrOn1bIBoX6ElgOiJrxnHa4KN4vmqJFIPV+enO3q 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: Sergey Senozhatsky Signed-off-by: Barry Song Reviewed-by: Nhat Pham Acked-by: Yosry Ahmed Reviewed-by: Chengming Zhou --- -v3: * rebase on top of mm-unstable according to Yosry and Andrew * collect review and ack tags of Nhat, Yosry and Chengming, thanks! mm/zswap.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 62fe307521c9..51de79aa8659 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1021,12 +1021,12 @@ static bool zswap_compress(struct folio *folio, struct zswap_entry *entry) { struct crypto_acomp_ctx *acomp_ctx; struct scatterlist input, output; + int comp_ret = 0, alloc_ret = 0; unsigned int dlen = PAGE_SIZE; unsigned long handle; struct zpool *zpool; char *buf; gfp_t gfp; - int ret; u8 *dst; acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); @@ -1057,26 +1057,18 @@ static bool zswap_compress(struct folio *folio, struct zswap_entry *entry) * 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 unlock; - } 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 unlock; - } - if (ret) { - zswap_reject_alloc_fail++; + alloc_ret = zpool_malloc(zpool, dlen, gfp, &handle); + if (alloc_ret) goto unlock; - } buf = zpool_map_handle(zpool, handle, ZPOOL_MM_WO); memcpy(buf, dst, dlen); @@ -1086,8 +1078,15 @@ static bool zswap_compress(struct folio *folio, struct zswap_entry *entry) entry->length = dlen; unlock: + 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); - return ret == 0; + return comp_ret == 0 && alloc_ret == 0; } static void zswap_decompress(struct zswap_entry *entry, struct page *page)