Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp157160rdb; Wed, 17 Jan 2024 22:21:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNmaoGdNfGFHxTw2/8nl+uQPbLMDcVh+l2GYj0yUiFQX3EXVyZSkHUG4etcMTNs9BIIOJ/ X-Received: by 2002:a05:620a:13cd:b0:783:2a99:1a08 with SMTP id g13-20020a05620a13cd00b007832a991a08mr334476qkl.86.1705558876936; Wed, 17 Jan 2024 22:21:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705558876; cv=pass; d=google.com; s=arc-20160816; b=wL/yHwyAPTRFdurpllZW2/EKoYVFFoolDiGlUKzA4aSIBPoVAei3AIBGlV3nmUUSTu r4Vn5ZwMp7RpV/Lw9/ctMF9hdsb1WSno4JTlLYSt0e/bYX521EqAgnQhUYqcv9J5Hqt4 4z82ZVotG4lXoi+6LXu3bmEfEXHRI/87dqAi1SAhn8TE96BriPa6jYiVZYIVn7mE76xb e2nX7XFqNJCz03/bD1weV+ce0h975lX0t/oiq36mRshvv4nqEPyzv9y3teo1A/VPkLFu mHO13OwOPobQgf5fTI8CFf1Z0LexSIraLG3bwwyZ7dM/BFYLbv/Epmw13Y/UUMHJPtP4 WiDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=VJlVK4iBv+zofuCe2C1FT9Euxl2G3WgJemm135I8Sv4=; fh=X6ryCwQ0Aal2Ve8IO+xkZ22uIPGtGnQM9Gfby62l8Cw=; b=NRzsmIC54X8OHeG4NVjW0kNr3cUBOXfPQDC34LEFEi9oTjUCHdZIlLm3Gd6z85GA14 kCTJpw64JgQukxU9lc1lKxPlSQPqIIEFAn1gUJYdbE+ZwMtlLf0hLjNrdDKHKPu4SoWf ohPozJ7DDhLZII+MX5BM3XutNmWGXY4zHQnAb8wqxOx9+e7BGqjVAATb99w5nWEoHbBr PHTEqf1G+UAkeVjDAfLe0uc+xH28WXdnb3aUrwrsZSo/slJ8sGWxuG1oL22P0c2Z8Nuj 6DktvU4ut2OcegIlQhf7Z2l7KXGwQSrI3aABfEOaDn3ehtAWYNsu07XOHz/1p3X+TTkg MQNg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GqeMTYm1; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-29733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29733-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i1-20020ae9ee01000000b007831c3461bbsi12884755qkg.159.2024.01.17.22.21.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 22:21:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GqeMTYm1; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-29733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29733-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A06311C220D2 for ; Thu, 18 Jan 2024 06:21:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1790AB645; Thu, 18 Jan 2024 06:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GqeMTYm1" Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97C23AD32 for ; Thu, 18 Jan 2024 06:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705558869; cv=none; b=ivzLL+bWtrrxLStR96+o/dRGhLhQRxAK5WXFTNDrOToKpXWKTlhkPyZwedgW18hhu6PlQvC30nSzugO82qrIMR4qN46GYNYwkOATL6kajAqTOpEooK2j7kySsnyN7xmFB6hUxvj22OiHsqAsO/CWrCLGcKkD+SGgDRHKHUVNiEw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705558869; c=relaxed/simple; bh=S20zCEpNDq/pV+bHDoxCXxZGf7EohjVM/y/O8lfCHtw=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:MIME-Version: References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc: Content-Type:Content-Transfer-Encoding; b=u0gAZcniB+LHTVqGRgNhMcw/6KDK/AGAzLB2wiUfVSzxJSZVsX7Hnuld1VN2R8qLz+5EVZrRziTLK9ECtat8FAhaVnL/653hHU0FAZOLr5DeBvytCDBCwUO+irRODuXSigrbolrSt2M5wHAZWKXIoLyWxDqli6BdHLBUqxT27Mg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GqeMTYm1; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-55a08b00ac1so199844a12.0 for ; Wed, 17 Jan 2024 22:21:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705558866; x=1706163666; 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=VJlVK4iBv+zofuCe2C1FT9Euxl2G3WgJemm135I8Sv4=; b=GqeMTYm1rrSXlF9fjQloKGDmg6ZZllT9GUMn5e5SW0Tt5z2mLha/rkTiMKtt5F0Miq 2Aa313hjp5RzkbAuYXn6gLIiArebRACiP73iefWT7AKAHPWI4GIA6YnyUM10NQ/0YbiL EBGcMQE563drLMC/JxTVC8wtC6WujoGICoGNMSBbfyWYifj8jKCRmabPNRDEU27eVLG+ WR3272nSrco4kv2/E8IMHwAuuvDUo5e4zZhftPJb6KkhzYJPSzyvoWG7WhR6Shauh1I+ x+DeNWmAbwCQ7lf81gV/Rev92FAAnf0rh+lXu57zDnQXtBlfUmPl1Nd6VoGEsNyLJtfj bCCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705558866; x=1706163666; 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=VJlVK4iBv+zofuCe2C1FT9Euxl2G3WgJemm135I8Sv4=; b=cWA/uqf8sOlaUpwQNoMd9JqdSQNCvr7rmhJ5SEd1uZqOkSRAGvWrhVWys7S7NnH99F CXngouDWQimfgPNJUkJwr+lwbb/yyg3SK4C0CWTwFHSQGa6uLPiVqnEDMvzqGoX1Tu9D 0k5I/C/yLmwaeQiAy9hygPyPrN4LUb8vgVpAuD1mHzpTer5xH91fUaNtRJrC/5yffSBr Yrxw8iwDkA/xTZuqLtRqokmEDF0EMx/9MXlGPUTbvUxeQRIvK/PT7ulRpsHLcyyDt8Tl p0OSZNHlIxxePuy6Lwa2w3jDBvAP8vazK33GiYqFTtkKB60NkzLz7i00Ttv4OiZ6W16N C71A== X-Gm-Message-State: AOJu0Yy0An7Vq1gFU3wyVHC5Gr3aYpzdX2pv4Ms4wEgfN9QG6qknGBTl mWSJBAh7pD37Ki6ke+WdfwsgSw9qESwfH9nDgfP8pCqyvMmGwpxFxbMato8cB2nm/QPV3rrQ0LO wB+CkqT8g1kw2Mmiq8suNgBB+bMt+TkOwbGVf X-Received: by 2002:a17:906:f0d8:b0:a2c:872c:5683 with SMTP id dk24-20020a170906f0d800b00a2c872c5683mr152624ejb.41.1705558865635; Wed, 17 Jan 2024 22:21:05 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240117-zswap-xarray-v1-0-6daa86c08fae@kernel.org> <20240117-zswap-xarray-v1-1-6daa86c08fae@kernel.org> In-Reply-To: <20240117-zswap-xarray-v1-1-6daa86c08fae@kernel.org> From: Yosry Ahmed Date: Wed, 17 Jan 2024 22:20:29 -0800 Message-ID: Subject: Re: [PATCH 1/2] mm: zswap.c: add xarray tree to zswap To: Chris Li Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?UTF-8?B?V2VpIFh177+8?= , Yu Zhao , Greg Thelen , Chun-Tse Shao , =?UTF-8?Q?Suren_Baghdasaryan=EF=BF=BC?= , Brain Geffon , Minchan Kim , Michal Hocko , Mel Gorman , Huang Ying , Nhat Pham , Johannes Weiner , Kairui Song , Zhongkun He , Kemeng Shi , Barry Song , "Matthew Wilcox (Oracle)" , "Liam R. Howlett" , Joel Fernandes , Chengming Zhou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 17, 2024 at 7:06=E2=80=AFPM Chris Li wrote: > > The xarray tree is added alongside the zswap RB tree. > Checks for the xarray get the same result as the RB tree operations. > > Rename the zswap RB tree function to a more generic function > name without the RB part. As I mentioned in the cover letter, I believe this should be squashed into the second patch. I have some comments below as well on the parts that should remain after the squash. [..] > > @@ -462,9 +463,9 @@ static void zswap_lru_putback(struct list_lru *list_l= ru, > /********************************* > * rbtree functions > **********************************/ > -static struct zswap_entry *zswap_rb_search(struct rb_root *root, pgoff_t= offset) > +static struct zswap_entry *zswap_search(struct zswap_tree *tree, pgoff_t= offset) Let's change the zswap_rb_* prefixes to zswap_tree_* instead of just zswap_*. Otherwise, it will be confusing to have both zswap_store and zswap_insert (as well as zswap_load and zswap_search). [..] > @@ -1790,15 +1808,21 @@ void zswap_swapon(int type) > void zswap_swapoff(int type) > { > struct zswap_tree *tree =3D zswap_trees[type]; > - struct zswap_entry *entry, *n; > + struct zswap_entry *entry, *e, *n; > + XA_STATE(xas, tree ? &tree->xarray : NULL, 0); > > if (!tree) > return; > > /* walk the tree and free everything */ > spin_lock(&tree->lock); > + > + xas_for_each(&xas, e, ULONG_MAX) Why not use xa_for_each? > + zswap_invalidate_entry(tree, e); > + > rbtree_postorder_for_each_entry_safe(entry, n, &tree->rbroot, rbn= ode) > - zswap_free_entry(entry); Replacing zswap_free_entry() with zswap_invalidate_entry() is a behavioral change that should be done separate from this series, but I am wondering why it's needed. IIUC, the swapoff code should be making sure there are no ongoing swapin/swapout operations, and there are no pages left in zswap to writeback. Is it the case that swapoff may race with writeback, such that writeback is holding the last remaining ref after zswap_invalidate() is called, and then zswap_swapoff() is called freeing the zswap entry while writeback is still accessing it?