mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
xarray: Replace exceptional entries
Introduce xarray value entries and tagged pointers to replace radix tree exceptional entries. This is a slight change in encoding to allow the use of an extra bit (we can now store BITS_PER_LONG - 1 bits in a value entry). It is also a change in emphasis; exceptional entries are intimidating and different. As the comment explains, you can choose to store values or pointers in the xarray and they are both first-class citizens. Signed-off-by: Matthew Wilcox <willy@infradead.org> Reviewed-by: Josef Bacik <jbacik@fb.com>
This commit is contained in:
@@ -28,34 +28,26 @@
|
||||
#include <linux/rcupdate.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/xarray.h>
|
||||
|
||||
/*
|
||||
* The bottom two bits of the slot determine how the remaining bits in the
|
||||
* slot are interpreted:
|
||||
*
|
||||
* 00 - data pointer
|
||||
* 01 - internal entry
|
||||
* 10 - exceptional entry
|
||||
* 11 - this bit combination is currently unused/reserved
|
||||
* 10 - internal entry
|
||||
* x1 - value entry
|
||||
*
|
||||
* The internal entry may be a pointer to the next level in the tree, a
|
||||
* sibling entry, or an indicator that the entry in this slot has been moved
|
||||
* to another location in the tree and the lookup should be restarted. While
|
||||
* NULL fits the 'data pointer' pattern, it means that there is no entry in
|
||||
* the tree for this index (no matter what level of the tree it is found at).
|
||||
* This means that you cannot store NULL in the tree as a value for the index.
|
||||
* This means that storing a NULL entry in the tree is the same as deleting
|
||||
* the entry from the tree.
|
||||
*/
|
||||
#define RADIX_TREE_ENTRY_MASK 3UL
|
||||
#define RADIX_TREE_INTERNAL_NODE 1UL
|
||||
|
||||
/*
|
||||
* Most users of the radix tree store pointers but shmem/tmpfs stores swap
|
||||
* entries in the same tree. They are marked as exceptional entries to
|
||||
* distinguish them from pointers to struct page.
|
||||
* EXCEPTIONAL_ENTRY tests the bit, EXCEPTIONAL_SHIFT shifts content past it.
|
||||
*/
|
||||
#define RADIX_TREE_EXCEPTIONAL_ENTRY 2
|
||||
#define RADIX_TREE_EXCEPTIONAL_SHIFT 2
|
||||
#define RADIX_TREE_INTERNAL_NODE 2UL
|
||||
|
||||
static inline bool radix_tree_is_internal_node(void *ptr)
|
||||
{
|
||||
@@ -83,11 +75,10 @@ static inline bool radix_tree_is_internal_node(void *ptr)
|
||||
|
||||
/*
|
||||
* @count is the count of every non-NULL element in the ->slots array
|
||||
* whether that is an exceptional entry, a retry entry, a user pointer,
|
||||
* whether that is a value entry, a retry entry, a user pointer,
|
||||
* a sibling entry or a pointer to the next level of the tree.
|
||||
* @exceptional is the count of every element in ->slots which is
|
||||
* either radix_tree_exceptional_entry() or is a sibling entry for an
|
||||
* exceptional entry.
|
||||
* either a value entry or a sibling of a value entry.
|
||||
*/
|
||||
struct radix_tree_node {
|
||||
unsigned char shift; /* Bits remaining in each slot */
|
||||
@@ -268,17 +259,6 @@ static inline int radix_tree_deref_retry(void *arg)
|
||||
return unlikely(radix_tree_is_internal_node(arg));
|
||||
}
|
||||
|
||||
/**
|
||||
* radix_tree_exceptional_entry - radix_tree_deref_slot gave exceptional entry?
|
||||
* @arg: value returned by radix_tree_deref_slot
|
||||
* Returns: 0 if well-aligned pointer, non-0 if exceptional entry.
|
||||
*/
|
||||
static inline int radix_tree_exceptional_entry(void *arg)
|
||||
{
|
||||
/* Not unlikely because radix_tree_exception often tested first */
|
||||
return (unsigned long)arg & RADIX_TREE_EXCEPTIONAL_ENTRY;
|
||||
}
|
||||
|
||||
/**
|
||||
* radix_tree_exception - radix_tree_deref_slot returned either exception?
|
||||
* @arg: value returned by radix_tree_deref_slot
|
||||
|
Reference in New Issue
Block a user