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 C022AC4828E for ; Fri, 2 Feb 2024 22:44:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FA3F6B008A; Fri, 2 Feb 2024 17:44:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A9CC6B00AD; Fri, 2 Feb 2024 17:44:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 323286B00A5; Fri, 2 Feb 2024 17:44:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1F5626B0080 for ; Fri, 2 Feb 2024 17:44:25 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D819AA0836 for ; Fri, 2 Feb 2024 22:44:24 +0000 (UTC) X-FDA: 81748344048.01.CFA333B Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) by imf30.hostedemail.com (Postfix) with ESMTP id 3842A80002 for ; Fri, 2 Feb 2024 22:44:23 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MuSfLtzh; spf=pass (imf30.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.166.41 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706913863; 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=AMLY6NdQnT1U9X32xfuv+CMyZtVAhapgA0VssdBsgis=; b=5k5FlNNNbqgCmT08IdKrQaanu6IxyDLHXZZMwUUxNoRvlC4B/NZnzuw6QyDmaNxerj2WBT 6QMRMFWOl5aTQDPdNZMSM3b0OpY0HDgC8SH2cJg3LLl5Bw7nt8TwIClF/WCCG/siPx0cIH AYZTcxSZ1valdO0VEPxS8mhYmqtUouI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706913863; a=rsa-sha256; cv=none; b=g234T9G4fakJsvvr5WwQKhhL/wYulCczAX8rIeyfwr+uf92oyocf5BX/96s9vUT/XEpz6q 6qYjIyDhvPIvCYGkWZo98SIulFLrae0YJ0OVMXBkxJnxwO4UQP563Gu3UrfGsFBVS0zYVx KZe58QSaLjXzXq9xireS340spQW4/4M= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MuSfLtzh; spf=pass (imf30.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.166.41 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-io1-f41.google.com with SMTP id ca18e2360f4ac-7beda2e6794so46133439f.1 for ; Fri, 02 Feb 2024 14:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706913862; x=1707518662; 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=AMLY6NdQnT1U9X32xfuv+CMyZtVAhapgA0VssdBsgis=; b=MuSfLtzhXeLvdqcKz5G9CdH9us6r4GmjGCTIAzmRlqgytaUKiIs8qAk8gKYe3agGI/ eslof1vLJYM3SbdTX7vGkbck7uzXSZrCBlTfpaf1DJmubdWbP1gAu2unbIrwaperqPBa qJyuuEclgrVtA8XTmSLFWh6MGqUlMMBdYcsIbXqWRtk0VH/jz4RfHd9hT3jQ/upO0+jP Q7CzLgNX1BfwJVm25KMuseExeuU+ZO/Cf8WiW/riyKN+MzntxNwWZAI0e/wGbE35hM/G j5koVSwKQGKqjp6HoHR95jygKzpLO9X5ZWff8mPZe9MqAgrk85jHKapg3YdAa/oV4fVR fqmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706913862; x=1707518662; 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=AMLY6NdQnT1U9X32xfuv+CMyZtVAhapgA0VssdBsgis=; b=irbXFNwNgmwaDCURJdZIn+7CLvu2Ga45P9f4aOCsmPce2wom7C9gTRK1GpKyPSjCwF 5WX0UZxgsgbRYVdzDQxVVxrOckN/JNIObkfSCjn6dR27pzBNzrT1LhBwVHLoaw6GS6bZ 2h+5fI70r1SnHn7kKTl/ocSUmWfBXcyB5fEgoNig5Qzv0d40ypSztArwCVPvdWBEuDgd FjOfyhEKzlW+UMzz9t+ank6HbtmnWbyR8KzWTe67ecgllbxVT9t+pq1oa/ipdpJj27sP 1hX3nk49NAZC21f8GaTGrPWpm2g3ytgQnjeQJKoSaHDNJDN5GYeuOmOy6Fhd9XKt7pwv cmWQ== X-Gm-Message-State: AOJu0YxU+GdRqmwRvmHTWhpspFfa5Ahk9HyCDnMeZ3+7nnxFAKqka5rv aQgtVvuR1Td1Pic/e5l4zA0lJvIpuGhmePyMcKnLfgy6RlWjEnYCN5GLNLF3w7p77/9G3LmQN3F gtAMFtjAb+aSrwo9UTHt1byMmn+E= X-Google-Smtp-Source: AGHT+IH54dv2c1Flty4eD/sScEZfqMpxLZ6chyRV6g+BFX++dzAEJMKXa73YnYMK5a1fG1HHs3k/dBXMaLLB2dgmljo= X-Received: by 2002:a05:6602:3f88:b0:7bf:f7d1:ad10 with SMTP id fb8-20020a0566023f8800b007bff7d1ad10mr9531iob.4.1706913862350; Fri, 02 Feb 2024 14:44:22 -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: Nhat Pham Date: Fri, 2 Feb 2024 14:44:11 -0800 Message-ID: Subject: Re: [PATCH 6/6] mm/zswap: zswap entry doesn't need refcount anymore To: Yosry Ahmed 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: 3842A80002 X-Rspam-User: X-Stat-Signature: fo8tfemopzc9zqkdwns9axbygaw8gc9w X-Rspamd-Server: rspam03 X-HE-Tag: 1706913863-870242 X-HE-Meta: U2FsdGVkX18Tmi4A+ruwfHwWgRg3oNZ8mDb0X1WX96vC+pFwAuVJsH6z6QCHYDOC7hTtLAKEKoqA8W4gjNwJR07ZAtBP069+2SJXFO2HxD62VMiFCh2wONOjwv1HUKsP1aaL2b6x7mLpRGCLDbwhB6ug0qJCLS2NOxHngU460GALrPPq8H+eh/YsNN4eDIm2MU8I5/3YOyw3NBIylrBhbRC4cPuJ4k6sUEgy4Qz2x7UtA29pnTcRTwQPGFANCOtsypyck1LoRWvkfM5tKEAqeKjnLbsdIv5M/ef/2kAADkArN9H7w4vI2kEJr20rbzuxWeADMNV9QS44A0+bkyhh9TV50zrRvfJsUAJ9L1qlaebsV+GsQbbGERaDzjBdaFE2zVyJWFqX3qRnA2yTMni9Qrht+AUpknzpEhYuwJEFRoX9q7dNVd8Y0OUZxrmen3WPhgZCwdtQ3/qLAq56cPluoE97OgBCap6Htndi8gW3ZAtrwIO7AIC4RktBSG92+ED+yXSx2tgy4exGtjhv0c3cSYdKVjv8iaE4k9eELm9957gFs/3Rfao84L+U1Y3cS9mLiYxRqzW5E9efTiqqVBVEfZ+tjAx6JC3nups2hU56fCc/Ns0IKqfUAxuwW66OO0SZ30S0hevBRMtGftpmHzb3Ju0nJ5HDAcg5h0sqe3mOuSh8paamPx0UsvAFSwuNWm77uKFZcIlgRI1IZW6JnxJo85N3BoW+CVM3nGbKh3L4qpbF1b/pTg+7Vul0ge6N7iqP/l4LoXjNDegwf/hxlDVJSZKz40I/wcss9Ma1uZFRBQ/xUpbw9+2cjBgfsKEYkfVwWN77Gi/kITRF3lY6ONs7C+p2NHgZSK5xhxYoMyYUk/YdxW8MleLe92SX+0bWP8B7nSHkJb+72D7n6iBBdLMlRwtnZsvd0ijVMQIecCZOMThsr5pBKeteEf21d/BBUlids4J8KIT1FIuuLaAwXXw KT4rpadq wuKaFbqXa4cm0LjtdZRyHaf7HNhAqwb3TvDcS X-Bogosity: Ham, tests=bogofilter, spamicity=0.003598, 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:37=E2=80=AFPM Yosry Ahmed = wrote: > > On Fri, Feb 2, 2024 at 2:33=E2=80=AFPM Nhat Pham wrot= e: > > > > 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 = swap type > > > * swpentry - associated swap entry, the offset indexes into the red= -black tree > > > - * refcount - the number of outstanding reference to the entry. This= is needed > > > - * to protect against premature freeing of the entry by c= ode > > > - * concurrent calls to load, invalidate, and writeback. = The lock > > > - * for the zswap_tree structure that contains the entry m= ust > > > - * be held while changing the refcount. Since the lock m= ust > > > - * be held, there is no reason to also make refcount atom= ic. > > > * length - the length in bytes of the compressed page data. Needed= during > > > * decompression. For a same value filled page length is 0,= and 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 :) Ah, is it because of the field alignment requirement? But yeah, one day we will remove enough of them :)