Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp228907imj; Wed, 13 Feb 2019 07:23:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IaZjgy3RhHfSOgqUGjLbimY4kRqyQg0FZBadt53ohdOyiSXbs9rtMFFUr1+bJVWHdhjwD1A X-Received: by 2002:a63:6c43:: with SMTP id h64mr939963pgc.22.1550071430052; Wed, 13 Feb 2019 07:23:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550071430; cv=none; d=google.com; s=arc-20160816; b=WMyfhJYgiSeD/vWcw4FtxPTFOl1oK35XBGMPyuKGY+OrcoxofwuA99XATax5cMc6yg nZfbRQeTuCeDQqmrImeXEPPLu2vFjLe57abP1K6ZIyM1advV4Oxz51COl4ZjEs+ueFN7 ELSj6aMBhI7Cw2ZzuLGIe6Jl3ZBkvi48zQ0Ppz6+UhuRcSuWB45lEDQ7la61OSolZzMW btwSpzVhrSM5rWYXTv5prpYwH0uWqDjS5n5xBVLgxz7RQWE79g2LDI7uw+QqABwHc10G qJTaCqMljtjTL9V0E1pzWT96jigQj81LN9N2MKp2pho+E3ZuIYX5UYAMijUp7JZFfdUt IX/g== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=7IBNKyjatn8X3VFcQkUE2ehE7yrXUj9SXz162g4Ei+U=; b=W34skl3vA+gJdaUBcay1krDykjImK48wvWitTkY8iF9/xAXJ/9n3Opm9zzEikBW559 KhIaRpE3YPFgZ+sx4ihQ9YOzDduOyt8iSTT7Xwg8a6ftny1r1OL+xSINqwALIJcQoWiM uIlaPkjLwSTRZVLsu4U/+DGrTkjhO6qZ8I8V7XIDE5dwG1KEa/Us8yZZze/pSAnMTKvv 9bBPghgieNOlxwuH8cLd/o82Et3HD+dJ5Aitmi7RIITcHKSkPa9qqk5Bloa/iUGHNtIR nxFYiRKgZTlJwOaVLkkCiZV0lB10bZOxfIWtlHy4CvaxUnG25lCf0yict08BLA0V1VLK NHpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="vAMwh8g/"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si16948738pld.249.2019.02.13.07.23.33; Wed, 13 Feb 2019 07:23:50 -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=@gmail.com header.s=20161025 header.b="vAMwh8g/"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390026AbfBMOrs (ORCPT + 99 others); Wed, 13 Feb 2019 09:47:48 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:42075 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726573AbfBMOrs (ORCPT ); Wed, 13 Feb 2019 09:47:48 -0500 Received: by mail-ed1-f68.google.com with SMTP id r15so2135532eds.9; Wed, 13 Feb 2019 06:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=7IBNKyjatn8X3VFcQkUE2ehE7yrXUj9SXz162g4Ei+U=; b=vAMwh8g/XishWbNX2Y9mkE/7sVAGEtfqyzIQFKBMK0Bhk0uM736PtD49W4PocooglJ o9MaxCWqjhZSrFTbV1p4Bhsu/046P4RuLNCJU5qEiBuM0Tgic6Tnm8MZpCe9WJmFJQFh 6KEM9/Xx/MFYqiQWsr3r7h9iC6t370cWx2/eFq6f9KfILvhsL+plyczp9156E49cKIiz hQeQawJSyiWXXVJrWDBNTcyxHdW/7pbYVH6mmE2n63WKaihun9iDaz2wsWh/ic9AII4u ySvZjGJSKNjuidlana+jJfXSDX4G4OqcD6u4ftKrJL838nl3eebLwwetdFpwwFw37yMK DE4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=7IBNKyjatn8X3VFcQkUE2ehE7yrXUj9SXz162g4Ei+U=; b=AimAjPkvJivVahHCxHtPf9or8ZSL2AGLhzD3LHKqtS70lHQmQqEmXv9ejcWzDYvUac SQR7fXS7LFTEaQcy7KRwSoAMrZ2LvFjkuh+fQJfCjs9dm5RGUG0icgpls35nnbIJQS2/ TDH9Ypb37c2yy4QE06srNWnbrp5Fd1QXP488kJQo/qneSLv1suJ6lQtLVi9AGCj37BLR E63GV6ri3Qoex8pXrthCeunYHYcb+8eA21Nr5zJON95CybQj+vSF5zU+qsXkuljX4bAE TELY7PHuzhOYGkFgFWVO3WZq+I0cCEq3djFgtCqxj8RR7+uZoIMkhx38A707A2YPhI/S 3+NQ== X-Gm-Message-State: AHQUAuZjFN3T5Y0Mrw39SSnmJAgAoXoJWmjaJPcmC4YwRXCPIwp+cbDF rDR4Z9qZnSQmQ4WG+8M42NU= X-Received: by 2002:aa7:c6c6:: with SMTP id b6mr709742eds.38.1550069266111; Wed, 13 Feb 2019 06:47:46 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id l25sm4649849edr.45.2019.02.13.06.47.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Feb 2019 06:47:45 -0800 (PST) Date: Wed, 13 Feb 2019 14:47:44 +0000 From: Wei Yang To: Matthew Wilcox Cc: "Tobin C. Harding" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xarray: Document erasing entries during iteration Message-ID: <20190213144744.ifejzbxrbaltivwc@master> Reply-To: Wei Yang References: <20190212072958.17373-1-tobin@kernel.org> <20190212135129.GL12668@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190212135129.GL12668@bombadil.infradead.org> User-Agent: NeoMutt/20170113 (1.7.2) 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 05:51:29AM -0800, Matthew Wilcox wrote: >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 ;-) > You mean replace radix tree in whole kernel? That would be a big effort. BTW, have we compared the performance difference? >> 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 >> -- Wei Yang Help you, Help me