md: Binary search in linear raid
authorSandeep K Sinha <sandeepksinha@gmail.com>
Tue, 16 Jun 2009 06:57:08 +0000 (16:57 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 16 Jun 2009 06:57:08 +0000 (16:57 +1000)
Replace the linear search with binary search in which_dev.

Signed-off-by: Sandeep K Sinha <sandeepksinha@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/linear.c

index 529a3d3..9b02a73 100644 (file)
  */
 static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
 {
-       dev_info_t *hash;
+       int lo, mid, hi;
        linear_conf_t *conf = mddev->private;
 
-       hash = conf->disks;
+       lo = 0;
+       hi = mddev->raid_disks - 1;
 
-       while (sector >= hash->end_sector)
-               hash++;
-       return hash;
+       /*
+        * Binary Search
+        */
+
+       while (hi > lo) {
+
+               mid = (hi + lo) / 2;
+               if (sector < conf->disks[mid].end_sector)
+                       hi = mid;
+               else
+                       lo = mid + 1;
+       }
+
+       return conf->disks + lo;
 }
 
 /**