Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3852150imj; Tue, 12 Feb 2019 05:52:28 -0800 (PST) X-Google-Smtp-Source: AHgI3IY9u8WWCjhiX+ZqDzgOc/3cmJ2fU/HAQFgnLIji2o8BzFYlmKbbXO4q4hS6e8IKzYfiIZV3 X-Received: by 2002:aa7:8094:: with SMTP id v20mr4109693pff.37.1549979548370; Tue, 12 Feb 2019 05:52:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549979548; cv=none; d=google.com; s=arc-20160816; b=avYZsGX5D4v5GsFPSvbI+JP0WaL/uVNjegSuk/wVRdEn/nxL4mpLyyxXcYfNDr6wTt 5NKo7jb412fC+iBom6vn+VYs0MIz6d3HxMx5j7q/ELyCiVGtQgVgr19Cu5kd8OGwgqNy rqV+JLDDAnXF5MS3e5q8oqBdY6/QIicN5bKZT129HaRtutW6m5Ad2eOVr/nNosJA+UYF yiTnl883/O6HrOmcnOSVYDoCkQta3xp+5Rgg9YjXlYMyhnU5xcg9KVYywN/DmIm7pPEi Xgla1qcjOfnMRLkenzLQsk8dpnh0cZbmbmUuN0gbI+qx+He+M8XxBKjGbLajllpNmIgN 39Dw== 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; bh=87fOArnzsZbXpqgOTphW64jpmWJ3K5CP7SJkFFXGk2Q=; b=WfMt3kyjbdZOfXjxd/hsbRavbRltty3au7JkAruQrm6JQAHIvvHJbrotmD9Df8SilP ehF3UTvy/CaS7TMRyUKqYesEn+R9rLnVo5HDhAs8jWDBO89EXivZ1GLfnVh/AiAJpp91 M9kioffsKqXUzOqNpS4tbqbagguIjX2DMbem8/Jd29DnDEUC4Iu3nnKpcyBWsdXWjpa3 gBFbJEbQhsD3sKVieqVFAl1cpVT/vWA7yLQuVPTValFsbWufxIH53AQZuRlUVEjndwWf mzFM7oKFdPoTMw9fBrUti4xQRtrZpHbNmXaWPhaQxT5m3yUrP30FxsRBYfsACG2X/OHA w+iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=gyxqr3ni; 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 r3si13529467plb.421.2019.02.12.05.52.12; Tue, 12 Feb 2019 05:52:28 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=gyxqr3ni; 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 S1730004AbfBLNva (ORCPT + 99 others); Tue, 12 Feb 2019 08:51:30 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:45972 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727428AbfBLNva (ORCPT ); Tue, 12 Feb 2019 08:51:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=87fOArnzsZbXpqgOTphW64jpmWJ3K5CP7SJkFFXGk2Q=; b=gyxqr3niwQ0yTJkKb5q1BnhXH HwgtahLGf4M0eoxvx8cl5Xz1wZPPhWuAyvL2iHCD2+vFeRMI0aeuaQoc8zK7kYEohhazLExIbmJxp BsZc1OPw+mxBitMaVvv6eL4hWeGx3Hwl+xq6XvU2PQDY8M7VNKEQTd7+O6S2/gAmrX4aE5jo1Znzk mH6hKWQ9mjD+B3JtWPqUQqZdl3aCeg4o5sppcSxdDsq6IFl3XUOLNc8Q04jKzYAESUskX1g9rtcGW V5Ux+Hd/Ktg5y07xoPptA4DAntBLV8hEmxqYHGyzIGddtCHKrCGPdcHaj6aF0RSmZ1fTVr/WZzy1s B2pBeTU4w==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gtYTB-0005lb-TE; Tue, 12 Feb 2019 13:51:29 +0000 Date: Tue, 12 Feb 2019 05:51:29 -0800 From: Matthew Wilcox To: "Tobin C. Harding" Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xarray: Document erasing entries during iteration Message-ID: <20190212135129.GL12668@bombadil.infradead.org> 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> User-Agent: Mutt/1.9.2 (2017-12-15) 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: > 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? You should be thinking it's an array. I've done everything I can to hide the fact that it's implemented as a tree because it's conceptually an array. The xa_for_each() iterator is designed to be extremely robust, at the expense of some performance. The only state it keeps is the @index, so you can do anything you like to the XArray during the iteration. It's definitely worth being clearer in the documentation, for the benefit of people who're wondering what the equivalent of list_for_each_entry_safe() is. So I'll apply this patch in a day or two unless anybody has further comment on it. > (As you might have guessed I _still_ don't know exactly how a radix tree > works :) That is _fine_. As you know I hope to get rid of the radix tree soon ;-) > 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`. that's spelled `xa_erase` ;-) > Calling :c:func:`xa_store_range` stores the same entry in a range > of indices. If you do this, some of the other operations will behave > diff --git a/include/linux/xarray.h b/include/linux/xarray.h > index 5d9d318bcf7a..1f8974281a0a 100644 > --- a/include/linux/xarray.h > +++ b/include/linux/xarray.h > @@ -407,6 +407,8 @@ static inline bool xa_marked(const struct xarray *xa, xa_mark_t mark) > * you should use the xas_for_each() iterator instead. The xas_for_each() > * iterator will expand into more inline code than xa_for_each(). > * > + * It is safe to erase entries from the XArray as you iterate over it. > + * > * Context: Any context. Takes and releases the RCU lock. > */ > #define xa_for_each(xa, index, entry) \ > -- > 2.20.1 >