lib: radix-tree: native accounting of exceptional entries
Subsystems (5)
[email protected]
maintainerPATCH 62/123 lib: radix-tree: native accounting of exceptional entries
From: Johannes Weiner <[email protected]>
Subject: lib: radix-tree: native accounting of exceptional entries
The way the page cache is sneaking shadow entries of evicted pages into the radix tree past the node entry accounting and tracking them manually in the upper bits of node->count is fraught with problems.
These shadow entries are marked in the tree as exceptional entries, which are a native concept to the radix tree. Maintain an explicit counter of exceptional entries in the radix tree node. Subsequent patches will switch shadow entry tracking over to that counter.
DAX and shmem are the other users of exceptional entries. Since slot replacements that change the entry type from regular to exceptional must now be accounted, introduce a __radix_tree_replace() function that does replacement and accounting, and switch DAX and shmem over.
The increase in radix tree node size is temporary. A followup patch switches the shadow tracking to this new scheme and we'll no longer need the upper bits in node->count and shrink that back to one byte.
---
fs/dax.c | 5 ++- include/linux/radix-tree.h | 10 +++++-- lib/radix-tree.c | 46 ++++++++++++++++++++++++++++++++--- mm/shmem.c | 8 +++--- 4 files changed, 57 insertions(+), 12 deletions(-)
fs/dax.c renamed from fs/dax.c~lib-radix-tree-native-accounting-of-exceptional-entries +3 -2
@@ -643,12 +643,13 @@ static void *dax_insert_mapping_entry(st } mapping->nrexceptional++; }else { +struct radix_tree_node *node;void **slot;void *ret; - ret =__radix_tree_lookup (page_tree, index,NULL , &slot); + ret =__radix_tree_lookup (page_tree, index, &node, &slot);WARN_ON_ONCE (ret != entry); -radix_tree_replace_slot (slot, new_entry); +__radix_tree_replace (page_tree, node, slot, new_entry); }if (vmf->flags &FAULT_FLAG_WRITE )radix_tree_tag_set (page_tree, index,PAGECACHE_TAG_DIRTY );
include/linux/radix-tree.h renamed from include/linux/radix-tree.h~lib-radix-tree-native-accounting-of-exceptional-entries +7 -3
@@ -85,9 +85,10 @@ static inline bool radix_tree_is_interna#define RADIX_TREE_COUNT_MASK ((1UL << RADIX_TREE_COUNT_SHIFT) - 1) struct radix_tree_node { - unsigned char shift; /* Bits remaining in each slot */ - unsigned char offset; /* Slot offset in parent */ - unsigned int count; + unsigned char shift; /* Bits remaining in each slot */ + unsigned char offset; /* Slot offset in parent */ + unsigned int count; /* Total entry count */ + unsigned char exceptional; /* Exceptional entry count */ union { struct { /* Used when ascending tree */
@@ -276,6 +277,9 @@ void *__radix_tree_lookup(struct radix_t struct radix_tree_node **nodep, void ***slotp);void *radix_tree_lookup (struct radix_tree_root *,unsigned long );void **radix_tree_lookup_slot (struct radix_tree_root *,unsigned long ); +void __radix_tree_replace (struct radix_tree_root *root, +struct radix_tree_node *node, +void **slot,void *item);bool __radix_tree_delete_node (struct radix_tree_root *root,struct radix_tree_node *node);void *radix_tree_delete_item (struct radix_tree_root *,unsigned long ,void *);
lib/radix-tree.c renamed from lib/radix-tree.c~lib-radix-tree-native-accounting-of-exceptional-entries +43 -3
79 lines not on this page · raw message
mm/shmem.c renamed from mm/shmem.c~lib-radix-tree-native-accounting-of-exceptional-entries +4 -4
@@ -300,18 +300,18 @@ void shmem_uncharge(struct inode *inode,static int shmem_radix_tree_replace (struct address_space *mapping,pgoff_t index,void *expected,void *replacement) { +struct radix_tree_node *node;void **pslot;void *item;VM_BUG_ON (!expected);VM_BUG_ON (!replacement); - pslot =radix_tree_lookup_slot (&mapping->page_tree, index); -if (!pslot) + item =__radix_tree_lookup (&mapping->page_tree, index, &node, &pslot); +if (!item)return -ENOENT ; - item =radix_tree_deref_slot_protected (pslot, &mapping->tree_lock);if (item != expected)return -ENOENT ; -radix_tree_replace_slot (pslot, replacement); +__radix_tree_replace (&mapping->page_tree, node, pslot, replacement);return 0 ; }
_