Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4529642imj; Tue, 12 Feb 2019 18:38:17 -0800 (PST) X-Google-Smtp-Source: AHgI3IZFmtl40lEHbZKyWfg8xfRpcG7XCqyrSVQJgSxjLemf66/o7E945JQWadwLmojwTCDWAOAb X-Received: by 2002:a62:43c5:: with SMTP id l66mr5362092pfi.77.1550025497500; Tue, 12 Feb 2019 18:38:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550025497; cv=none; d=google.com; s=arc-20160816; b=SoCWwDnrn2fH1lI/5zyUs99c/ECTmKSPpI7wfRpMlWmB92L4OBQxdiQsqFPe5mRYCq GCCzUt1Byr90rgwVxaTWEGGMdtiCRqZakshP8xweFCv6GbZmDGP7LjGK8c0cNFv/h+bF C4JpQk4VhD+X3hHknjX4PQytUZpwjnAyDua4s5TU1JwMq+kpbVaqSCvu+tWY3Nkoy/an oIdrxFaOt58HFKkKtQ1MimR+mC24NmdiOoUcFJhXDl1zvzhqL2wuOH5Sp7gRc9Vsu/1Q zFQt7PIsCxWth3uYONGUKULFvJTnkUpjyGMvR0NDOr38lxwT1wEbi3rt1A+upNOV5fRB N+Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=/vsni0qI4nIlP2MtRM9/uEjnMvwObGlkgdfO3PfJISo=; b=S3UAsn6ZSY4KFXhRJ0BeSQxUcambpeSeX9ZXzAQmQOvveSGdj2BffcI74laYyCIJXX VICTGzUSDjba8mWOmZ6pwx2TNFLnOUDWmL4Jw1xVr33XCFNeQCs4ToaZ+yCw0JJomQc0 WgYtAX0TQHWU0yOr2kzY6AIOC/RB4V1oM3sY0V+gCGfEVlz8sfvpE6obyCwWX/xYEsTZ wgxuZ8I0gpIv2/dCFuO/C+8hUI0wS8xxT0UawmFLfsnFs1oIbuW1OJs6R5Bnr4T8LKVN WnUWuOfTXsPR/OvYLOuLlwW6mEhpAR23sbVG2C5RbxikBX/MMchD97uK+UM3BKEQqBXu P4LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tobin.cc header.s=fm2 header.b=GBREfe+I; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=UT3HKVRB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j14si12094602pgg.44.2019.02.12.18.38.01; Tue, 12 Feb 2019 18:38:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@tobin.cc header.s=fm2 header.b=GBREfe+I; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=UT3HKVRB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730553AbfBMBN4 (ORCPT + 99 others); Tue, 12 Feb 2019 20:13:56 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:35425 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729726AbfBMBN4 (ORCPT ); Tue, 12 Feb 2019 20:13:56 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 5D38021D07; Tue, 12 Feb 2019 20:13:53 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 12 Feb 2019 20:13:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tobin.cc; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=/vsni0qI4nIlP2MtRM9/uEjnMvw ObGlkgdfO3PfJISo=; b=GBREfe+IaNu9MN4ysUkKzXc3q741zVmIMyvcTElSMab qaOnWrhH5L9k/zSktZt0FD4MuXuZ4f7CXUDokMK3myFif9Co5FytGYVnTt6pafv1 cbM/bLrhOGpkyspnYUj1jugnmDQD8OySP/olkAOiX0nKRR4wY8WxLWS3llHsul17 dpVDirkVEllNcBhQqviXah2SkimT6Q9KICjczpbTSgBh9AVos7MKtZVOULptdnQG QaLbteNgo1RNUuXwqS54vBXANYBse7Io5pLmvKefI/y44ChDU5NS0n5laA893IEv CF/QbagS3F0xUc7NEmpslh4rJ9w0vVXaz9Y5vqTgwGQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=/vsni0 qI4nIlP2MtRM9/uEjnMvwObGlkgdfO3PfJISo=; b=UT3HKVRBITRkJypVgGFLED qv18xzFsnV5L6iem9iX3/ckmxTmJU5ClGacny9G/5hnU5YiZw9Jjddx1E3WTBQqC gMVHdp+0IQ2mdIjI0q+xYEo/Ul3EDc/Ke6HdmspWzADm/BEPe1dFD04LrVyOAaXz qMvABH6fg+VdzFTsXabpmauexRDf2hM4kr29GDH+RQe439f/bK2WaGx2M1eWk8GX pkY/hoIC+dNbuOTzGWtAnrixRkbokCANGhyK04INmyvuqGNx32Q4aG0UCsbXr/tS IYayXARX0qPcGKuHIwnMdc8AMRfGyE0M22aHjzoMD/IDl3KXe7KRZ9Eq4rQvUMeg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledruddtvddgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecufghrlhcuvffnffculdeftddmnecujfgurhepfffhvffukfhfgggtuggjofgfse httdertdforedvnecuhfhrohhmpedfvfhosghinhcuvedrucfjrghrughinhhgfdcuoehm vgesthhosghinhdrtggtqeenucfkphepuddukedrvdduuddrudelledruddtgeenucfrrg hrrghmpehmrghilhhfrhhomhepmhgvsehtohgsihhnrdgttgenucevlhhushhtvghrufhi iigvpedt X-ME-Proxy: Received: from localhost (ppp118-211-199-104.bras1.syd2.internode.on.net [118.211.199.104]) by mail.messagingengine.com (Postfix) with ESMTPA id 0B255E4693; Tue, 12 Feb 2019 20:13:51 -0500 (EST) Date: Wed, 13 Feb 2019 12:13:40 +1100 From: "Tobin C. Harding" To: "Tobin C. Harding" Cc: Matthew Wilcox , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xarray: Document erasing entries during iteration Message-ID: <20190213011340.GA29295@eros.localdomain> References: <20190212072958.17373-1-tobin@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190212072958.17373-1-tobin@kernel.org> X-Mailer: Mutt 1.11.3 (2019-02-01) User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 12, 2019 at 06:29:58PM +1100, Tobin C. Harding wrote: > The XArray is, in a way, a replacement data structure for linked lists, > as such, on first use developers may wonder if it is safe to remove > items while iterating over the array. > > For example, this is fine: > > DEFINE_XARRAY(things); > > void cleanup() > { > struct thing *thing; > unsigned long index; > > xa_for_each(&things, index, thing) > xa_erase(&things, index); > } > > Document this feature explicitly in the docs and also for the macro > definition. > > Signed-off-by: Tobin C. Harding > --- > > Hi Willy, > > I had my first go using the XArray today and during that I wondered if > it was safe to remove items during iteration. Conceptually it seems > fine and it seemed to work just fine in code - is this something people > should not be doing for any reason? Is this the best way to traverse > the tree and get every thing just to erase it? Are we even supposed to > be thinking this is a tree or should we just be thinking it is an array? > > (As you might have guessed I _still_ don't know exactly how a radix tree > works :) > > Oh, and FTR the XArray is hot - good effort man. > > thanks, > Tobin. > > > Documentation/core-api/xarray.rst | 3 ++- > include/linux/xarray.h | 2 ++ > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/Documentation/core-api/xarray.rst b/Documentation/core-api/xarray.rst > index 5d54b27c6eba..2578e0bdaa17 100644 > --- a/Documentation/core-api/xarray.rst > +++ b/Documentation/core-api/xarray.rst > @@ -97,7 +97,8 @@ You can copy entries out of the XArray into a plain array by calling > :c:func:`xa_extract`. Or you can iterate over the present entries in > the XArray by calling :c:func:`xa_for_each`. You may prefer to use > :c:func:`xa_find` or :c:func:`xa_find_after` to move to the next present > -entry in the XArray. > +entry in the XArray. It is safe to call :c:func:`xa_release` on entries > +as you iterate over the array using :c:func:`xa_for_each`. Re-reading documentation this line may be in the wrong place . Perhaps it would be better added at the end of the 'Normal API' section? Finally, you can remove all entries from an XArray by calling :c:func:`xa_destroy`. If the XArray entries are pointers, you may wish to free the entries first. You can do this by iterating over all present entries in the XArray using the :c:func:`xa_for_each` iterator. It is safe to call :c:func:`xa_erase` while iterating the array. I'm a bit lazy when I read docs and soon as I find an answer I stop reading (bad Tobin) so it might be nice to tie the first mention of xa_for_each with the comment on xa_erase _and_ the section on xa_destroy. Man, writing docs is never as easy as it first appears. Oh and I sent v2 already but it hasn't shown up in my inbox so replying here on v1. thanks, Tobin.