PATCH[03/03] md: Replacing linear with binary search for linear raid

From: SandeepKsinha <hidden>
Date: 2009-05-19 06:31:04
Subsystem: the rest · Maintainer: Linus Torvalds

Signed-off-by: Sandeep K Sinha <redacted>

    Replacing the linear search to perform binary search.
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index c0fb282..6e8db27 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -27,17 +27,33 @@
  */
 static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
 {
-	dev_info_t *hash;
+	int lo, hi, mid;
+	dev_info_t *dev;
 	linear_conf_t *conf = mddev_to_conf(mddev);

+	lo = 0;
+	hi = mddev->raid_disks - 1;
+
 	/*
-	 * Linear Search
+	 * Binary Search
 	 */
-	hash = conf->disks;

-	while (sector >= hash->rdev->sectors + hash->start_sector)
-		hash++;
-	return hash;
+	while (hi >= lo) {
+		mid = (hi + lo) / 2;
+		dev = conf->disks + mid;
+		
+		if(sector >= dev->start_sector && sector < dev->start_sector +
dev->rdev->sectors)
+			return dev;
+		else if (sector < dev->start_sector)
+			hi = mid;
+		else
+			lo = mid + 1;
+	}
+
+	/*
+	 * We should ideally never reach here.
+	 */
+	return dev;
 }

 /**

-- 
Regards,
Sandeep.





 	
“To learn is to change. Education is a process that changes the learner.”
--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help