Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3522409imj; Mon, 11 Feb 2019 23:32:02 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ379sTUVDVQ6gyGoql0fOg8gC1abbiyOZNpaD8Xu0KReOH+wZH0kJS5jIrCQ+Zu7ZBHgp0 X-Received: by 2002:a63:4002:: with SMTP id n2mr2380800pga.137.1549956722804; Mon, 11 Feb 2019 23:32:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549956722; cv=none; d=google.com; s=arc-20160816; b=U+aoSVxvgd0bSu4KQRMvCuZbTXKNcKAiaM9F0Gi7Z2pp2GUgAHFCPpSnYzxmkVgc86 rUcJSJ8EYDI3+SsIUssiFf8VF8QvYTE+jXh8t+ZU8PH2sWrrS6JHsGwDA+zD82HQBFiH gADAb+trvXvfn1FGRg7nNq+0KbbzXpAwdxo9c6rCSAiaJ2xo3lRsAqB59I5HETPy8aLj /rr5vpLZ691NPUVr2Z7FrFplJwCNN2pgXzBDVTCnfIJgyZsNGkYLH0SZ31ak5ogGNIK0 JARPULsfgIS9EMnqHr0oWqDncE/iBc5kQA870teUmPz2cy69hmZr/wIVWiNaAYO3n/T+ MJbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wrJoYBO97LlCKkoipjuoC/+8a4eB+DEm6P5r7lEfh4k=; b=lDB19f3wdy0PDJiIqzO+Z1+j2MmWm7uQGC+atcOuuUwEfIm+t5QV3wDZYq02J3HuR/ e8QBHRIVB+8LHl/30dsAF+M6Wxbf2Hz39TCq2NVTTNzD+iat4clmvcje2Nf2+SNuxmOx Y2Fqjm4396/Mp7K6TlLINYlSmI5sYOco6a4iShMO9zM4YwpjMr6F+EuyZqzlNBlbPkhJ P3X9GxaE9de+2AWsvC1q67NhrRw8iLP2d+B0Q5l8Utg0AagES5pSmh+hnvfNLSYc+2B9 Q/Yh3Bm6M5NbmIQqppvo/8Chs9YUj3cXL1kJcmdEUhiwPLOZnA4s5Nt9NrJ80ozJjbyn 7SUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=C+nUTRMs; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w31si13027737pla.308.2019.02.11.23.31.46; Mon, 11 Feb 2019 23:32:02 -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=@messagingengine.com header.s=fm2 header.b=C+nUTRMs; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbfBLHaW (ORCPT + 99 others); Tue, 12 Feb 2019 02:30:22 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:58007 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbfBLHaV (ORCPT ); Tue, 12 Feb 2019 02:30:21 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 7538E231BB; Tue, 12 Feb 2019 02:30:20 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 12 Feb 2019 02:30:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=wrJoYBO97LlCKkoip juoC/+8a4eB+DEm6P5r7lEfh4k=; b=C+nUTRMs5xJcTWDTuihsSpFY2/U9x+D/F bRQk86XyodKJg84SECJSaWxNnPvSeDsxa7JIvCxMj7QBoIFhxl/28zxmP1zL0k1P kJKUDNQkdPeorLVNUWGHkyCbL2y0CYzi3JGpQHLcDF1aWHXzcDeKBxvFJcrpNHZC COc678TvnVkYaeby/7IkQ1/wP1EhyoN4rZcUMF35PAZlsyGA37/SPqhgPZN5iXDt yoeesvha4wGqLUZltAB58SEjCDMigw6CyiLUatzmjlKTnfemPi3hr8tDZC0FTkpk nBnLTWpU4Y6eYJic1NkFmxStr6EyMeZrXjynvrlspGMRinJxcutXQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledruddttddguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecu fedttdenucenucfjughrpefhvffufffkofgggfestdekredtredttdenucfhrhhomhepfd fvohgsihhnucevrdcujfgrrhguihhnghdfuceothhosghinheskhgvrhhnvghlrdhorhhg qeenucfkphepuddvgedrudejuddrvdefrdduheenucfrrghrrghmpehmrghilhhfrhhomh epthhosghinheskhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from eros.localdomain (124-171-23-15.dyn.iinet.net.au [124.171.23.15]) by mail.messagingengine.com (Postfix) with ESMTPA id 0137CE4597; Tue, 12 Feb 2019 02:30:17 -0500 (EST) From: "Tobin C. Harding" To: Matthew Wilcox Cc: "Tobin C. Harding" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] xarray: Document erasing entries during iteration Date: Tue, 12 Feb 2019 18:29:58 +1100 Message-Id: <20190212072958.17373-1-tobin@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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`. 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