Signed-off-by: Sandeep K Sinha <sandeepksinha@xxxxxxxxx> 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@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html