From 652615dcb71c32901810a0830dcfa7636c92ed70 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 24 Mar 2013 16:43:07 +0000 Subject: [PATCH] Micro-optimize the control flow in a few places. Eliminate a panic call that could never be reached in vm_radix_insert(). (If the pointer being checked by the panic call were ever NULL, the immmediately preceding loop would have already crashed on a NULL pointer dereference.) Reviewed by: attilio (an earlier version) Sponsored by: EMC / Isilon Storage Division --- sys/vm/vm_radix.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sys/vm/vm_radix.c b/sys/vm/vm_radix.c index 3909b9101547..61eb61e69df2 100644 --- a/sys/vm/vm_radix.c +++ b/sys/vm/vm_radix.c @@ -310,7 +310,9 @@ vm_radix_reclaim_allnodes_int(struct vm_radix_node *rnode) { int slot; - for (slot = 0; slot < VM_RADIX_COUNT && rnode->rn_count != 0; slot++) { + KASSERT(rnode->rn_count <= VM_RADIX_COUNT, + ("vm_radix_reclaim_allnodes_int: bad count in rnode %p", rnode)); + for (slot = 0; rnode->rn_count != 0; slot++) { if (rnode->rn_child[slot] == NULL) continue; if (vm_radix_node_page(rnode->rn_child[slot]) == NULL) @@ -414,9 +416,7 @@ vm_radix_insert(struct vm_radix *rtree, vm_page_t page) vm_radix_addpage(rnode, index, 0, page); return; } - while (rnode != NULL) { - if (vm_radix_keybarr(rnode, index)) - break; + do { slot = vm_radix_slot(index, rnode->rn_clev); m = vm_radix_node_page(rnode->rn_child[slot]); if (m != NULL) { @@ -437,9 +437,7 @@ vm_radix_insert(struct vm_radix *rtree, vm_page_t page) return; } rnode = rnode->rn_child[slot]; - } - if (rnode == NULL) - panic("%s: path traversal ended unexpectedly", __func__); + } while (!vm_radix_keybarr(rnode, index)); /* * Scan the trie from the top and find the parent to insert @@ -748,8 +746,8 @@ vm_radix_reclaim_allnodes(struct vm_radix *rtree) root = vm_radix_getroot(rtree); if (root == NULL) return; - vm_radix_reclaim_allnodes_int(root); vm_radix_setroot(rtree, NULL); + vm_radix_reclaim_allnodes_int(root); } #ifdef DDB