Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	Shardul Bankar <shardul.b@mpiricsoftware.com>,
	"David Hildenbrand (ARM)" <david@kernel.org>,
	Dev Jain <dev.jain@arm.com>,
	janak@mpiricsoftware.com, Jinjiang Tu <tujinjiang@huawei.com>
Subject: [PATCH 2/2] lib/test_xarray: check unused spare node after range creation
Date: Sat, 14 Nov 2026 19:16:57 -0800	[thread overview]
Message-ID: <2dfabfd9476542e39c7d5473a6597208.2@linux-foundation.org> (raw)
In-Reply-To: <2dfabfd9476542e39c7d5473a6597208.0@linux-foundation.org>

Shardul Bankar's "[PATCH v4] lib: xarray: free unused spare node in
xas_create_range()" [1] releases a spare node left over after range
creation.  Exercise the case without depending on allocator failures or
timing: let xas_nomem() reserve a node, then populate the relevant XArray
node through a separate operation before xas_create_range() retries.

Check that the retry succeeds and releases the unused spare node.

Link: https://lore.kernel.org/r/20251204142625.1763372-1-shardul.b@mpiricsoftware.com [1]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Shardul Bankar <shardul.b@mpiricsoftware.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: David Hildenbrand (ARM) <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: <janak@mpiricsoftware.com>
Cc: Jinjiang Tu <tujinjiang@huawei.com>

 lib/test_xarray.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

--- a/lib/test_xarray.c~lib-test_xarray-check-unused-spare-node-after-range-creation
+++ a/lib/test_xarray.c
@@ -1834,6 +1834,34 @@ static noinline void check_create_range_
 	xa_destroy(xa);
 }
 
+#ifdef CONFIG_XARRAY_MULTI
+static noinline void check_create_range_spare(struct xarray *xa)
+{
+	XA_STATE_ORDER(xas, xa, 0, XA_CHUNK_SHIFT);
+	bool spare_left;
+
+	XA_BUG_ON(xa, !xa_empty(xa));
+
+	/* Model a failed allocation followed by a successful xas_nomem(). */
+	xas_set_err(&xas, -ENOMEM);
+	XA_BUG_ON(xa, !xas_nomem(&xas, GFP_KERNEL));
+
+	/* Model another user populating the tree before the retry. */
+	xa_insert_index(xa, 0);
+	xa_insert_index(xa, 1);
+
+	xas_lock(&xas);
+	xas_create_range(&xas);
+	xas_unlock(&xas);
+
+	XA_BUG_ON(xa, xas_error(&xas));
+	spare_left = xas.xa_alloc != NULL;
+	xas_destroy(&xas);
+	XA_BUG_ON(xa, spare_left);
+	xa_destroy(xa);
+}
+#endif
+
 static noinline void check_create_range(struct xarray *xa)
 {
 	unsigned int order;
@@ -1867,6 +1895,9 @@ static noinline void check_create_range(
 	}
 
 	check_create_range_3();
+#ifdef CONFIG_XARRAY_MULTI
+	check_create_range_spare(xa);
+#endif
 }
 
 static noinline void __check_store_range(struct xarray *xa, unsigned long first,
_


      parent reply	other threads:[~2026-11-15  3:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15  3:16 [PATCH 0/2] xarray: free unused spare node after range creation Andrew Morton
2026-11-15  3:16 ` [PATCH 1/2] lib: xarray: free unused spare node in xas_create_range() Andrew Morton
2026-11-15  3:16 ` Andrew Morton [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=2dfabfd9476542e39c7d5473a6597208.2@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=janak@mpiricsoftware.com \
    --cc=linux-mm@kvack.org \
    --cc=shardul.b@mpiricsoftware.com \
    --cc=tujinjiang@huawei.com \
    --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