From mboxrd@z Thu Jan 1 00:00:00 1970 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 5F2F5C48260 for ; Fri, 16 Feb 2024 09:07:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D935D8D0014; Fri, 16 Feb 2024 04:07:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1CE78D0013; Fri, 16 Feb 2024 04:07:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBDF48D0014; Fri, 16 Feb 2024 04:07:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AA3A58D0013 for ; Fri, 16 Feb 2024 04:07:25 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 76AAE80369 for ; Fri, 16 Feb 2024 09:07:25 +0000 (UTC) X-FDA: 81797088450.07.B1BA82F Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf25.hostedemail.com (Postfix) with ESMTP id 9D7FBA000A for ; Fri, 16 Feb 2024 09:07:22 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="kq/JeY/4"; spf=pass (imf25.hostedemail.com: domain of zhouchengming@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zhouchengming@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708074443; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=te7LBuSkGpNERcPih/GmGHlalGkBFMiZ+Ca0upEKLOg=; b=hzFTNPIyo/6O7Rf18Mnst4AAp5Bxbdi+JOlb0KzjXH2jZ1iLAJWHih2FVI0g3Pb6nMrs7r 3EzLTdzT7a7OocLdg9aNfa/ilmjUi+Cc2t/ok9i8kyIh27of6wHACcgI4OeyPN7LnngVVk x+VGE4H/KT+aVVsDFz9M6OUhnt5XKkk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708074443; a=rsa-sha256; cv=none; b=4x/XxRkwSdPhH06NhRV9ersN0s2JHQTL2cAFMU1aRh1tSlmz9UBmrLRSoqqJyk5BP6Vjel 8NR8unrqAFKnkypi55Mjx/GqX9gZ2zuRHfeg1a/xwSmAWemNFO+jaxEDxSN42kUqPbDvJu /MfxYVLvKVlrL0+Bx4BT/4g02zqiq9Y= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="kq/JeY/4"; spf=pass (imf25.hostedemail.com: domain of zhouchengming@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zhouchengming@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e104a8e3f7so1474401b3a.1 for ; Fri, 16 Feb 2024 01:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1708074441; x=1708679241; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=te7LBuSkGpNERcPih/GmGHlalGkBFMiZ+Ca0upEKLOg=; b=kq/JeY/4LkzN4jSqHUV/aynmoazDWaVFMdrJLdq0Afj9ZBjs9z+EMN25QxCV/WD7Dk nHCXkyq6lY1+alNTfBsklIj7xSGqwk0trVO3SNk6QbiO+qjZDoase9ZHDBA4HyLwuyZv zb+tgNCRh53dWaYWBysGiudv7hTVPXlelgzJHP83Rl+N6Z1kBDrxFyu/COXI+4s9tRjW QtMatgY76B0bLiEDceQzhrqH0jIYHaFcI7Z8GQVl9P77EbXKJxC9p0iJYgcZOiL2izmB 4D9LuMjh8iJulWRRbIhrEoqdvj0KZODamRgdB7GzsGwE0En2F79Rvv9OLXCZDplJtjrM VEaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708074441; x=1708679241; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=te7LBuSkGpNERcPih/GmGHlalGkBFMiZ+Ca0upEKLOg=; b=krPMuHejSICo5J+rDyCcmpRP6MG9VyckP4K7cNyrb+TqpHYfHr+d/N+eJtmaD4BpXR gN5q+Ifbfk3qhpA4Qf7zy/rklC2YE/x8WUZDFskHgUu5p/P50uwgDGY9sGOPFjycouGR 1nAmupj3OZqdzBGPFMF54kcmMBdKVhBtorxLqFU+H8PxVVhp52eo/rSt+u1GdqFEVHaI 1XgqE/UJTf9Cf+DvDLp/7SSqDC3ZxCQ9qFQEJEC8YjGTjkxKwNxNVDVingCQ6swKSY1G qYK2DPR7WNHfol8dthAylS6CIwYihyV1kLicgUZl7YtxiTcJ80ID6YWgErDwZv2lpzhm edBQ== X-Forwarded-Encrypted: i=1; AJvYcCXyFwcGqIjck7bd/Lp95KrG7MDrDjCS2t56qtwX6xFTMDg7T3G2JjQvfrMayPE8Ghdp/54hV9Hnf9A9DOHUKvIaqQA= X-Gm-Message-State: AOJu0YzfGWIcYIBq93CgQpLbl09Svcu66Fi9zVLu5gRfJLnfqXJlLEuc CFm4vLU9rq7tVMAk7ODzZTE7FXd8fDQJUYf7rgQ07Alz5zZc65NGZl68ympS02Q= X-Google-Smtp-Source: AGHT+IEF8CmYpemNqYgmMWaNlK1GOcey+10tFseNDFQ4cxYUp7hRe0oHLGS1E4wBIAu0sncoXGA6Yw== X-Received: by 2002:aa7:85c3:0:b0:6e0:4ed0:7b38 with SMTP id z3-20020aa785c3000000b006e04ed07b38mr3957056pfn.4.1708074441275; Fri, 16 Feb 2024 01:07:21 -0800 (PST) Received: from [10.4.195.175] ([139.177.225.229]) by smtp.gmail.com with ESMTPSA id x10-20020a056a000bca00b006ddc03c425bsm2628098pfu.180.2024.02.16.01.07.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Feb 2024 01:07:20 -0800 (PST) Message-ID: Date: Fri, 16 Feb 2024 17:07:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: zswap: increase reject_compress_poor but not reject_compress_fail if compression returns ENOSPC Content-Language: en-US To: Yosry Ahmed , Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Nhat Pham , Sergey Senozhatsky References: <20240216030539.110404-1-21cnbao@gmail.com> From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: uphfpzkbhchuz3ox7d4f97ybuwwthxza X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9D7FBA000A X-Rspam-User: X-HE-Tag: 1708074442-373965 X-HE-Meta: U2FsdGVkX1+Q5j+goLC2fRBCbnP0AtA4GwYI/VF1snM9qr60bif1x4CSf4GWNfu1dlAOOp0aHcWhr1/F48gSYuEOKqnc62eXycxUmS92A744mtsfHxvw9rVSo4Hiu+YMCOpAqmfoqUUc9q2pedNhcG447LkkmbL+oH3m+8+EDBJ9ZRbvr/r2E2G0GR12vKyVXA4WLaF22ubOvjt3YyQgvciPT5OgDHesgHRGlDCbcMmjZpUORAhq7EtVVVJr8Qq8KaFp7pWjO8SJkq9hgdjB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Dcoaj1UvTh/OUiR8KJpUZWNZ7R17HwGUnNJeE9B2rQuthBfQNNM71qLFXVmZRy/J4cnEaMexNw2NNTv+nEQF/MOoA7KfE6ZoZWH1NpRrHAgFOghALqJOlbPiFw3PVsUUEQXlj3kfAas0g3aAz45u5DJijw2QmaLiDqLhMkdz3l+4RgA6PSj9SnVk/yskrb7TT1jYEzGRkufoEP6VEyP3H5wfv6XawVVkKHRpHq4vNh7XDPYv0B0ul+r5zpieeNmYstA5oYwCwRTy7znh5Dw/U+nEszeRLi7ONSwhL5vg0qD4f02TnlyhXAq/aUmVg4/Qv451A== 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: On 2024/2/16 16:23, Yosry Ahmed wrote: > On Fri, Feb 16, 2024 at 04:05:39PM +1300, Barry Song wrote: >> From: Barry Song >> >> My commit fc8580edbaa6 ("mm: zsmalloc: return -ENOSPC rather than -EINVAL >> in zs_malloc while size is too large") wanted to depend on zs_malloc's >> returned ENOSPC to distinguish the case that compressed data is larger >> than the original data from normal compression cases. The commit, for >> sure, was correct and worked as expected but the code wouldn't run to >> there after commit 744e1885922a ("crypto: scomp - fix req->dst buffer >> overflow") as Chengming's this patch makes zswap_store() goto out >> immediately after the special compression case happens. So there is >> no chance to execute zs_malloc() now. We need to fix the count right >> after compressions return ENOSPC. >> >> Fixes: fc8580edbaa6 ("mm: zsmalloc: return -ENOSPC rather than -EINVAL in zs_malloc while size is too large") > > I don't see how this is a fix for that commit. Commit fc8580edbaa6 made > sure zsmalloc returns a correct errno when the compressed size is too > large. The fact that zswap stores were failing before calling into > zsmalloc and not reporting the error correctly in debug counters is not > that commits fault. > > I think the proper fixes should be 744e1885922a if it introduced the > first scenario where -ENOSPC can be returned from scomp without handling > it properly in zswap. If -ENOSPC was a possible return value before > that, then it should be cb61dad80fdc ("zswap: export compression failure > stats"), where the counter was introduced. Right, 744e1885922a maybe a better fixes target. > >> Cc: Chengming Zhou >> Cc: Nhat Pham >> Cc: Sergey Senozhatsky >> Signed-off-by: Barry Song >> --- >> mm/zswap.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/mm/zswap.c b/mm/zswap.c >> index 6319d2281020..9a21dbe8c056 100644 >> --- a/mm/zswap.c >> +++ b/mm/zswap.c >> @@ -1627,7 +1627,10 @@ bool zswap_store(struct folio *folio) >> dlen = acomp_ctx->req->dlen; >> >> if (ret) { >> - zswap_reject_compress_fail++; >> + if (ret == -ENOSPC) >> + zswap_reject_compress_poor++; >> + else >> + zswap_reject_compress_fail++; > > With this diff, we have four locations in zswap_store() where we > increment zswap_reject_compress_{poor/fail}. > > How about the following instead?A > > diff --git a/mm/zswap.c b/mm/zswap.c > index 62fe307521c93..3a7e8ba7f6116 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1059,24 +1059,16 @@ static bool zswap_compress(struct folio *folio, struct zswap_entry *entry) > */ > 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 (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++; > + if (ret) > goto unlock; > - } > > buf = zpool_map_handle(zpool, handle, ZPOOL_MM_WO); > memcpy(buf, dst, dlen); > @@ -1086,6 +1078,10 @@ static bool zswap_compress(struct folio *folio, struct zswap_entry *entry) > entry->length = dlen; > > unlock: > + if (ret == -ENOSPC) > + zswap_reject_compress_poor++; > + else if (ret) > + zswap_reject_alloc_fail++; Here have two cases: zswap_reject_compress_fail, zswap_reject_alloc_fail. > mutex_unlock(&acomp_ctx->mutex); > return ret == 0; > } > >> goto put_dstmem; >> } >> >> -- >> 2.34.1 >>