Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp179397rdb; Wed, 17 Jan 2024 23:28:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFvTIk+DZfcwTfVMfft9n64pVrchsCS9Zh4nn2sWoqx6S7hdnaBf2O+Jr+rGVQJOk7sIDb X-Received: by 2002:a17:906:7155:b0:a28:aa2a:316d with SMTP id z21-20020a170906715500b00a28aa2a316dmr485274ejj.59.1705562921639; Wed, 17 Jan 2024 23:28:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705562921; cv=pass; d=google.com; s=arc-20160816; b=qUkzXcYdbYIMq/5g06p6M1N9ZPScIwL/eVn67ngOJL+iyC1szKdnyS6zZWK8vEHFDM WJicuhI9IEJohpnj9nFLmJ2SOWiHTHUHuAkC4Oi27Ukkjg0nfY3/bIa9LX400VFhgxWD jR/EJ906ztuBkp/WY69kw6l7esafex/EyMMfYEsy50BB0DBAY31x5qtWJEl7pZ/RxJ9l 5/PhsZXZzTuavaD8PkWKOI4gcba0RIJGqP+rwxGa4NBuegnjxO1pfl4vOfE+FPU4xAfr fEgZpFrOfGqY7RKa+byLcrAQLoTrac0VHJar7X5Dpy2v5cg0bAI6ViH9eDVZ1EPfS6gU A9Hw== 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=Q4W73qGRou9IGq3hjJrftt/KTtPOdqFsTzXiRX/xyJE=; fh=3G+LrlaXkaxjxsos+peGn2UxPridobGTAuxKHlBj55Y=; b=s5nByHEhpCEJNU1fa4tGZc5KyaxnkgeYO6wZPvquUx3uZzYipMZ96ka5gXon+lKqxN i4E849BSSfAKJVGWGnjFSk6jSg/MBPj4XDUuqAjkqHLz5LL7j5geKWdJgok+/B5/kh6z wOJJj1R+MRsWDVhsLlf7KJzT9h0EQqljPg0M4KcZTuF8Jw5O9pfzTulcIZ2kPMx06j+p MbdxOHOwQnbtwJXaXvkKwVjiCkC1RQkI+S2k43zcNpnkpz6wkEv6IxiiRrm5KIXe6Urx nAsuhoeY/ocIGKP6UbWKoJubpNo6C1HxOwCcNQRHrgGOC+nI6LEDPMMkJD5JiYezIegU 4HFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dndPNy9V; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-29762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29762-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id kt20-20020a170906aad400b00a27c7422162si6495726ejb.237.2024.01.17.23.28.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 23:28:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29762-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=@kernel.org header.s=k20201202 header.b=dndPNy9V; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-29762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29762-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 671D31F22B87 for ; Thu, 18 Jan 2024 07:28:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CEFCFB64C; Thu, 18 Jan 2024 07:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dndPNy9V" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC20C947E for ; Thu, 18 Jan 2024 07:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705562913; cv=none; b=Cj+g3QlzNfBmZsTHjrtoEVVKo4qYeNlOm8UAGRSXwh0cJbdLs0J5hNGiysFIO7EJSbJG33JB/ELE+uTA5GsFuY6ED88Ln3sIZRIhBMLYzYJy3kQ0kbteI9EDasHLclVHnnZAWNgqtPvnF9WFI16ovXiBljU7AALVkWg5X7SRZOU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705562913; c=relaxed/simple; bh=Q4W73qGRou9IGq3hjJrftt/KTtPOdqFsTzXiRX/xyJE=; h=Received:DKIM-Signature:Received:X-Gm-Message-State: X-Google-Smtp-Source:X-Received:MIME-Version:References: In-Reply-To:From:Date:X-Gmail-Original-Message-ID:Message-ID: Subject:To:Cc:Content-Type:Content-Transfer-Encoding; b=ANDvFCqGjmwrwApwJZKHs13wLn7l4r9f41ymdauD9dFbpFeqy5yPu46heHZ+H87eKFmmAp6araUH8agqbjCXJq2TaUBhzcBEJiKu3YWC2udOIAV4CzgS7RsBl5RVj6mWOIsxGjT36ebheooDXPCvc49XnpqE9desVtPgiACa2xw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dndPNy9V; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58C2EC43394 for ; Thu, 18 Jan 2024 07:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705562912; bh=Q4W73qGRou9IGq3hjJrftt/KTtPOdqFsTzXiRX/xyJE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dndPNy9VJENMWrIKU2nCk5fC4X0VE+7job5eWhxWkfIfUsyr+MHu6dQhDn76BKxxL 8YFfaVZ+lz4/bArAngZSIsd6w825idl4a4MWVKTdfd87WRyouNp84snfvEWUNXlrK2 6qEK8a9yXOml2xrIV/+npFbUZiAV+9VZxUv71SXwcw4jW3QB19aNXqOEZDeKRf6h75 Mwp5KFYZDZATcQfEDBNX3aovFDFYTf9bNy/CKmzYgt65fPxpylvN+fxttxgNwVMwNf HfdPykCLMr2hcCQm9okjrLNM954PWz77MmOcPF8bbc44g5Mwojkg/aCgf7vpbGt7nl lR/nCoHj6hCJw== Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6db0c49e93eso8898146b3a.1 for ; Wed, 17 Jan 2024 23:28:32 -0800 (PST) X-Gm-Message-State: AOJu0Yw2DM2VAqfNygY73akxc6fJl5p47aOy1hGmIfbqCLE0TKW52O8m oa0MMr6iOQOWjUXPTpswxETgY3dbnuTsBmDoSxxMu0sVPEbelKdzIDk9KaJZbGSTOkgnCA57U52 pda0DET8/SqL17cvX+s6bgCd1K7HbgHu+h9lm X-Received: by 2002:a05:6a20:d80c:b0:19a:4073:e178 with SMTP id iv12-20020a056a20d80c00b0019a4073e178mr526568pzb.25.1705562911908; Wed, 17 Jan 2024 23:28:31 -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: Chris Li Date: Wed, 17 Jan 2024 23:28:17 -0800 X-Gmail-Original-Message-ID: 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 11:05=E2=80=AFPM Yosry Ahmed wrote: > > The name changes from Chris to Christopher are confusing :D > > > > > 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 think having two patches is unnecessarily noisy, and we add some > debug code in this patch that we remove in the next patch anyway. > Let's see what others think, but personally I prefer a single patch. > > > > > > > > > > > > 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 th= e > > > 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. > > I think this can be done in an RCU read section surrounding xa_load() xa_load() already has RCU read lock inside. If you do that you might just as well use some XAS API to work with the lock directly. > and the refcount increment. Didn't look closely to check how much > complexity this adds to manage refcounts with RCU, but I think there > should be a lot of examples all around the kernel. The complexity is not adding the refcount inside xa_load(). It is on the zswap code that calls zswap_search() and zswap_{insert,erase}(). As far as I can tell, those codes need some tricky changes to go along with the refcount change. > > IIUC, there are no performance benefits from this conversion until we > remove the tree spinlock, right? The original intent is helping the long tail case. RB tree has worse long tails than xarray. I expect it will help the page fault long tail even without removing the tree spinlock. Chris