Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp566792rdb; Thu, 18 Jan 2024 11:36:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6f0XdL2U+qVK4wd6UytRTY11UHN39AqAY3KEXwWjkSx5r33qK+G93Tbgcp13+kHzhIdA8 X-Received: by 2002:a05:622a:14a:b0:429:c6fc:f4c8 with SMTP id v10-20020a05622a014a00b00429c6fcf4c8mr1323529qtw.109.1705606587031; Thu, 18 Jan 2024 11:36:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705606587; cv=pass; d=google.com; s=arc-20160816; b=ks7Irc3QsQ4T43+s9AuYM/cqdek34KYha1DRNQDyb8wGbVltASkjCuMHPDEBxnbrPu vNz1dH73HRHirvq2+U7yf0QQCugs2xuKuyb1eK1LaNKP7ZUEkrn3i400i5NE3Lsai7Fo uDuJjzv+JJNoxtSd0iLJHjZWcbV989OcM9SpYSOhCUYp0kNNYCsdHSm3y5Qjgky7aOPi CCdp2Q0IP50JOSKuR2bLolxuOoPb+J5SXjz9vbwb5dYM6TaqCIlAidUsxTIZTuhzGbYb KZgCzOvWetjVfEH8InnROg4CmSfgoNadVb/gRHMcfB43ra040WlpuX88+B606iQPWuqp Nkuw== 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=cZDkcKK8uyhcMNTfFp6ML8LXI1RuetKqYpSVVoE584Q=; fh=X6ryCwQ0Aal2Ve8IO+xkZ22uIPGtGnQM9Gfby62l8Cw=; b=HLY1hxq2KFih0LDiB8RqByIvWzZj9YWIbaTCnNiEPnpJD9E9PSCcznwXDddZaZ9h8O Kzc614xAgwlFsK5o/o4tW2vPMOg/XOjDv5UdvD69ZNlR1iWJhgBf0DZZWWWeljIw/YG0 /jktFf19flOtVu5XHxYHA1pRgj2nKSZwazFPzFhKwpS7ERARhxUXYq17k7d/OaUwYuIq iDCHFIiwHLF39cfDOyjnNpralvsahxaKp6O8pTWa2JKEoz1RKmYf7IGiOHM3BidMv0dz znDjoOoLFsEZYBxlk2CnEbkCQZ2FZlvmu4tDTvEG+Qzo7ZyouQZM2zemQXZ7mYb+89WP QZnw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eXxknxGf; 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-30521-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30521-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k18-20020ac85fd2000000b00429cd0d7d65si12722399qta.97.2024.01.18.11.36.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:36:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30521-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eXxknxGf; 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-30521-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30521-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 64F9A1C215C0 for ; Thu, 18 Jan 2024 19:36:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB46A2E413; Thu, 18 Jan 2024 19:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eXxknxGf" Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 5E6A52E403 for ; Thu, 18 Jan 2024 19:36:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705606580; cv=none; b=gmFcuul3NUszmP7Myr2MqfUyWfjx+TRuxJaIk7QBynzO+ttGnLc6GpZTeATYGU8OL3rM1ogIs/4QAHZC4dUIr//nFDIhEdVNjkWky/4zZcw8DXMewHHwJefkzGem6+ZkOmomXPQOwFnFQBucSxHLAgGb+W2O3opbmpgxubiff4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705606580; c=relaxed/simple; bh=0Spb8poRMfqQSK08H+TL3uHUKPHZzTZQ/fCBGPaH0wI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=koO178slDm/3zEfHSUzxjIyavcbuwjNYXbIl1iIVn/XC3ouG2dTB8c0adiR3rAfsJ0PCSGP1r4UtIWi1ZmuJvsfZ3ispIhBbSZX3kGVaXuRFtw9BEoepOOvUK/nXILd0fmTPJeen3WZLiZ2FGSqiKC6XH1YI8yODQGTJiAlMsJo= 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=eXxknxGf; arc=none smtp.client-ip=209.85.208.48 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-f48.google.com with SMTP id 4fb4d7f45d1cf-559cef15db5so2122544a12.0 for ; Thu, 18 Jan 2024 11:36:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705606576; x=1706211376; 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=cZDkcKK8uyhcMNTfFp6ML8LXI1RuetKqYpSVVoE584Q=; b=eXxknxGfb5/amFXjTjOI+dnJEAVV0gYSvwKJwnM2hN9/CAWLTdqWMOfyByGjx/PFAb gogmVFEuZklyUCra12O0PIdIf/i/osHfDGbKGmmRilYhnSRwZjj7ab+uSSIwNdjDnIa9 JxgkdAvH5MOOUhyPdF/lvJgrQAv3MGDA4h2JKKjtw6Lxj2FxJQxjwJcK2vdOy+WUHxF2 QbCXKa4PejW1aZGs43PrQpPi7EXi67m9Iw4cc8TF6ysjaB0FiAa5zkAC3yL9B76xZRCL MAo2Cn17Ep1GNglbs4R+/58of25xPTyO5Jo4IzfvDrHtGigZ73GHy58hsyVyeqbM90tl huRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705606576; x=1706211376; 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=cZDkcKK8uyhcMNTfFp6ML8LXI1RuetKqYpSVVoE584Q=; b=oMBSooxe1KMOzQJmCYEJPkEg0Z1HOJmAEHkTKmRL4bvgY6RIqZ9yBGX2E2HnSqJqsG uxdZreM1mah7cmOGunTJf34tJtB45ifemtUyeEI4O5aZTRTTPlHmlkffQhJ9I2u65dWL hL2ADogKVWk2Je8e0ll8eWsNUjSrMKNMwaCWgpLXamW/2BpYQ8vRqPLUbok9bZswovyW yYwA1JS6XjBSyLO22P1ghKpaUqV/7uIsoA6BnrfgHWYRgRJAJe+chwBvP+bKuaYwRAzz egHGJOZqj5OrXHzqg12MwKtBH52wF3xfXhKXyoOZB9BvGRLQyEzTVwcKlkXtMfi9Ko8R pDhg== X-Gm-Message-State: AOJu0YwUE121KZXzWSJ6QlB2kneMQyvy8DGrUWUuY9CbKb15TePCBXaB rwzGo7yBllFjBd8Syd3nqWte8h1TvrEorkbxs+Ms4ZlQn2TRNVwv7Cd4mATMFrA6Bi//2gKnstG 4MtFeR6FdV/+yjbxPMoVjdEsHUeLhpQLztHNL X-Received: by 2002:a17:907:da8:b0:a2e:98d2:9c29 with SMTP id go40-20020a1709070da800b00a2e98d29c29mr2257202ejc.70.1705606576334; Thu, 18 Jan 2024 11:36:16 -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-2-6daa86c08fae@kernel.org> In-Reply-To: From: Yosry Ahmed Date: Thu, 18 Jan 2024 11:35:38 -0800 Message-ID: Subject: Re: [PATCH 2/2] mm: zswap.c: remove RB tree 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 10:35=E2=80=AFPM Yosry Ahmed wrote: > > > @@ -493,45 +471,47 @@ static struct zswap_entry *zswap_search(struct zs= wap_tree *tree, pgoff_t offset) > > static int zswap_insert(struct zswap_tree *tree, struct zswap_entry *e= ntry, > > struct zswap_entry **dupentry) > > { > > - struct rb_root *root =3D &tree->rbroot; > > - struct rb_node **link =3D &root->rb_node, *parent =3D NULL; > > - struct zswap_entry *myentry, *old; > > - pgoff_t myentry_offset, entry_offset =3D swp_offset(entry->swpe= ntry); > > - > > - > > - while (*link) { > > - parent =3D *link; > > - myentry =3D rb_entry(parent, struct zswap_entry, rbnode= ); > > - myentry_offset =3D swp_offset(myentry->swpentry); > > - if (myentry_offset > entry_offset) > > - link =3D &(*link)->rb_left; > > - else if (myentry_offset < entry_offset) > > - link =3D &(*link)->rb_right; > > - else { > > - old =3D xa_load(&tree->xarray, entry_offset); > > - BUG_ON(old !=3D myentry); > > - *dupentry =3D myentry; > > + struct zswap_entry *e; > > + pgoff_t offset =3D swp_offset(entry->swpentry); > > + XA_STATE(xas, &tree->xarray, offset); > > + > > + do { > > + xas_lock_irq(&xas); > > + do { > > + e =3D xas_load(&xas); > > + if (xa_is_zero(e)) > > + e =3D NULL; > > + } while (xas_retry(&xas, e)); > > + if (xas_valid(&xas) && e) { > > + xas_unlock_irq(&xas); > > + *dupentry =3D e; > > return -EEXIST; > > } > > - } > > - rb_link_node(&entry->rbnode, parent, link); > > - rb_insert_color(&entry->rbnode, root); > > - old =3D xa_store(&tree->xarray, entry_offset, entry, GFP_KERNEL= ); > > - return 0; > > + xas_store(&xas, entry); > > + xas_unlock_irq(&xas); > > + } while (xas_nomem(&xas, GFP_KERNEL)); > > + return xas_error(&xas); > > I think using the xas_* APIs can be avoided here. The only reason we > need it is that we want to check if there's an existing entry first, > and return -EEXIST. However, in that case, the caller will replace it > anyway (and do some operations on the dupentry): > > while (zswap_rb_insert(&tree->rbroot, entry, &dupentry) =3D=3D -EEXIST) { > WARN_ON(1); > zswap_duplicate_entry++; > zswap_invalidate_entry(tree, dupentry); > } > > So I think we can do something like this in zswap_insert() instead: > > dupentry =3D xa_store(..); > if (WARN_ON(dupentry)) { > zswap_duplicate_entry++; > zswap_invalidate_entry(tree, dupentry); > } If this is doable, I think we can return xa_store(..) and keep the logic in the caller. I think there's a chance zswap_{search/insert/erase} may end up being very thin wrappers around xa_{load/store/erase}, and we may be able to remove them completely. Let's see how it goes.