--- memhotplug-dave/lib/radix-tree.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-) diff -puN lib/radix-tree.c~radix-tree-count lib/radix-tree.c --- memhotplug/lib/radix-tree.c~radix-tree-count 2006-02-21 10:50:25.000000000 -0800 +++ memhotplug-dave/lib/radix-tree.c 2006-02-21 10:51:00.000000000 -0800 @@ -538,7 +538,9 @@ __lookup(struct radix_tree_root *root, v for (i = index & RADIX_TREE_MAP_MASK; i < RADIX_TREE_MAP_SIZE; i++) { index++; if (slot->slots[i]) { - results[nr_found++] = slot->slots[i]; + if (results) + results[nr_found] = slot->slots[i]; + nr_found++; if (nr_found == max_items) goto out; } @@ -559,6 +561,9 @@ out: * them at *@results and returns the number of items which were placed at * *@results. * + * If *@results is NULL, the function will return a count of pages found, + * without any actual results. + * * The implementation is naive. */ unsigned int @@ -572,10 +577,13 @@ radix_tree_gang_lookup(struct radix_tree while (ret < max_items) { unsigned int nr_found; unsigned long next_index; /* Index of next search */ + void *cur_result = NULL; if (cur_index > max_index) break; - nr_found = __lookup(root, results + ret, cur_index, + if (results) + cur_result = results + ret; + nr_found = __lookup(root, cur_result, cur_index, max_items - ret, &next_index); ret += nr_found; if (next_index == 0) @@ -586,6 +594,13 @@ radix_tree_gang_lookup(struct radix_tree } EXPORT_SYMBOL(radix_tree_gang_lookup); +unsigned int +radix_tree_lookup_count(struct radix_tree_root *root + unsigned long first_index) +{ + return radix_tree_gang_lookup(root, NULL, first_index, ~0); +} + /* * FIXME: the two tag_get()s here should use find_next_bit() instead of * open-coding the search. _