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 10EE8C4332F for ; Thu, 14 Dec 2023 22:02:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8422B6B0562; Thu, 14 Dec 2023 17:02:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F2686B0563; Thu, 14 Dec 2023 17:02:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E1516B0564; Thu, 14 Dec 2023 17:02:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5FADE6B0562 for ; Thu, 14 Dec 2023 17:02:32 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3476D1C14FB for ; Thu, 14 Dec 2023 22:02:32 +0000 (UTC) X-FDA: 81566798544.12.1723230 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf09.hostedemail.com (Postfix) with ESMTP id A165E140006 for ; Thu, 14 Dec 2023 22:02:28 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WnYJWpA9; spf=pass (imf09.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702591349; 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=C+Ukl1C4q56PMFXgAY2rFDxz55Ib83hO1GYH/qExqT4=; b=JQvYbnV0GOOpLOTRBcZH/NVvBN1pfwtvirvQObIWIqMXoXgU65L+eBHy0V7KabMVYtfAQ+ cx0FWfVY5WVMPx1N9ZedWACMcdv7WpYWB7NeIRCQ+G8kjjRoQ1r+9IQQIqZGqwh+K4vnkZ WgSYHQMgY8cgVGFvGc99y0n+1SIxAuY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702591349; a=rsa-sha256; cv=none; b=jRbaSaNFNNuIEijy65nLx/Z+P/0vw17wql7cSrS+z31fKTWjbE9DK7nwvmDEvQBzgDl04Y rONktORcA3YCLG2DOTM4Wc88o46+M6FBEjfbQjWvRQwrdOU+IkGBpVdQiR548dAAuR9vzs XQ+zwxK9f1VVlYOeCME9MAu+svRzd6U= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WnYJWpA9; spf=pass (imf09.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id B8889CE2652 for ; Thu, 14 Dec 2023 22:02:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78323C43395 for ; Thu, 14 Dec 2023 22:02:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702591343; bh=C+Ukl1C4q56PMFXgAY2rFDxz55Ib83hO1GYH/qExqT4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=WnYJWpA9hh4rCdH+ni/v6Gr9i3n6qiWyvZGXLtqUEovTT7wtyHOd6Me/ksvu5YHdd dyvjHatBO75SYk0DFWi/HH/XcdUGeR/FNqRQubprL1EofmWZl0/EapJRlpu2JGbe3z 9hq6OAqd9l0A6+XKBtEiK1tdOV5sQrYuV206qtmIG/P3CEOHyCqLoH7M2G2TZBNxof ufCbBGWb3SqbQYcQ0lVdYQ+v2Uzh+RTIS2+QTYwZZVd0J29YMv80XQs85ZLN/K8AFx fHqgrX9gTW0CQ2mMj6q+JAz0JW351VBq5EwjtQN4CZbYNQ/cEGFnmj6vD+BL6BS+dI 81/TTfz91MKLA== Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-28b06be7cf6so939413a91.2 for ; Thu, 14 Dec 2023 14:02:23 -0800 (PST) X-Gm-Message-State: AOJu0YytnYfB+dEZ6lhA4rz5g00BUV49Zj5D8OErUkfOKowki66R2Aan Z3ucHOECAXof6TPMAHwyg3r/ZAdnSNLIooKxouV9BA== X-Google-Smtp-Source: AGHT+IFgwY4ydcxX5SA5ZcLLxVd0G9cVRGEidy3qgrOv1NVhFhLl8ZPDgihzMEajEZYQ5SOQAvnCuSzK9qNdIFU1lp4= X-Received: by 2002:a17:90a:ba8b:b0:28a:c74b:25a with SMTP id t11-20020a17090aba8b00b0028ac74b025amr2721462pjr.20.1702591342758; Thu, 14 Dec 2023 14:02:22 -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: From: Chris Li Date: Thu, 14 Dec 2023 14:02:11 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/5] mm/zswap: reuse dstmem when decompress To: Yosry Ahmed Cc: Chengming Zhou , Andrew Morton , Nhat Pham , 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-Stat-Signature: ijr6wdoiqzx7xnanqxff3cjfcazu98jh X-Rspamd-Server: rspam10 X-Rspamd-Queue-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IIx/lvr/6jP0ewjcq0YIPkJPa32RLfWFH5LlgqmkL13K5UGtVI41eZmXTgBTxMUS3GWye/vNaUJ4u82VVDU8EVxAyPoKPnuhC+OPxiAuFSyipSgNXPk0csbguuro8LoPsPAyxeTTgs3wu+l2Iblt0uDXM7tnCoUu7zpXy+jHlsP3iLDrV/pTYXVepAmKUB5Mw1sBz0jgnalrceHKarUhZXJDEMyVcxzo5C8+ZC0WqggTyfwrrSUpZuJ6N44swOGH9sC7OUlywKHuj1v1mWC7KVIbewbxcDPHuX1L45kObh0XYDRpZP2 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: Hi Yosry, On Thu, Dec 14, 2023 at 10:27=E2=80=AFAM Yosry Ahmed wrote: > > On Thu, Dec 14, 2023 at 9:59=E2=80=AFAM Chris Li wrot= e: > > > > 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 fi= rst > > > copy the entry->handle memory to a temporary memory, which is allocat= ed > > > using kmalloc. > > > > > > Obviously we can reuse the per-compressor dstmem to avoid allocating > > > every time, since it's percpu-compressor and protected in mutex. > > > > You are trading more memory for faster speed. > > Per-cpu data structure does not come free. It is expensive in terms of > > memory on a big server with a lot of CPU. Think more than a few > > hundred CPU. On the big servers, we might want to disable this > > optimization to save a few MB RAM, depending on the gain of this > > optimization. > > Do we have any benchmark suggesting how much CPU overhead or latency > > this per-CPU page buys us, compared to using kmalloc? > > IIUC we are not creating any new percpu data structures here. We are > reusing existing percpu buffers used in the store path to compress > into. Now we also use them in the load path if we need a temporary > buffer to decompress into if the zpool backend does not support > sleeping while the memory is mapped. That sounds like pure win then. Thanks for explaining it. Hi Nahn, > I think Chengming is re-using an existing per-CPU buffer for this > purpose. IIUC, it was previously only used for compression > (zswap_store) - Chengming is leveraging it for decompression (load and > writeback) too with this patch. This sounds fine to me tbh, because > both directions have to hold the mutex anyway, so that buffer is > locked out - might as well use it. Agree. Acked-by: Chris Li > > We're doing a bit more work in the mutex section (memcpy and handle > (un)mapping) - but seems fine to me tbh. Thanks for the heads up. Chris