linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [md PATCH 1/2] md: raid0: remove ->sectors from the strip_zone structure.
       [not found] <20090516115726.14596.58766.stgit@notabene.brown>
@ 2009-05-16 11:57 ` NeilBrown
  2009-05-16 11:57 ` [md PATCH 2/2] md: raid0: remove ->dev pointer from " NeilBrown
  1 sibling, 0 replies; 4+ messages in thread
From: NeilBrown @ 2009-05-16 11:57 UTC (permalink / raw)
  To: linux-raid; +Cc: NeilBrown

storing ->sectors is redundant as is can be computed from the
difference  z->zone_end - (z-1)->zone_end

The one place where it is used, it is just as efficient to use
a zone_end value instead.

And removing it makes strip_zone smaller, so they array of these that
is searched on every request has a better chance to say in cache.

So discard the field and get the value from elsewhere.

Signed-off-by: NeilBrown <neilb@suse.de>
---

 drivers/md/raid0.c |   37 +++++++++++++++++++++----------------
 drivers/md/raid0.h |    1 -
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 0305061..4b6c16a 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -55,7 +55,7 @@ static int raid0_congested(void *data, int bits)
 static int create_strip_zones(mddev_t *mddev)
 {
 	int i, c, j, err;
-	sector_t current_start, curr_zone_start;
+	sector_t current_start, curr_zone_start, sectors;
 	mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev;
 	struct strip_zone *zone;
 	int cnt;
@@ -153,11 +153,10 @@ static int create_strip_zones(mddev_t *mddev)
 		goto abort;
 	}
 	zone->nb_dev = cnt;
-	zone->sectors = smallest->sectors * cnt;
-	zone->zone_end = zone->sectors;
+	zone->zone_end = smallest->sectors * cnt;
 
 	current_start = smallest->sectors;
-	curr_zone_start = zone->sectors;
+	curr_zone_start = zone->zone_end;
 
 	/* now do the other zones */
 	for (i = 1; i < conf->nr_strip_zones; i++)
@@ -190,14 +189,14 @@ static int create_strip_zones(mddev_t *mddev)
 		}
 
 		zone->nb_dev = c;
-		zone->sectors = (smallest->sectors - current_start) * c;
+		sectors = (smallest->sectors - current_start) * c;
 		printk(KERN_INFO "raid0: zone->nb_dev: %d, sectors: %llu\n",
-			zone->nb_dev, (unsigned long long)zone->sectors);
-
-		zone->zone_end = curr_zone_start + zone->sectors;
-		curr_zone_start += zone->sectors;
+			zone->nb_dev, (unsigned long long)sectors);
 
+		curr_zone_start += sectors;
 		current_start = smallest->sectors;
+		zone->zone_end = curr_zone_start;
+
 		printk(KERN_INFO "raid0: current zone start: %llu\n",
 			(unsigned long long)current_start);
 	}
@@ -312,16 +311,22 @@ static int raid0_stop(mddev_t *mddev)
 	return 0;
 }
 
-/* Find the zone which holds a particular offset */
+/* Find the zone which holds a particular offset
+ * Update *sectorp to be an offset in that zone
+ */
 static struct strip_zone *find_zone(struct raid0_private_data *conf,
-		sector_t sector)
+				    sector_t *sectorp)
 {
 	int i;
 	struct strip_zone *z = conf->strip_zone;
+	sector_t sector = *sectorp;
 
 	for (i = 0; i < conf->nr_strip_zones; i++)
-		if (sector < z[i].zone_end)
+		if (sector < z[i].zone_end) {
+			if (i)
+				*sectorp = sector - z[i-1].zone_end;
 			return z + i;
+		}
 	BUG();
 }
 
@@ -333,7 +338,7 @@ static int raid0_make_request (struct request_queue *q, struct bio *bio)
 	struct strip_zone *zone;
 	mdk_rdev_t *tmp_dev;
 	sector_t chunk;
-	sector_t sector, rsect;
+	sector_t sector, rsect, sector_offset;
 	const int rw = bio_data_dir(bio);
 	int cpu;
 
@@ -370,11 +375,11 @@ static int raid0_make_request (struct request_queue *q, struct bio *bio)
 		bio_pair_release(bp);
 		return 0;
 	}
-	zone = find_zone(conf, sector);
+	sector_offset = sector;
+	zone = find_zone(conf, &sector_offset);
 	sect_in_chunk = bio->bi_sector & (chunk_sects - 1);
 	{
-		sector_t x = (zone->sectors + sector - zone->zone_end)
-				>> chunksect_bits;
+		sector_t x = sector_offset >> chunksect_bits;
 
 		sector_div(x, zone->nb_dev);
 		chunk = x;
diff --git a/drivers/md/raid0.h b/drivers/md/raid0.h
index dbcf1da..124ba34 100644
--- a/drivers/md/raid0.h
+++ b/drivers/md/raid0.h
@@ -5,7 +5,6 @@ struct strip_zone
 {
 	sector_t zone_end;	/* Start of the next zone (in sectors) */
 	sector_t dev_start;	/* Zone offset in real dev (in sectors) */
-	sector_t sectors;	/* Zone size in sectors */
 	int nb_dev;		/* # of devices attached to the zone */
 	mdk_rdev_t **dev;	/* Devices attached to the zone */
 };



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [md PATCH 2/2] md: raid0: remove ->dev pointer from strip_zone structure
       [not found] <20090516115726.14596.58766.stgit@notabene.brown>
  2009-05-16 11:57 ` [md PATCH 1/2] md: raid0: remove ->sectors from the strip_zone structure NeilBrown
@ 2009-05-16 11:57 ` NeilBrown
  2009-05-18 23:00   ` Subject: [PATCH 1/6] md: raid0 to compile when MD DEBUG is on raz ben yehuda
  1 sibling, 1 reply; 4+ messages in thread
From: NeilBrown @ 2009-05-16 11:57 UTC (permalink / raw)
  To: linux-raid

If we treat conf->devlist more like a 2 dimensional array,
we can get the devlist for a particular zone simply by indexing
that array, so we don't need to store the pointers to subarrays
in strip_zone.  This makes strip_zone smaller and so (hopefully)
searches faster.

Signed-of-by: NeilBrown <neilb@suse.de>
---

 drivers/md/raid0.c |   21 +++++++++++----------
 drivers/md/raid0.h |    1 -
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 4b6c16a..afea606 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -27,7 +27,7 @@ static void raid0_unplug(struct request_queue *q)
 {
 	mddev_t *mddev = q->queuedata;
 	raid0_conf_t *conf = mddev_to_conf(mddev);
-	mdk_rdev_t **devlist = conf->strip_zone[0].dev;
+	mdk_rdev_t **devlist = conf->devlist;
 	int i;
 
 	for (i=0; i<mddev->raid_disks; i++) {
@@ -41,7 +41,7 @@ static int raid0_congested(void *data, int bits)
 {
 	mddev_t *mddev = data;
 	raid0_conf_t *conf = mddev_to_conf(mddev);
-	mdk_rdev_t **devlist = conf->strip_zone[0].dev;
+	mdk_rdev_t **devlist = conf->devlist;
 	int i, ret = 0;
 
 	for (i = 0; i < mddev->raid_disks && !ret ; i++) {
@@ -56,7 +56,7 @@ static int create_strip_zones(mddev_t *mddev)
 {
 	int i, c, j, err;
 	sector_t current_start, curr_zone_start, sectors;
-	mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev;
+	mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev, **dev;
 	struct strip_zone *zone;
 	int cnt;
 	char b[BDEVNAME_SIZE];
@@ -115,7 +115,7 @@ static int create_strip_zones(mddev_t *mddev)
 	zone = &conf->strip_zone[0];
 	cnt = 0;
 	smallest = NULL;
-	zone->dev = conf->devlist;
+	dev = conf->devlist;
 	err = -EINVAL;
 	list_for_each_entry(rdev1, &mddev->disks, same_set) {
 		int j = rdev1->raid_disk;
@@ -125,12 +125,12 @@ static int create_strip_zones(mddev_t *mddev)
 				"aborting!\n", j);
 			goto abort;
 		}
-		if (zone->dev[j]) {
+		if (dev[j]) {
 			printk(KERN_ERR "raid0: multiple devices for %d - "
 				"aborting!\n", j);
 			goto abort;
 		}
-		zone->dev[j] = rdev1;
+		dev[j] = rdev1;
 
 		blk_queue_stack_limits(mddev->queue,
 				       rdev1->bdev->bd_disk->queue);
@@ -162,7 +162,7 @@ static int create_strip_zones(mddev_t *mddev)
 	for (i = 1; i < conf->nr_strip_zones; i++)
 	{
 		zone = conf->strip_zone + i;
-		zone->dev = conf->strip_zone[i-1].dev + mddev->raid_disks;
+		dev = conf->devlist + i * mddev->raid_disks;
 
 		printk(KERN_INFO "raid0: zone %d\n", i);
 		zone->dev_start = current_start;
@@ -171,7 +171,7 @@ static int create_strip_zones(mddev_t *mddev)
 
 		for (j=0; j<cnt; j++) {
 			char b[BDEVNAME_SIZE];
-			rdev = conf->strip_zone[0].dev[j];
+			rdev = conf->devlist[j];
 			printk(KERN_INFO "raid0: checking %s ...",
 				bdevname(rdev->bdev, b));
 			if (rdev->sectors <= current_start) {
@@ -179,7 +179,7 @@ static int create_strip_zones(mddev_t *mddev)
 				continue;
 			}
 			printk(KERN_INFO " contained as device %d\n", c);
-			zone->dev[c] = rdev;
+			dev[c] = rdev;
 			c++;
 			if (!smallest || rdev->sectors < smallest->sectors) {
 				smallest = rdev;
@@ -385,7 +385,8 @@ static int raid0_make_request (struct request_queue *q, struct bio *bio)
 		chunk = x;
 
 		x = sector >> chunksect_bits;
-		tmp_dev = zone->dev[sector_div(x, zone->nb_dev)];
+		tmp_dev = conf->devlist[(zone - conf->strip_zone)*mddev->raid_disks
+					+ sector_div(x, zone->nb_dev)];
 	}
 	rsect = (chunk << chunksect_bits) + zone->dev_start + sect_in_chunk;
  
diff --git a/drivers/md/raid0.h b/drivers/md/raid0.h
index 124ba34..7b3605e 100644
--- a/drivers/md/raid0.h
+++ b/drivers/md/raid0.h
@@ -6,7 +6,6 @@ struct strip_zone
 	sector_t zone_end;	/* Start of the next zone (in sectors) */
 	sector_t dev_start;	/* Zone offset in real dev (in sectors) */
 	int nb_dev;		/* # of devices attached to the zone */
-	mdk_rdev_t **dev;	/* Devices attached to the zone */
 };
 
 struct raid0_private_data



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Subject: [PATCH 1/6] md: raid0 to compile when MD DEBUG  is on
  2009-05-16 11:57 ` [md PATCH 2/2] md: raid0: remove ->dev pointer from " NeilBrown
@ 2009-05-18 23:00   ` raz ben yehuda
  2009-05-18 23:43     ` Neil Brown
  0 siblings, 1 reply; 4+ messages in thread
From: raz ben yehuda @ 2009-05-18 23:00 UTC (permalink / raw)
  To: NeilBrown; +Cc: linux-raid

Because of the removal the device list from 
the strips raid0 did not compile with MD_DEBUG flag on.
commit is stacked on top of:
commit 747df02a154401948426050979b061446eadc37e
Author: NeilBrown <neilb@suse.de>
Date:   Sat May 16 21:51:51 2009 +1000

 raid0.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

Signed-off-by: raziebe@gmail.com
---
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 86249c5..df224ae 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -402,26 +402,29 @@ bad_map:
 	return 0;
 }
 
-static void raid0_status (struct seq_file *seq, mddev_t *mddev)
+static void raid0_status(struct seq_file *seq, mddev_t *mddev)
 {
 #undef MD_DEBUG
 #ifdef MD_DEBUG
 	int j, k, h;
 	char b[BDEVNAME_SIZE];
 	raid0_conf_t *conf = mddev->private;
-
+	sector_t zone_size;
+	sector_t zone_start = 0;
 	h = 0;
 	for (j = 0; j < conf->nr_strip_zones; j++) {
 		seq_printf(seq, "      z%d", j);
 		seq_printf(seq, "=[");
 		for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
 			seq_printf(seq, "%s/", bdevname(
-				conf->strip_zone[j].dev[k]->bdev,b));
-
-		seq_printf(seq, "] ze=%d ds=%d s=%d\n",
-				conf->strip_zone[j].zone_end,
-				conf->strip_zone[j].dev_start,
-				conf->strip_zone[j].sectors);
+				conf->devlist[k]->bdev, b));
+
+		zone_size  = conf->strip_zone[j].zone_end - zone_start;
+		seq_printf(seq, "] ze=%lld ds=%lld s=%lld\n",
+			(unsigned long long)zone_start>>1,
+			(unsigned long long)conf->strip_zone[j].dev_start>>1,
+			(unsigned long long)zone_size>>1);
+		zone_start = conf->strip_zone[j].zone_end;
 	}
 #endif
 	seq_printf(seq, " %dk chunks", mddev->chunk_size/1024);



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Subject: [PATCH 1/6] md: raid0 to compile when MD DEBUG  is on
  2009-05-18 23:00   ` Subject: [PATCH 1/6] md: raid0 to compile when MD DEBUG is on raz ben yehuda
@ 2009-05-18 23:43     ` Neil Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Neil Brown @ 2009-05-18 23:43 UTC (permalink / raw)
  To: raz ben yehuda; +Cc: linux-raid

On Tuesday May 19, raziebe@gmail.com wrote:
> Because of the removal the device list from 
> the strips raid0 did not compile with MD_DEBUG flag on.

Thanks, I had forgotten to check that!

>  
> -static void raid0_status (struct seq_file *seq, mddev_t *mddev)
> +static void raid0_status(struct seq_file *seq, mddev_t *mddev)
>  {
>  #undef MD_DEBUG
>  #ifdef MD_DEBUG
>  	int j, k, h;
>  	char b[BDEVNAME_SIZE];
>  	raid0_conf_t *conf = mddev->private;
> -
> +	sector_t zone_size;
> +	sector_t zone_start = 0;
>  	h = 0;
>  	for (j = 0; j < conf->nr_strip_zones; j++) {
>  		seq_printf(seq, "      z%d", j);
>  		seq_printf(seq, "=[");
>  		for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
>  			seq_printf(seq, "%s/", bdevname(
> -				conf->strip_zone[j].dev[k]->bdev,b));
> -
> -		seq_printf(seq, "] ze=%d ds=%d s=%d\n",
> -				conf->strip_zone[j].zone_end,
> -				conf->strip_zone[j].dev_start,
> -				conf->strip_zone[j].sectors);
> +				conf->devlist[k]->bdev, b));
                                              ^

This doesn't look right.  There should a 'j' in there shouldn't there?
something like
                               conf->devlist[j*mddev->raid_disks + k]->bdev
??

> +
> +		zone_size  = conf->strip_zone[j].zone_end - zone_start;
> +		seq_printf(seq, "] ze=%lld ds=%lld s=%lld\n",
> +			(unsigned long long)zone_start>>1,
> +			(unsigned long long)conf->strip_zone[j].dev_start>>1,
> +			(unsigned long long)zone_size>>1);
> +		zone_start = conf->strip_zone[j].zone_end;

The rest looks fine.

Thanks,
NeilBrown


>  	}
>  #endif
>  	seq_printf(seq, " %dk chunks", mddev->chunk_size/1024);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-18 23:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20090516115726.14596.58766.stgit@notabene.brown>
2009-05-16 11:57 ` [md PATCH 1/2] md: raid0: remove ->sectors from the strip_zone structure NeilBrown
2009-05-16 11:57 ` [md PATCH 2/2] md: raid0: remove ->dev pointer from " NeilBrown
2009-05-18 23:00   ` Subject: [PATCH 1/6] md: raid0 to compile when MD DEBUG is on raz ben yehuda
2009-05-18 23:43     ` Neil Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).