Re: Tagged pointers in the XArray
From: Randy Dunlap <hidden>
Date: 2018-08-28 22:39:01
Also in:
linux-fsdevel, lkml
Just a question, please... On 08/28/2018 03:27 PM, Matthew Wilcox wrote:
quoted hunk ↗ jump to hunk
diff --git a/include/linux/xarray.h b/include/linux/xarray.h index c74556ea4258..d1b383f3063f 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h@@ -150,6 +150,54 @@ static inline int xa_err(void *entry) return 0; } +/** + * xa_tag_pointer() - Create an XArray entry for a tagged pointer. + * @p: Plain pointer. + * @tag: Tag value (0, 1 or 3). + *
What's wrong with a tag value of 2? and what happens when one is used? [I don't see anything preventing that.]
+ * If the user of the XArray prefers, they can tag their pointers instead
+ * of storing value entries. Three tags are available (0, 1 and 3).
+ * These are distinct from the xa_tag_t as they are not replicated up
+ * through the array and cannot be searched for.
+ *
+ * Context: Any context.
+ * Return: An XArray entry.
+ */
+static inline void *xa_tag_pointer(void *p, unsigned long tag)
+{
+ return (void *)((unsigned long)p | tag);
+}
+
+/**
+ * xa_untag_pointer() - Turn an XArray entry into a plain pointer.
+ * @entry: XArray entry.
+ *
+ * If you have stored a tagged pointer in the XArray, call this function
+ * to get the untagged version of the pointer.
+ *
+ * Context: Any context.
+ * Return: A pointer.
+ */
+static inline void *xa_untag_pointer(void *entry)
+{
+ return (void *)((unsigned long)entry & ~3UL);
+}
+
+/**
+ * xa_pointer_tag() - Get the tag stored in an XArray entry.
+ * @entry: XArray entry.
+ *
+ * If you have stored a tagged pointer in the XArray, call this function
+ * to get the tag of that pointer.
+ *
+ * Context: Any context.
+ * Return: A tag.
+ */
+static inline unsigned int xa_pointer_tag(void *entry)
+{
+ return (unsigned long)entry & 3UL;
+}thanks, -- ~Randy