Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1372994rdb; Mon, 19 Feb 2024 13:21:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWWs9fumYzPb4On5KOzYRsE6QQCQTLeqB6oFltdmfx7Orhd2cdqRdH5piBMwOYeVUT3KGoCboidCq37ZAoEyylgAuEUvQTLDC0yqxnBXg== X-Google-Smtp-Source: AGHT+IGNFT+qn+isep+PIVsJpiZLed6fyCJ+fhv9B9sxHrR3maPmJ3MAQEC5j7L/S4tavA8a0mis X-Received: by 2002:a05:620a:1d96:b0:787:763a:8eda with SMTP id pj22-20020a05620a1d9600b00787763a8edamr307291qkn.15.1708377668557; Mon, 19 Feb 2024 13:21:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708377668; cv=pass; d=google.com; s=arc-20160816; b=RCXGvagp0BWG/cXt7KIcpXn4Wp9DZp++J2vmCEe4J8urwjehfJ+5Pgo7UVKS4anDBe On70ooAPdI1sNWcb+L+dgR3mscciIeZFI/DAoi1PQzE7K9e6oy/Q/JOaHIuOwvquwcy1 tLxYN9paRg/3TDZxX2loSard/9ZYjzpl10N5Y0ONBa3Mdk+KR8tRUxoaqymysiGRE7Pk GTbn6qlmpyf+rzA/gegf5u08G3hABNhuB81xOhZLF1wDLPD+kDstE7c20dQOwt+hivR9 0u3Hi33EaM+pEHx6hwNPlPl3KIyUNxu62TIttlhhuqiO/nY45rweJgvJq6m0U1sdoOm4 8Ncg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=wxEqpQi/TVfPO8koWPr1g27ez4NagydW/9mU4Hd8GmM=; fh=izByYUJealxW+BAJpWOFDsSd8LBo5TTp1FaSLi6ONdI=; b=QiT0hjltjdNp8GoaquqemsZKQsJc0zDuae42MDD4zbMnGlSxQOHMdqOdDz9/jv1h/o fIBE1/7nrg0fM7PAGbsYmDX9naNDX3pEDgIIBxLcoM0PDLlkLhudkaMAIb8uXCzoBLMD 2ATGJUGM+M4O41xK9Sp33vYFLNmBBTdyu+PQqFqeq8AlRAxkvtJTURr5ijyoW6iH27p2 1YJCd8uRgkiQEQnXlrLNc99o72iQHvZJ1+x9lzq/IMdTI8KtrpJnk8ttMpCOryVtekV6 ekLOot6JTCyjg+RBz5AW2lz/MTNzsbNoBZLeH1A3D8G5soqHXbo4HU5RKAmg37lUajUV 2sLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ei9Rce7K; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-71995-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71995-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p23-20020a05620a057700b0078772129d33si1320173qkp.364.2024.02.19.13.21.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 13:21:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71995-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ei9Rce7K; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-71995-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71995-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 71BD81C2112B for ; Mon, 19 Feb 2024 21:20:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FEB853E18; Mon, 19 Feb 2024 21:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ei9Rce7K" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 364CA53E13 for ; Mon, 19 Feb 2024 21:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708377603; cv=none; b=DBIlNbKgb3vBzR7O/zrhXJ9YFLgGgzMNYt3cC28qOqCZwYNGIvVGX0rfqodn/5McirVqZaa0LTPVTioKpHuNQ6Jl+Hw73FafxO2FT/fHZMd/Z3sujEj3rixafuoR1a7PMcMUyD2lgkNWd8kPqm1DsEeXb68d1g0xCQKYvgk6oX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708377603; c=relaxed/simple; bh=DgQ2fXzVj6rzCYfQy6bc1ZxdYWeW5jg3gg+WwPIZre4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=eS6qgQy/TmL3vXfCkmdteN95+5PZTQMjeurcmUVusT1oKwFlKF0BJscd2Itm1djglAgGHawpbGs0CxmpJVQbJg5t8reD8iv0AjHNKaR6vM2XgDnCQcFM5Gi0D3WxNiGH3lgoJXBsLsQFC4rFKWgqY1FFTe9WME3x6esJBbcv6Bg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ei9Rce7K; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1dc09556599so6708995ad.1 for ; Mon, 19 Feb 2024 13:20:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708377601; x=1708982401; darn=vger.kernel.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=Ei9Rce7K8CXViY5/2RxRPfa0Cn5NnyiARg8cS5geTY6ul+9wSCu0FUbs/pff7DM/ZE vafGqNZ5+jjrFAdI0V6GU2tnK1QzY7wa7uWMt2YkHlJaGXSKxxdHkXRd13sMUV+2dJdy rMmgeqRqkgF7MdryC6DWnoDw4kB50FfB8HWCzK/uIZq3M66GWNzWoUU7WgcIddS/TFQA vDPT7ThC3MvaBqtcbB6nWcFxE9aEgQbl4IHWjOGQLOBJWYUek4jYRZ4orhcTlvYF5H9Q GZmztfTPext9oc7M8/pkaAspRNnz6jIegATjOL4lqBn9Zpm86gd15sUUJjFFOk3Nf17o f2eQ== 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=SPQ0JCvT2tXnGC1w8dWPqsuhFxhM/M3nO1QgOBCuPegkfh0CqzLeg+/p30h06Lwdgg 1CjAHiR+eX2LQbRoJbAxe2awRXRsnAgxEMOZIh9+FfmWI2QIhXdkQBDDaee9+YFLinMu nhU8a1T5mZBzUITPT7y+uE1VIMkWiyAqHgMHFqs7rXD/UPw7LD+Cu+U/6TBS8K2as1Vz 6KMJOqUkdLR92AZvZiokgA6Qq3LYcciaGRYMnFwBaU2DccL2CnojclBasZCYI5QNBQ+K RetW6m58OLVH05z3fJKKqDzYJmnDnO6/sNoyjlJ9q4zqz/BpHamXOrRijVSuQ/brYGuL lKiA== X-Gm-Message-State: AOJu0YyveUJV/THdxgwGYEJK2y+cy4kQX5+lb2ycvIUoPSen+CUMfU0T JH7dOQi57W0LC7vWzdfVQER5ZRDCWovoAtktrtP0FwgXbYnIJc9FpiF0NUoXTi8= 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) -- 2.34.1