From: Mateusz Guzik <mjguzik@gmail.com>
To: oleg@redhat.com
Cc: brauner@kernel.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, linux-mm@kvack.org,
Mateusz Guzik <mjguzik@gmail.com>
Subject: [PATCH 1/3] idr: add idr_prealloc_many
Date: Sun, 23 Nov 2025 07:30:52 +0100 [thread overview]
Message-ID: <20251123063054.3502938-2-mjguzik@gmail.com> (raw)
In-Reply-To: <20251123063054.3502938-1-mjguzik@gmail.com>
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
include/linux/idr.h | 1 +
lib/radix-tree.c | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 789e23e67444..c9aeae695442 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -110,6 +110,7 @@ static inline void idr_set_cursor(struct idr *idr, unsigned int val)
#define idr_unlock_irqrestore(idr, flags) \
xa_unlock_irqrestore(&(idr)->idr_rt, flags)
+void idr_preload_many(int nr, gfp_t gfp_mask);
void idr_preload(gfp_t gfp_mask);
int idr_alloc(struct idr *, void *ptr, int start, int end, gfp_t);
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 976b9bd02a1b..2e71024e5323 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1459,6 +1459,22 @@ int radix_tree_tagged(const struct radix_tree_root *root, unsigned int tag)
}
EXPORT_SYMBOL(radix_tree_tagged);
+/**
+ * idr_preload_many - preload for idr_alloc()
+ * @gfp_mask: allocation mask to use for preloading
+ * @nr: how many calls to preload for
+ *
+ * Preallocate memory to use for n calls to idr_alloc(). This function
+ * returns with preemption disabled. It will be enabled by idr_preload_end().
+ */
+void idr_preload_many(int nr, gfp_t gfp_mask)
+{
+ WARN_ON_ONCE(!nr);
+ if (__radix_tree_preload(gfp_mask, nr * IDR_PRELOAD_SIZE))
+ local_lock(&radix_tree_preloads.lock);
+}
+EXPORT_SYMBOL(idr_preload_many);
+
/**
* idr_preload - preload for idr_alloc()
* @gfp_mask: allocation mask to use for preloading
@@ -1468,8 +1484,7 @@ EXPORT_SYMBOL(radix_tree_tagged);
*/
void idr_preload(gfp_t gfp_mask)
{
- if (__radix_tree_preload(gfp_mask, IDR_PRELOAD_SIZE))
- local_lock(&radix_tree_preloads.lock);
+ idr_preload_many(1, gfp_mask);
}
EXPORT_SYMBOL(idr_preload);
--
2.48.1
next prev parent reply other threads:[~2025-11-23 6:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-23 6:30 [PATCH 0/3] further damage-control lack of clone scalability Mateusz Guzik
2025-11-23 6:30 ` Mateusz Guzik [this message]
2025-11-23 6:30 ` [PATCH 2/3] ns: pad refcount Mateusz Guzik
2025-11-23 18:58 ` Oleg Nesterov
2025-11-23 19:47 ` Mateusz Guzik
2025-11-24 18:25 ` Oleg Nesterov
2025-11-23 6:30 ` [PATCH 3/3] pid: only take pidmap_lock once on alloc Mateusz Guzik
2025-11-23 20:09 ` Oleg Nesterov
2025-11-23 22:48 ` Mateusz Guzik
2025-11-23 15:00 ` [PATCH 0/3] further damage-control lack of clone scalability Matthew Wilcox
2025-11-23 16:39 ` Mateusz Guzik
2025-11-23 21:45 ` Matthew Wilcox
2025-11-23 22:33 ` Mateusz Guzik
2025-11-24 4:03 ` Mateusz Guzik
2025-12-03 8:37 ` Mateusz Guzik
2025-12-03 9:18 ` Mateusz Guzik
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=20251123063054.3502938-2-mjguzik@gmail.com \
--to=mjguzik@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=oleg@redhat.com \
/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