Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp165412rdb; Wed, 17 Jan 2024 22:48:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IH92Y2Me8iwhifh0fEqXpWJDy5cqlnCSIHF7IdygUJJnAEOM3WpOfNPJMTGvh0QrHUa9Daq X-Received: by 2002:a17:902:6b41:b0:1d5:78bd:af9e with SMTP id g1-20020a1709026b4100b001d578bdaf9emr511587plt.116.1705560516942; Wed, 17 Jan 2024 22:48:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705560516; cv=pass; d=google.com; s=arc-20160816; b=tkK6SKP/Up6LVVGJSjNPubJWmV+q5dG5zK45PiCXZ5QhOynZFwFFUrCBhANU8E8AON F7qaNjQWvlooMdqfUFQKr43y6whHKm08PXOQ9qAXpBOTK5wXsrJSLIfqY1QQqumUXGxY sfjdvUpsaXkhwfKbffl+RoRVwBrRxHomEjzj0lWCrYdJgDNxDrBVHos7+wConJljcGyP a8y9TI1Xkarr86lx+sHdSFH9EKNkVDnN+uE/UrJwDHHDLzZWtGfOsyxbNh9eMFCm6ywq aZY8TPJMeHmZcpFA3kWpSi7vkRb9b86gBIlMq7/Ex9vmhuQv2x25DAt7ueGJd/bHz4Mi Bizg== 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; bh=8jauxg95i132eOZCuJr/hrW8/+eD3j4e3f3VPpTT5U4=; fh=3G+LrlaXkaxjxsos+peGn2UxPridobGTAuxKHlBj55Y=; b=0hg/nxCym8ZRUFERdnLM/toHdBDHKKPjJgL8HhNrsGGKdQQkA3kX93R3ciQNigGbAR Mui8ZBHUuEYODDe4csmYZYSC7fuPUyN834eUpqLfg6XCA/SakjZ0aW0rHNKJKCUy7oQJ yGRzOPzbZBc76VNOhaitEK1FjULy8827xK+DRZa98+E1+XLofSZ+B7vQ1vydnYiy8fHF x83pIVW8QMO/oMIyAICCsL4Cn5vaRI9SNYWM53PBAPzCbl5alRNpn3Uypsgnzv04/rhc jEvE0gsBlSEmtTyXq9NoZiC71/41R/MiwWy8nth/rn9jCLQJC8ABauuUn1djIjfMqmac HohQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-29746-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29746-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r24-20020a170902be1800b001d5e2a969ddsi930839pls.562.2024.01.17.22.48.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 22:48:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29746-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-29746-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29746-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8DEE0283854 for ; Thu, 18 Jan 2024 06:48:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C935944B; Thu, 18 Jan 2024 06:48:29 +0000 (UTC) Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 417997481 for ; Thu, 18 Jan 2024 06:48:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705560508; cv=none; b=l9ypoLITViq1cfsUVBkXc7q/6d89xZ6NvjmeYm5YMkiFsPHUmNXgXkB497jket83Anz4UjA1+OB0fZhahhOAbPprVvIrkWvTa0eXkjxUjWMPhWhY4dqoaKZ7NB1PdUqNHtrNMLZMTrrK0XNvbvm7GSI9d9wcw/dg694eGeMtS6s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705560508; c=relaxed/simple; bh=8jauxg95i132eOZCuJr/hrW8/+eD3j4e3f3VPpTT5U4=; h=Received: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=qisREiPzge3tgBPJFGFn3BjGZ3x+Y9G1oRkFh2OFSVdhjahsfUsMphfQHkjkN2rT42EgofLgf0CNSl7JiIyqG0bv1+rLf7HejShwfKVSubuYNketVEWefojX8J+/dbG9C6dE7QE7ZYfnXnY7GqVdMN5E2NY0RAr1Pj6yptPqvSE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-50e80d14404so354981e87.1 for ; Wed, 17 Jan 2024 22:48:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705560504; x=1706165304; 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=8jauxg95i132eOZCuJr/hrW8/+eD3j4e3f3VPpTT5U4=; b=Fag5lDKIuZPbAGviynsCRgJ9H+6wpJt0SNWD1DvNn+g7w635DtZxBpdMSc2OAIVRZJ HGFNaTaiGYyhZxPH8yvUU7zTg2/ObnieO7AXEV5dPfqXYEqk8bKLWyX4XW24Sz7sTbK0 WqG8Y+6myusxyOgeEgUNRy3/xnXckfKGPBGlspP8Cr2d+hWMzOyReX5qrnsIKlbWPsks NQw2q00tWGpNZAOGsMKrXPVhn1FhvS7yWSZqpUPpF9fhbuQr6E0h1bg5igiQAtpekHWt V6sTLA2PoMS2t3y6yhW1BZJu0RhgPpCNjfc7sG4V7A8frpweSKM7QwP8iIKwEu9Aw1cD CcOg== X-Gm-Message-State: AOJu0YwHWz8avItETu06Wkaib/gZh/QCREUj8pepuX3778bS4xHrgsuC 4N6CDpGNO07GUQwItuiBauYbpdi2uzGYjprgZ1g7ZYvYNIpol9FPv80isNQS36IQ+NDItxfRXbo FPMdS/fWODDDQcuYIwy/PjlOW6w== X-Received: by 2002:ac2:4283:0:b0:50e:ed79:d94a with SMTP id m3-20020ac24283000000b0050eed79d94amr246958lfh.30.1705560503950; Wed, 17 Jan 2024 22:48:23 -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> In-Reply-To: From: Christopher Li Date: Wed, 17 Jan 2024 22:48:11 -0800 Message-ID: Subject: Re: [PATCH 0/2] RFC: zswap tree use xarray instead of RB tree To: Yosry Ahmed 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:02=E2=80=AFPM Yosry Ahmed wrote: > > That's a long CC list for sure :) > > On Wed, Jan 17, 2024 at 7:06=E2=80=AFPM Chris Li wrot= e: > > > > The RB tree shows some contribution to the swap fault > > long tail latency due to two factors: > > 1) RB tree requires re-balance from time to time. > > 2) The zswap RB tree has a tree level spin lock protecting > > the tree access. > > > > The swap cache is using xarray. The break down the swap > > cache access does not have the similar long time as zswap > > RB tree. > > I think the comparison to the swap cache may not be valid as the swap > cache has many trees per swapfile, while zswap has a single tree. Yes, good point. I think we can bench mark the xarray zswap vs the RB tree zswap, that would be more of a direct comparison. > > Moving the zswap entry to xarray enable read side > > take read RCU lock only. > > Nice. > > > > > The first patch adds the xarray alongside the RB tree. > > There is some debug check asserting the xarray agrees with > > the RB tree results. > > > > The second patch removes the zwap RB tree. > > The breakdown looks like something that would be a development step, > but for patch submission I think it makes more sense to have a single > patch replacing the rbtree with an xarray. I think it makes the review easier. The code adding and removing does not have much overlap. Combining it to a single patch does not save patch size. Having the assert check would be useful for some bisecting to narrow down which step causing the problem. I am fine with squash it to one patch as well. > > > > > I expect to merge the zswap rb tree spin lock with the xarray > > lock in the follow up changes. > > Shouldn't this simply be changing uses of tree->lock to use > xa_{lock/unlock}? We also need to make sure we don't try to lock the > tree when operating on the xarray if the caller is already holding the > lock, but this seems to be straightforward enough to be done as part > of this patch or this series at least. > > Am I missing something? Currently the zswap entry refcount is protected by the zswap tree spin lock as well. Can't remove the tree spin lock without changing the refcount code. I think the zswap search entry should just return the entry with refcount atomic increase, inside the RCU read() or xarray lock. The previous zswap code does the find_and_get entry() which is closer to what I want. Chris