Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1210787rdb; Fri, 19 Jan 2024 11:30:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnguFPtc/S5tRRDETcJIVufe4whblmF1f2nbxt6WPj7g64VedVOzQQn3IruUZDU0AorJ4X X-Received: by 2002:a2e:b908:0:b0:2cd:9fbc:d3d3 with SMTP id b8-20020a2eb908000000b002cd9fbcd3d3mr104230ljb.69.1705692631588; Fri, 19 Jan 2024 11:30:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705692631; cv=pass; d=google.com; s=arc-20160816; b=y5MX8Fwb3cGnHXRhcNCyE1KbOti1OUZzCNA+RLGeUmUgfdtdJdUZgnqKLUQrm+E8VN bBFL+HZ7dpg5O3MIW/HXy4R5LDEeLOFaIk39je3LlEmfOtddzh2iyw46pf3uxOj0J27p 8w/uvLVIMONk2QovwvWPNFxKCNR1QsMYnUjTUu2JyOZX+crrq0ufYtGCTPgb6LD3j5ua DHtJLA86DvgLPwxLtyhNoCCMKzQep/1S4xjPPomEtbsh9e7YIHuUszsAMh0XMnqEKAB+ IELdCdqc03CfeqCjC19AySKFAUs7ejKAzo+qpKUpUmBHTn5Jk9D6D4rlp2lELdrKvQnK NVbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=ugyBhCYqe/JSP/toMybx2mnqVSMpXtGwbZ5vXwky8K8=; fh=X6ryCwQ0Aal2Ve8IO+xkZ22uIPGtGnQM9Gfby62l8Cw=; b=TezndaHl4Rlam0ykI6aI29Bc7Xv3x4X4fpgnilFap0malthb5Rx5njI8q+iskIUY1O 3DF28oAMpkH1ZKMwnVZC4XEaA9p57ohONXpjfg1mlWs/8X0gmKKP5h468w7vchFEWyTL rOqRS1/Z8BeQraL0+7JHGNvQBAyP0feoy5iqGG7HEEZNDJJbY2eIs+ZWPGXjBwMVp1tO ZT/Pb1jp6HiLGUbEGFQi5HoSE5POdFVhUx8BcvwHJO3kDkTHEKpFaO4z8ugAqRwYaiQ4 5mjL9Vbjo/VeGmWF/gNeZqaERIPWe7ZhyshshCTvGKyAAZA6iv54gcnhj2j5m0Cd4ciA RSyQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bhMkI0Yv; 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-31513-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31513-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 13-20020a0564021f4d00b005578c6a3099si8421142edz.144.2024.01.19.11.30.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 11:30:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31513-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bhMkI0Yv; 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-31513-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31513-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2F12E1F2483E for ; Fri, 19 Jan 2024 19:30:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 814B55645A; Fri, 19 Jan 2024 19:30:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bhMkI0Yv" Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 1447F5466D for ; Fri, 19 Jan 2024 19:30:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705692622; cv=none; b=aidW6G1dCrPNio/j1NQSu1eWvOg6OLSL87u0Bzp8OXL/fUasTwv410BISIXddKqUy/xwcWtWwovXnxw9P4bpIMnCVFQz85W0Ok3V7dIM0FMWAEaZHqxkPahp93w4awjNsf1ZdlS4etSpbW/0DFnHBNd5/572sDPQYoY6vgRH3ko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705692622; c=relaxed/simple; bh=4okcQjoHZtRPK7y+6GvlMJHUm+mOGWVYBEIFCFvB/QU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rSgDn6hRr1V7l1Zc7PCV5iupykK/h9lPcImZAC/BIZG/aYLKzDRY6GP19LAi4sLKSioeT70pElZXqCbmpcQpD4wFaQ5PjFlF6xY+tkaOtdpfTLA/4eh+68VH1YhDrWOGvjozst4jOlyNHV5zzkRzqEi8+T4ot26cwu1ddqwem/8= 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=bhMkI0Yv; arc=none smtp.client-ip=209.85.218.45 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-ej1-f45.google.com with SMTP id a640c23a62f3a-a2fbb646eb4so9162566b.3 for ; Fri, 19 Jan 2024 11:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705692619; x=1706297419; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ugyBhCYqe/JSP/toMybx2mnqVSMpXtGwbZ5vXwky8K8=; b=bhMkI0Yv2VR7gW1YjD3pGVaPe632+Sw0ZG08f1HwV1gL0L9KnjQL5eSZCf2jQzNjJM QqbLRQ5el2W6fKkNJNS2MVd6U3YQP6nQbSq/b3ihiJCgexUBhDbbyKWHBCXM7w6nsfFs oyrCTgRKU5R2gquk/meDWJyOyMbBSpGZSTUDoE9C/mnOe+HNgiIaJEMWB0rpbvJA6QKX 7Jagpt01i3bwmRpqsOCCj/jiHSGnLa0i7MZ5iQjx9CZOWN74GzP7GbFN5k9Rt98LRqvw /9/5cYzWD2SpoVqjQ9WGz/Wlz03ufrtXvZYMRrIxhkK1Lvd6ap4I1wGq3qTkdRcISYwd x0+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705692619; x=1706297419; h=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=ugyBhCYqe/JSP/toMybx2mnqVSMpXtGwbZ5vXwky8K8=; b=ScWWkE2Q19SrG07OMu6g6p/dEgZxvGQo5VAxr5F9IAc7KcoRVLDDFkxBAjg6IfSYag 29e3/VS4xMju0Q/+iIEknc8rkpW3OzGVXsWv94otxS8+VfHhJUqewOljJWUlPgziwAqO 9kaTF0i6nv1mo6rXd4wQLDbgvRWw/oZmEQK3+tqtttAc2GcPnemprjckqWAAOcnPDrAg tOvKA6084EjV19/NzrlN8IQpGFJTr6rOqxuHUBrcuJxpxzyHswoMIsZN+o0bOMpch5uL GPN1i0jF7/qaU9GVnrIsLnaSSfYQX6C0DgummMY4qkbRH8GrJp31NjyuKxd50Hpe9cWR B86Q== X-Gm-Message-State: AOJu0Yx57nEEvZRyUSP4K8zwUlMSb6ZA28zeA+IpkxSPNMfbe6iONOls i3S9GubZDjPynO4dQQxzMnH43z+WrjDXud399TwC+J5KqI6Cx1CLton7nOG8RVe0EONOxGuiHnV cRVnkgc8p5cbITg/i2GTJsz6be+nejczzRbTy X-Received: by 2002:a17:906:2b85:b0:a2f:8533:af79 with SMTP id m5-20020a1709062b8500b00a2f8533af79mr139810ejg.36.1705692619040; Fri, 19 Jan 2024 11:30:19 -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: From: Yosry Ahmed Date: Fri, 19 Jan 2024 11:29:42 -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" My previous email got messed up, sorry. > > > @@ -462,9 +463,9 @@ static void zswap_lru_putback(struct list_lru *list_lru, > > > /********************************* > > > * 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). > > How about zswap_xa_* ? SGTM. > > > > [..] > > > @@ -1790,15 +1808,21 @@ void zswap_swapon(int type) > > > void zswap_swapoff(int type) > > > { > > > struct zswap_tree *tree = 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, rbnode) > > > - 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? > > For the RB tree the mapping is stored in the zswap entry as RB node. > That is different from xarray. Xarry stores the mapping outside of > zswap entry. Just freeing the entry does not remove the mapping from > xarray. Therefore it needs to call zswap_invalidate_entry() to remove > the entry from the xarray. I could call zswap_erase() then free entry. > I just think zswap_invalidate_entry() is more consistent with the rest > of the code. I see, but it's not clear to me if the xarray is being properly cleaned up in this case. Do we have to call xa_destroy() anyway to make sure everything is cleaned up in the xarray? In that case, we can just do that after the loop.