Skip to content

Commit bb850f4

Browse files
urezkitorvalds
authored andcommitted
mm/vmap: add DEBUG_AUGMENT_PROPAGATE_CHECK macro
This macro adds some debug code to check that the augment tree is maintained correctly, meaning that every node contains valid subtree_max_size value. By default this option is set to 0 and not active. It requires recompilation of the kernel to activate it. Set to 1, compile the kernel. [[email protected]: v4] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Uladzislau Rezki (Sony) <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Joel Fernandes <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Oleksiy Avramchenko <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Thomas Garnier <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 68ad4a3 commit bb850f4

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

mm/vmalloc.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ EXPORT_SYMBOL(vmalloc_to_pfn);
325325

326326
/*** Global kva allocator ***/
327327

328+
#define DEBUG_AUGMENT_PROPAGATE_CHECK 0
329+
328330
#define VM_LAZY_FREE 0x02
329331
#define VM_VM_AREA 0x04
330332

@@ -539,6 +541,48 @@ unlink_va(struct vmap_area *va, struct rb_root *root)
539541
}
540542
}
541543

544+
#if DEBUG_AUGMENT_PROPAGATE_CHECK
545+
static void
546+
augment_tree_propagate_check(struct rb_node *n)
547+
{
548+
struct vmap_area *va;
549+
struct rb_node *node;
550+
unsigned long size;
551+
bool found = false;
552+
553+
if (n == NULL)
554+
return;
555+
556+
va = rb_entry(n, struct vmap_area, rb_node);
557+
size = va->subtree_max_size;
558+
node = n;
559+
560+
while (node) {
561+
va = rb_entry(node, struct vmap_area, rb_node);
562+
563+
if (get_subtree_max_size(node->rb_left) == size) {
564+
node = node->rb_left;
565+
} else {
566+
if (va_size(va) == size) {
567+
found = true;
568+
break;
569+
}
570+
571+
node = node->rb_right;
572+
}
573+
}
574+
575+
if (!found) {
576+
va = rb_entry(n, struct vmap_area, rb_node);
577+
pr_emerg("tree is corrupted: %lu, %lu\n",
578+
va_size(va), va->subtree_max_size);
579+
}
580+
581+
augment_tree_propagate_check(n->rb_left);
582+
augment_tree_propagate_check(n->rb_right);
583+
}
584+
#endif
585+
542586
/*
543587
* This function populates subtree_max_size from bottom to upper
544588
* levels starting from VA point. The propagation must be done
@@ -588,6 +632,10 @@ augment_tree_propagate_from(struct vmap_area *va)
588632
va->subtree_max_size = new_va_sub_max_size;
589633
node = rb_parent(&va->rb_node);
590634
}
635+
636+
#if DEBUG_AUGMENT_PROPAGATE_CHECK
637+
augment_tree_propagate_check(free_vmap_area_root.rb_node);
638+
#endif
591639
}
592640

593641
static void

0 commit comments

Comments
 (0)