Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5648729rdb; Wed, 13 Dec 2023 15:25:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTmtnG1os72uzY9ypao4qNfZf2G0Tebpp1MSeKjU/1NJGT59s+W1yfF/HiZy6qhYWqo9DU X-Received: by 2002:a17:903:11c7:b0:1d2:ec56:eab8 with SMTP id q7-20020a17090311c700b001d2ec56eab8mr12705175plh.44.1702509908164; Wed, 13 Dec 2023 15:25:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702509908; cv=none; d=google.com; s=arc-20160816; b=Gmrb9cGh6SBsGkhmETn1bnthamzjEpcs7MQxw7dGCm1HP1fYEvVzwnbOBia1+GueEb 8DCSRzI4rF6GyZtMvLDF+6HjgwEiPdbZORq22zvYJvUv9mfPeARXlgDu83udHPM3ciRg dTZ+128Z3Fc/ADAvagKHr/JVhePGribSRkFBkNXSaC64QTEE1XOODWr2ePh0P1B7/2Je 9e+lKau3QWG0RzhEelEyEhXMjmpR8J5JtY8jeti51I7Icmlk6VGKqOSZdv8zlKMfy8NO QTTlCix3ufSDuLtw5Y5fcuI7/2CfAwtRL5sW9XuV26uqsa96RCXCPs+2gs9GmXA6mfxF HV6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pFEmwUcK7ari3l1HAYNZ+QAFaZZrXeQEzXKeC4yMuRw=; fh=CIEK4oU1VpeGYez8Kqg5XgL7oVBF13djoAg0dYB/DRs=; b=O0ZCWToALNBSqlPDDXLi7RusX5i3cQwfz40IM28sBVp4yef7ZaiBnSsSzfdqqTIAPc 1BgBC+Z1Cg8m129kSt99rzFixgxTCny2PJiiZ3Fh7Gq14qhwNZzilyYn5UEz2jdkcmSA 1D0eKpFGiOrJUDdyz9ct5pi7H3iGdNO49aRaRMBBD6985SKfb1Pef5ScuHFjyFAkpdhZ 65ZwUeptiNpxWwsKgMjsDAcq9IdiiOPVVOCBZ7MBO6O03VsyCr6a2yw2Ifn6xi3Z/RTi bDe/YxwT4Ph1abvFNlc1E3+AvsumLIaCirToXzp3xy9YITSENLc1BLik2uYYJiDiflwZ w16Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=p67Dgqqs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id e2-20020a17090301c200b001d347f9532asi1495913plh.187.2023.12.13.15.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 15:25:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=p67Dgqqs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E158180C2553; Wed, 13 Dec 2023 15:25:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbjLMXYv (ORCPT + 99 others); Wed, 13 Dec 2023 18:24:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjLMXYu (ORCPT ); Wed, 13 Dec 2023 18:24:50 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4F37E3 for ; Wed, 13 Dec 2023 15:24:56 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a1ec87a7631so670748366b.0 for ; Wed, 13 Dec 2023 15:24:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702509895; x=1703114695; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pFEmwUcK7ari3l1HAYNZ+QAFaZZrXeQEzXKeC4yMuRw=; b=p67Dgqqsa+zo3k4YSYAMwwxXURoveV/FCvOzakUOwIJlxyyB/N3M3K65xVEdmgvX2/ uTVwnFygeSEk9cX7L62k3UMDHs2IN4TZgoDpgdTFliEAEVGGeMUf48viX7I1uZnSKlOq vD7K9hqpr26sGas6ADgIR+MOd9S1HzYySFun2CmdR4deNZ3i/r6qB0+XyKwlv3dJPRlH FHiEkxhnoa7ZzwOZR33YlwCBDDuKLAuh+ADW3HHCPn+elgWE+OfiqBodi7LpdU5cI6nW YnvJAc8IK1AD6tEAlTHGoajjwcb1KX6A6DALTJjNyOrUYVq+IwGh4j9YJFPWcSkbRcEq aceA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702509895; x=1703114695; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pFEmwUcK7ari3l1HAYNZ+QAFaZZrXeQEzXKeC4yMuRw=; b=EdT0kxYXGb/KBohF/S5bLRBS19+LXuAIl0X2WQrHg48K6ftFu2qzOXCtTMPANwaZR9 zM+2EDthZ3nEDMG06MozMA6/5gEdpOUGplWUzFn/bnchXN2DOyYy1wHs3qIhLCRxAviJ 8zlM4nUtXOOLMi6KphCWn36MigteiYoeXpx0AoRQzPPVEMdYkuRbOuC/2ov7LpA9Lf2e pu1vol18J+NQSyE6ZLRz3qVMhm5WWegdyASIiHpCUvDHmR7q5yu2erFfmQ8n9THsV/B4 bua76IIdyKGIQZ/UdA0ign0Xn6LVt5r/On/DNhOkU8VTzV8sclJfxXDmL15eAwa2kVRW 22fw== X-Gm-Message-State: AOJu0Yzf2VZCoqdlGw3Zz5S2J4reDNbdnZrqZkbEFShsxImZ5pGUTwUs Libb1oIcUgtcu7W6hvysjyyqfels3Z7JgQ0u5i8Jdg== X-Received: by 2002:a17:906:35ca:b0:a19:29b3:89f4 with SMTP id p10-20020a17090635ca00b00a1929b389f4mr4825392ejb.52.1702509895189; Wed, 13 Dec 2023 15:24:55 -0800 (PST) MIME-Version: 1.0 References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> <20231213-zswap-dstmem-v1-1-896763369d04@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v1-1-896763369d04@bytedance.com> From: Yosry Ahmed Date: Wed, 13 Dec 2023 15:24:17 -0800 Message-ID: Subject: Re: [PATCH 1/5] mm/zswap: reuse dstmem when decompress To: Chengming Zhou Cc: Andrew Morton , Nhat Pham , Chris Li , Johannes Weiner , Seth Jennings , Dan Streetman , Vitaly Wool , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 13 Dec 2023 15:25:06 -0800 (PST) On Tue, Dec 12, 2023 at 8:18=E2=80=AFPM Chengming Zhou wrote: > > In the !zpool_can_sleep_mapped() case such as zsmalloc, we need to first > copy the entry->handle memory to a temporary memory, which is allocated > using kmalloc. > > Obviously we can reuse the per-compressor dstmem to avoid allocating > every time, since it's percpu-compressor and protected in mutex. > > Signed-off-by: Chengming Zhou > Reviewed-by: Nhat Pham > --- > mm/zswap.c | 29 +++++++++-------------------- > 1 file changed, 9 insertions(+), 20 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 7ee54a3d8281..edb8b45ed5a1 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1772,9 +1772,9 @@ bool zswap_load(struct folio *folio) > struct zswap_entry *entry; > struct scatterlist input, output; > struct crypto_acomp_ctx *acomp_ctx; > - u8 *src, *dst, *tmp; > + unsigned int dlen =3D PAGE_SIZE; > + u8 *src, *dst; > struct zpool *zpool; > - unsigned int dlen; > bool ret; > > VM_WARN_ON_ONCE(!folio_test_locked(folio)); > @@ -1796,27 +1796,18 @@ bool zswap_load(struct folio *folio) > goto stats; > } > > - zpool =3D zswap_find_zpool(entry); > - if (!zpool_can_sleep_mapped(zpool)) { > - tmp =3D kmalloc(entry->length, GFP_KERNEL); > - if (!tmp) { > - ret =3D false; > - goto freeentry; > - } > - } > - > /* decompress */ > - dlen =3D PAGE_SIZE; > - src =3D zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); > + acomp_ctx =3D raw_cpu_ptr(entry->pool->acomp_ctx); > + mutex_lock(acomp_ctx->mutex); > > + zpool =3D zswap_find_zpool(entry); > + src =3D zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); > if (!zpool_can_sleep_mapped(zpool)) { > - memcpy(tmp, src, entry->length); > - src =3D tmp; > + memcpy(acomp_ctx->dstmem, src, entry->length); > + src =3D acomp_ctx->dstmem; I don't like that we are now using acomp_ctx->dstmem and acomp_ctx->mutex now for purposes other than what the naming suggests. How about removing these two fields from acomp_ctx, and directly using zswap_dstmem and zswap_mutex in both the load and store paths, rename them, and add proper comments above their definitions that they are for generic percpu buffering on the load and store paths?