linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tobin C. Harding" <me@tobin.cc>
To: "Tobin C. Harding" <tobin@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] xarray: Document erasing entries during iteration
Date: Wed, 13 Feb 2019 12:13:40 +1100	[thread overview]
Message-ID: <20190213011340.GA29295@eros.localdomain> (raw)
In-Reply-To: <20190212072958.17373-1-tobin@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 <tobin@kernel.org>
> ---
> 
> 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.

      parent reply	other threads:[~2019-02-13  1:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12  7:29 [PATCH] xarray: Document erasing entries during iteration Tobin C. Harding
2019-02-12 13:51 ` Matthew Wilcox
2019-02-13 14:47   ` Wei Yang
2019-02-13 16:12     ` Matthew Wilcox
2019-02-14 22:16       ` Wei Yang
2019-02-14 22:33         ` Matthew Wilcox
2019-02-16 21:53           ` Wei Yang
2019-02-13  1:13 ` Tobin C. Harding [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190213011340.GA29295@eros.localdomain \
    --to=me@tobin.cc \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tobin@kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).