PATCH[03/03] md: Binary search in linear raid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
This patch replaces the linear search in which_dev to binary search.

Author: Sandeep K Sinha <sandeepksinha@xxxxxxxxx>
Date:   Tue May 19 16:14:15 2009 +0530

    Replaces the linear search to binary search in which_dev.

diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index f7f6bb9..9ad6ec4 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -27,14 +27,26 @@
  */
 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_to_conf(mddev);
+	
+	lo = 0;
+	hi = mddev->raid_disks - 1;

-	hash = conf->disks;
+	/*
+	 * Binary Search
+	 */
+
+	while (hi > lo) {
+
+		mid = (hi + lo) / 2;
+		if (sector < conf->disks[mid].end_sector)
+			hi = mid;
+		else
+			lo = mid + 1;
+	}

-	while (sector >= hash->end_sector)
-		hash++;
-	return hash;
+	return conf->disks + lo;
 }

 /**

-- 
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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux