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 DCC8CC4828E for ; Fri, 2 Feb 2024 22:37:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56DA96B00BE; Fri, 2 Feb 2024 17:37:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51E096B00C0; Fri, 2 Feb 2024 17:37:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E5CC6B00C1; Fri, 2 Feb 2024 17:37:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2CEC46B00BE for ; Fri, 2 Feb 2024 17:37:25 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E47A4140DF5 for ; Fri, 2 Feb 2024 22:37:24 +0000 (UTC) X-FDA: 81748326408.02.E91EC55 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf14.hostedemail.com (Postfix) with ESMTP id 1FD55100026 for ; Fri, 2 Feb 2024 22:37:22 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JjqcMVvr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706913443; 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=433x/1W6CeaGmua3fRLx6mYR/meu70/H/QyCZc2fg1Q=; b=3dzOPmkBwCn1qk9/V4yAa7sx4mUaJ5PDlPAYuYSoq7Z9qE4XYu5tv/od9wq0xsvBo98fH3 Kkky2Vt9l5ziDiYzVYsWuvYplNj8cD7BMTZij1yDcMbeoTxBP1D1UJBoHiNXCnGi8t7uqD 5dJgfPFmtlfN8Zx3PTv4CD52FyhsPQw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JjqcMVvr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706913443; a=rsa-sha256; cv=none; b=Yi1W5MA4PGjFz0FpdaFVkOi2c1XlGdw5MWZpd+iLsTLG4QTgOTkYalnPZdVT5pVeyp8Yvj 4VzwVLlwBYwDo9eO/u+vPw1+FdZFee7HTbBb0TvYxWrPDTayd6jvrp3Pa7XdyGVi8zbbCT fbs/OsAo3cl7WGmFUcp1hSBGB2eDoSU= Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a34c5ca2537so369140466b.0 for ; Fri, 02 Feb 2024 14:37:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706913442; x=1707518242; darn=kvack.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=433x/1W6CeaGmua3fRLx6mYR/meu70/H/QyCZc2fg1Q=; b=JjqcMVvrJXdpXWVLZ0QEvJDiKJQbT1yxmk2ZAlTZ96eJFZYo8Pw1NvvDsTuqfTv8LJ C+Oz9mDL3vgJR3GbT9Po3PybyIVUDUpYjlYXcDaR1D/zf40Ld/KLlRPSfTz6qEIEjNoj TW8S1cA0jxkaJ6HeHzupo6NYRy9VHx2TO1xK0s+KoszkuhtnMALB+9dvNdy6eVTN12qZ kVuX/qS5/irIxX8EfcjrPdU97d2f0aenk+B/64jh0mlIWjSWWS7jlB3xeC9oaqjMgoDs hzodrWwW4hI855wbG7EplMDKuctLcFam+zeAC7RU1v/2gOLEuNpm7H0nnGvwZ64DG65U vR0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706913442; x=1707518242; 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=433x/1W6CeaGmua3fRLx6mYR/meu70/H/QyCZc2fg1Q=; b=Gy/Dw1WcdWiCViV8a6pTEd0LZX6D9QuMX3Z5U1P5FYXduhOU5LYuyOG80IDYS03ZwT 1xola+5PKlTC930g1NZswqPnsZ0Ag3jb3+zQ+NbMV1+rY5BtYUmPaj3HIS2FxuesJAaT OR93UeDmuOr0kD53mbc2SmaGdprZ/b8BEV6RHAvM6tJlSKBb5DiJ5aRuo96g/SeAIfuC lOoGDa5bTWsiS7JoCLf/DqwGCuFbT/IQ8JovWvwCYBscI8GDq0cPsDG04erTPySIMicL MYyvv0Ork3hdecSkBZbfk3zZA6l6WxUF2SGdSrNGOND8TmE5ZhGg6COoA6gWZKtvx9n0 VwYw== X-Gm-Message-State: AOJu0YwT8YsXQFs2g3V9IHGFUPW67F6hSSk9YHilmadh3j3HO5/ZU9fL 58H8/Q7aqYHsRdkT+oboXILkNQMqp3aCUoQb6hHz/HRoSRZDxcCVB/clq6IqebZrAu0Hv9sqIf0 cZEH9pNNeLcF/8Kwc3CxzBa1XkhNaqED6QLcv X-Google-Smtp-Source: AGHT+IELDNXRuRrhDxrQoHA/yFMI8jmugZCJXcQEnOevp62Y+WrQuSWSiuYHD2pjZhxwVXQPNHswjlGIq2qQ6ir7oQI= X-Received: by 2002:a17:907:7747:b0:a37:5ca:3117 with SMTP id kx7-20020a170907774700b00a3705ca3117mr1944120ejc.11.1706913441542; Fri, 02 Feb 2024 14:37:21 -0800 (PST) MIME-Version: 1.0 References: <20240201-b4-zswap-invalidate-entry-v1-0-56ed496b6e55@bytedance.com> <20240201-b4-zswap-invalidate-entry-v1-6-56ed496b6e55@bytedance.com> In-Reply-To: From: Yosry Ahmed Date: Fri, 2 Feb 2024 14:36:43 -0800 Message-ID: Subject: Re: [PATCH 6/6] mm/zswap: zswap entry doesn't need refcount anymore To: Nhat Pham Cc: Chengming Zhou , Johannes Weiner , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 1FD55100026 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: nydyasqmojhke4krfc3c1kg1uwhsnxxu X-HE-Tag: 1706913442-56032 X-HE-Meta: U2FsdGVkX1/hj3erw1cJHT7R+uSWgSR1if24jAnUlejxj2ehJBsYTS46IdKjgYyEIMEWwI+KVHje4arSMKqdRUFX0Q+9w05Tpz8Z9gbDp6orsntis+v8A2U4nTlbkBJw/pbXBKFA0YrmMaxevEmx6v7QYFOkvYBAbqc/aDVBUCZKJlSlSHM7r3HWjJR1tUzMqqQP9mwlk0IL0KyNBI2OzsxCE3aU8aJXpWEWN2kcOPe7g3cbw2w7is82Jw1NT906HmGtoM7MLvjIY4Ffmg9jL/OsCY74/L4JRAP2TMAA4cgUizoizYW6OZDYhKRse93GpwG35STcc1+f4N5F8MMclV02/an5MSBcUmeQ5kPNxdXYWJy/WDSgThNVFW2t+252mdODGaqdfNziOvEQWgWOTxfRxkQCndV60UTa084WZ8nH4pX8sL/q5bEeYGgv+Xio/K8MmMJrlaXPBaHl1v06bIuaSClJe9Eh9t78quH/kwlBu+Zr6IFcTEewl2tuuCUowIy317+BaJzQvVjMWM/z9Tv/tuT5lCmM2BS0lxTfSLmdXZTWrIon11aXS8zvCZ24DIKn9f58XsKfB/GDpHOUMMWpFCgTxGSpMeNqtptYNzmCwQxBNH9Uthm/HmHwPFKzOdM9M1cf25VRg+sT9o3CicedTsQMiwUJXtI8yu5UaeSPs0FecYHIFbzyEbdCx7pv1yOuqB+hTZD1FHQ8rGbQTzRCGEBb53YvNH62kEzFqDGnVhd8nYEcZtYfTSPFgW1xb26SZCrB/UXB8zCIsi8e54Wg4boklt8HxgkImRHQ1ybTybq/H+O4T1DloaoZfcUC9wfkyjKJAUNpm/P4apEYn8sV7GOsJo+O1FPUEcrLxpVNwSRloBdUvQ/2b6/JyZJUcP4pHK9ckcFRG/l8GlKwOvQUqQ3rFVBFn8ro2mm2IJlGF3miPARdxcYtHT4ZpWzSwReMBCb9IobNZJhTyb9 ltkQH6SU AydzMhgNly3bvi2++SR9qU2xg9GvI0igPTYpaY9NGpvGGAd2Ks1piGqls8tqLYASbLQKUmeJ+BZfVfeibGvcrZFAb0pmR8V/ETbosb0mF/GzzacjQZsIF3cyLoAMtN6psvkMh28yVeCAAb39GIOZyiuJXJVbIS0uj5tm7VTIvPmp1yEsiCuNro9QDSb8qe9ZqTEgWpBAlEEtqsnjLYUd7MSr0MnyRMdMCQNhH69dGNkYgqVnaIHHXLaAqwRTkd61wMTRuFnjQ83w39NjeHZ+fwv6SDaWscPzAfS5mU7AOqLg/YN+eYLbKkac21A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, 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 Fri, Feb 2, 2024 at 2:33=E2=80=AFPM Nhat Pham wrote: > > On Thu, Feb 1, 2024 at 7:50=E2=80=AFAM Chengming Zhou > wrote: > > > > Since we don't need to leave zswap entry on the zswap tree anymore, > > we should remove it from tree once we find it from the tree. > > > > Then after using it, we can directly free it, no concurrent path > > can find it from tree. Only the shrinker can see it from lru list, > > which will also double check under tree lock, so no race problem. > > > > So we don't need refcount in zswap entry anymore and don't need to > > take the spinlock for the second time to invalidate it. > > > > The side effect is that zswap_entry_free() maybe not happen in tree > > spinlock, but it's ok since nothing need to be protected by the lock. > > > > Signed-off-by: Chengming Zhou > > Oh this is sweet! Fewer things to keep in mind. > Reviewed-by: Nhat Pham > > > --- > > mm/zswap.c | 63 +++++++++++-------------------------------------------= -------- > > 1 file changed, 11 insertions(+), 52 deletions(-) > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > index cbf379abb6c7..cd67f7f6b302 100644 > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -193,12 +193,6 @@ struct zswap_pool { > > * > > * rbnode - links the entry into red-black tree for the appropriate sw= ap type > > * swpentry - associated swap entry, the offset indexes into the red-b= lack tree > > - * refcount - the number of outstanding reference to the entry. This i= s needed > > - * to protect against premature freeing of the entry by cod= e > > - * concurrent calls to load, invalidate, and writeback. Th= e lock > > - * for the zswap_tree structure that contains the entry mus= t > > - * be held while changing the refcount. Since the lock mus= t > > - * be held, there is no reason to also make refcount atomic= . > > * length - the length in bytes of the compressed page data. Needed d= uring > > * decompression. For a same value filled page length is 0, a= nd both > > * pool and lru are invalid and must be ignored. > > @@ -211,7 +205,6 @@ struct zswap_pool { > > struct zswap_entry { > > struct rb_node rbnode; > > swp_entry_t swpentry; > > - int refcount; > > Hah this should even make zswap a bit more space-efficient. IIRC Yosry > has some analysis regarding how much less efficient zswap will be > every time we add a new field to zswap entry - this should go in the > opposite direction :) Unfortunately in this specific case I think it won't change the size of the allocation for struct zswap_entry anyway, but it is a step nonetheless :)