lkml.org 
[lkml]   [2009]   [Apr]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/3] radix-tree: add radix_tree_prev_hole()
On Sun, Apr 12, 2009 at 10:29:52AM -0700, Andrew Morton wrote:
> On Sun, 12 Apr 2009 15:19:51 +0800 Wu Fengguang <fengguang.wu@intel.com> wrote:
>
> > +unsigned long radix_tree_prev_hole(struct radix_tree_root *root,
> > + unsigned long index, unsigned long max_scan)
> > +{
> > + unsigned long i;
> > +
> > + for (i = 0; i < max_scan; i++) {
> > + if (!radix_tree_lookup(root, index))
> > + break;
> > + index--;
> > + if (index == LONG_MAX)
> > + break;
> > + }
> > +
> > + return index;
> > +}
>
> argh. This is about as inefficient as we could possibly make it :(

Right, a dumb loop!

> Really, this function should dive into radix-tree internals and walk
> individual radix_tree_node.slots[] arrays. And heck, it can peek at
> radix_tree_node.count and _bypass_ entire nodes, too.

Good idea! In fact I'm planning such a smart version. It will be using
radix_tree_lookup_slot() to access the ->count member, in order to
check if the whole slot can be bypassed.

radix_tree_next_hole() is another optimization candidate.
But that will be a post 2.6.30 stuff.

The current dumb-but-obvious-right version is OK for 2.6.30, because
in most radix_tree_prev_hole() invocations the actual loop count will
be merely 1.

Thanks,
Fengguang


\
 
 \ /
  Last update: 2009-04-13 15:47    [W:1.283 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site