From: Brian Foster <bfoster@redhat.com>
To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: ikent@redhat.com, onestero@redhat.com, willy@infradead.org
Subject: [PATCH v2 2/4] idr: support optional id tagging
Date: Mon, 11 Jul 2022 09:52:35 -0400 [thread overview]
Message-ID: <20220711135237.173667-3-bfoster@redhat.com> (raw)
In-Reply-To: <20220711135237.173667-1-bfoster@redhat.com>
Certain idr users can benefit from generic tagging support of the
underlying radix-tree (or xarray) data structure. For example, a
readdir of the /proc root dir performs an inefficient walk of the
pid namespace idr tree. This involves checking the entry of every
allocated id for a group leader task association. Expose a simple,
single tag interface for idr users to facilitate more efficient
scans in situations like this.
Signed-off-by: Brian Foster <bfoster@redhat.com>
---
include/linux/idr.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/include/linux/idr.h b/include/linux/idr.h
index a0dce14090a9..44e8bb287d0e 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -27,6 +27,7 @@ struct idr {
* to users. Use tag 0 to track whether a node has free space below it.
*/
#define IDR_FREE 0
+#define IDR_TAG 1
/* Set the IDR flag and the IDR_FREE tag */
#define IDR_RT_MARKER (ROOT_IS_IDR | (__force gfp_t) \
@@ -174,6 +175,31 @@ static inline void idr_preload_end(void)
local_unlock(&radix_tree_preloads.lock);
}
+static inline void idr_set_tag(struct idr *idr, unsigned long id)
+{
+ radix_tree_tag_set(&idr->idr_rt, id - idr->idr_base, IDR_TAG);
+}
+
+static inline bool idr_get_tag(struct idr *idr, unsigned long id)
+{
+ return radix_tree_tag_get(&idr->idr_rt, id - idr->idr_base, IDR_TAG);
+}
+
+/*
+ * Find the next id with the internal tag set.
+ */
+static inline void *idr_get_next_tag(struct idr *idr, unsigned long id)
+{
+ unsigned int ret;
+ void *entry;
+
+ ret = radix_tree_gang_lookup_tag(&idr->idr_rt, &entry,
+ id - idr->idr_base, 1, IDR_TAG);
+ if (ret != 1)
+ return NULL;
+ return entry;
+}
+
/**
* idr_for_each_entry() - Iterate over an IDR's elements of a given type.
* @idr: IDR handle.
--
2.35.3
next prev parent reply other threads:[~2022-07-11 13:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 13:52 [PATCH v2 0/4] proc: improve root readdir latency with many threads Brian Foster
2022-07-11 13:52 ` [PATCH v2 1/4] radix-tree: propagate all tags in idr tree Brian Foster
2022-07-11 13:52 ` Brian Foster [this message]
2022-07-11 13:52 ` [PATCH v2 3/4] pid: tag pids associated with group leader tasks Brian Foster
2022-07-11 13:52 ` [PATCH v2 4/4] procfs: use efficient tgid pid search on root readdir Brian Foster
2022-07-11 20:19 ` [PATCH v2 0/4] proc: improve root readdir latency with many threads Matthew Wilcox
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=20220711135237.173667-3-bfoster@redhat.com \
--to=bfoster@redhat.com \
--cc=ikent@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=onestero@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.