Skip to content

Commit

Permalink
raxix-tree: introduce CONFIG_RADIX_TREE_MULTIORDER
Browse files Browse the repository at this point in the history
I've been receiving increasingly concerned notes from 0day about how
much my recent changes have been bloating the radix tree.  Make it
happier by only including multiorder support if
CONFIG_TRANSPARENT_HUGEPAGES is set.

This is an independent Kconfig option, so other radix tree users can
also set it if they have a need.

Signed-off-by: Matthew Wilcox <[email protected]>
Reviewed-by: Ross Zwisler <[email protected]>
Cc: Konstantin Khlebnikov <[email protected]>
Cc: Kirill Shutemov <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Neil Brown <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matthew Wilcox authored and torvalds committed May 21, 2016
1 parent 6c4bd68 commit 57578c2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ config INTERVAL_TREE

for more information.

config RADIX_TREE_MULTIORDER
bool

config ASSOCIATIVE_ARRAY
bool
help
Expand Down
26 changes: 18 additions & 8 deletions lib/radix-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
slot = node->slots[offset];
}

#ifdef CONFIG_RADIX_TREE_MULTIORDER
/* Insert pointers to the canonical entry */
if ((shift - order) > 0) {
int i, n = 1 << (shift - order);
Expand All @@ -499,6 +500,7 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
node->count++;
}
}
#endif

if (nodep)
*nodep = node;
Expand Down Expand Up @@ -1469,6 +1471,20 @@ bool __radix_tree_delete_node(struct radix_tree_root *root,
return deleted;
}

static inline void delete_sibling_entries(struct radix_tree_node *node,
void *ptr, unsigned offset)
{
#ifdef CONFIG_RADIX_TREE_MULTIORDER
int i;
for (i = 1; offset + i < RADIX_TREE_MAP_SIZE; i++) {
if (node->slots[offset + i] != ptr)
break;
node->slots[offset + i] = NULL;
node->count--;
}
#endif
}

/**
* radix_tree_delete_item - delete an item from a radix tree
* @root: radix tree root
Expand All @@ -1484,7 +1500,7 @@ void *radix_tree_delete_item(struct radix_tree_root *root,
unsigned long index, void *item)
{
struct radix_tree_node *node;
unsigned int offset, i;
unsigned int offset;
void **slot;
void *entry;
int tag;
Expand Down Expand Up @@ -1513,13 +1529,7 @@ void *radix_tree_delete_item(struct radix_tree_root *root,
radix_tree_tag_clear(root, index, tag);
}

/* Delete any sibling slots pointing to this slot */
for (i = 1; offset + i < RADIX_TREE_MAP_SIZE; i++) {
if (node->slots[offset + i] != ptr_to_indirect(slot))
break;
node->slots[offset + i] = NULL;
node->count--;
}
delete_sibling_entries(node, ptr_to_indirect(slot), offset);
node->slots[offset] = NULL;
node->count--;

Expand Down
1 change: 1 addition & 0 deletions mm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ config TRANSPARENT_HUGEPAGE
bool "Transparent Hugepage Support"
depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE
select COMPACTION
select RADIX_TREE_MULTIORDER
help
Transparent Hugepages allows the kernel to use huge pages and
huge tlb transparently to the applications whenever possible.
Expand Down
1 change: 1 addition & 0 deletions tools/testing/radix-tree/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "../../include/linux/compiler.h"

#define CONFIG_RADIX_TREE_MULTIORDER
#define CONFIG_SHMEM
#define CONFIG_SWAP

Expand Down

0 comments on commit 57578c2

Please sign in to comment.