Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp790817rdb; Thu, 18 Jan 2024 21:28:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+J0IwKhkpHslBNa2YCtujGGjRkvCPyyNjiB/zVDRqMmMfDlpjaqYWfA2dHEZR3RMI96Aq X-Received: by 2002:a81:6008:0:b0:5ff:981e:d228 with SMTP id u8-20020a816008000000b005ff981ed228mr1031913ywb.94.1705642115013; Thu, 18 Jan 2024 21:28:35 -0800 (PST) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y4-20020a05622a004400b00429fa91031fsi8433139qtw.344.2024.01.18.21.28.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 21:28:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30774-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=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b="i/qxAmei"; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-30774-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30774-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B0A821C2287E for ; Fri, 19 Jan 2024 05:28:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FB1D4A11; Fri, 19 Jan 2024 05:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i/qxAmei" 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 49C7A469E for ; Fri, 19 Jan 2024 05:28:25 +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=1705642107; cv=none; b=jYv7LLSuOZmfWnIbv+cYvDYOT1I0jU9iTAnmw6A0CBBxPTI6PIeoCCH6aY/pN5LielxSZ8P4cOSeBcL4fw5czULIstWddjyOxYwT31mQlU8q1AMKps3fCcqNqJRJ49E2q+IuPz/kKvc7yMpPyVZ6+vx2WqknDhm5joSugnjc2u8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705642107; c=relaxed/simple; bh=czy8DnaAWLHQlorivc+Ot+gTA06S0rxyezopG91WYbw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=B3piuBVpI7L0gDwr5RM7F0K8fYtYRdp7nFtoGrd3pok9jhqeSD2WiysnSuK4whMeZK1332dQaQGrk0cYV90PVCiW4csoA8O+Uk8h+A1Nl62UAxP/XcrqtnfmC82FzheoTaB6a58WlDBZfxNGpZEmGjYX03s0Aj04OILzzxHO/JA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i/qxAmei; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA96EC433B2 for ; Fri, 19 Jan 2024 05:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705642105; bh=czy8DnaAWLHQlorivc+Ot+gTA06S0rxyezopG91WYbw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=i/qxAmeiqpEB0LGY4stShFOqEOB21Lg4pAWxq74Kq3asfQMUJCvPrGSbGNWeONvRg 2ui4YyDE0ZyPzT3t50gVpcPcK83KNu+yI/fafjxiIkUqQcTP1r1pqBQr1q+UhcHfxz qmG08IB2TBk8Ut8hzTAS2cxDGlzKJ/1krR811IE/AFbxCVSHyX+HM4OjV9OQL4FVE+ bYVNRsb1Ix/566v4TY1w4H4G9tiHD3Z8o0loSg58dkldM4O/9Vh/RyXGjuupfFXNNv 7mmVK4lzPGA2Nrusp7EhRXjuh/I4Xr42Jr5BzcOD1ZOjqquJUEQdCxkNFLjXZQ6KNR maRfhul3QRtPw== Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dc23bf7e5aaso502187276.0 for ; Thu, 18 Jan 2024 21:28:25 -0800 (PST) X-Gm-Message-State: AOJu0YzrPm09O2sc/4KZ8m0KYKXncKOc7bzVJ+Gm1G5SBxYedFjSdib+ te7PHDWUUP1LjqopafYztIm/XqLUPw3bltvGdSeeVQvNc1rfR3/ZYRML4VZVhOx058JV9bSeq3G /w8pPLJKdQr7gDo4H6zE6KQ80/lwXWvDh7W5a X-Received: by 2002:a25:9207:0:b0:dbf:114a:9443 with SMTP id b7-20020a259207000000b00dbf114a9443mr1873923ybo.67.1705642104867; Thu, 18 Jan 2024 21:28:24 -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: Chris Li Date: Thu, 18 Jan 2024 21:28:13 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] mm: zswap.c: add xarray tree to zswap To: Matthew Wilcox Cc: Yosry Ahmed , 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 , "Liam R. Howlett" , Joel Fernandes , Chengming Zhou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 18, 2024 at 10:25=E2=80=AFAM Matthew Wilcox wrote: > > On Thu, Jan 18, 2024 at 08:59:55AM -0800, Yosry Ahmed wrote: > > On Thu, Jan 18, 2024 at 5:52=E2=80=AFAM Matthew Wilcox wrote: > > > > > > On Wed, Jan 17, 2024 at 10:20:29PM -0800, Yosry Ahmed wrote: > > > > > /* walk the tree and free everything */ > > > > > spin_lock(&tree->lock); > > > > > + > > > > > + xas_for_each(&xas, e, ULONG_MAX) > > > > > > > > Why not use xa_for_each? > > > > > > xas_for_each() is O(n) while xa_for_each() is O(n log n), as mentione= d > > > in the fine documentation. If you don't need to drop the lock while > > > in the body of the loop, always prefer xas_for_each(). > > > > Thanks for pointing this out. Out of ignorance, I skipped reading the > > doc for this one and operated under the general assumption to use xa_* > > functions were possible. > > > > The doc also says we should hold either the RCU read lock or the > > xa_lock while iterating, we are not doing either here, no? > > I have no idea; I haven't studied the patches in detail yet. I have > debugging assertions for that, so I was assuming that Chris had been > developing with debug options turned on. If not, I guess the bots will > do it for him. It is fine now because we have the extra zswap tree spin lock. When we remove the zswap tree spin lock it does require RCU read lock. You are right I would get assertion failure. Chris