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:
@@ -18,9 +18,8 @@
|
||||
*
|
||||
* swp_entry_t's are *never* stored anywhere in their arch-dependent format.
|
||||
*/
|
||||
#define SWP_TYPE_SHIFT(e) ((sizeof(e.val) * 8) - \
|
||||
(MAX_SWAPFILES_SHIFT + RADIX_TREE_EXCEPTIONAL_SHIFT))
|
||||
#define SWP_OFFSET_MASK(e) ((1UL << SWP_TYPE_SHIFT(e)) - 1)
|
||||
#define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
|
||||
#define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1)
|
||||
|
||||
/*
|
||||
* Store a type+offset into a swp_entry_t in an arch-independent format
|
||||
@@ -29,8 +28,7 @@ static inline swp_entry_t swp_entry(unsigned long type, pgoff_t offset)
|
||||
{
|
||||
swp_entry_t ret;
|
||||
|
||||
ret.val = (type << SWP_TYPE_SHIFT(ret)) |
|
||||
(offset & SWP_OFFSET_MASK(ret));
|
||||
ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -40,7 +38,7 @@ static inline swp_entry_t swp_entry(unsigned long type, pgoff_t offset)
|
||||
*/
|
||||
static inline unsigned swp_type(swp_entry_t entry)
|
||||
{
|
||||
return (entry.val >> SWP_TYPE_SHIFT(entry));
|
||||
return (entry.val >> SWP_TYPE_SHIFT);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -49,7 +47,7 @@ static inline unsigned swp_type(swp_entry_t entry)
|
||||
*/
|
||||
static inline pgoff_t swp_offset(swp_entry_t entry)
|
||||
{
|
||||
return entry.val & SWP_OFFSET_MASK(entry);
|
||||
return entry.val & SWP_OFFSET_MASK;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MMU
|
||||
@@ -90,16 +88,13 @@ static inline swp_entry_t radix_to_swp_entry(void *arg)
|
||||
{
|
||||
swp_entry_t entry;
|
||||
|
||||
entry.val = (unsigned long)arg >> RADIX_TREE_EXCEPTIONAL_SHIFT;
|
||||
entry.val = xa_to_value(arg);
|
||||
return entry;
|
||||
}
|
||||
|
||||
static inline void *swp_to_radix_entry(swp_entry_t entry)
|
||||
{
|
||||
unsigned long value;
|
||||
|
||||
value = entry.val << RADIX_TREE_EXCEPTIONAL_SHIFT;
|
||||
return (void *)(value | RADIX_TREE_EXCEPTIONAL_ENTRY);
|
||||
return xa_mk_value(entry.val);
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_DEVICE_PRIVATE)
|
||||
|
Reference in New Issue
Block a user