Commit 33d07c0d authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Alasdair G Kergon

dm stripe: optimize chunk_size calculations

dm-stripe is usually used with a chunk size that is a power of two.
Use faster shifts and bit masks in such cases.

stripe_width is already optimized in a similar way.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 8f069b41
...@@ -31,6 +31,7 @@ struct stripe_c { ...@@ -31,6 +31,7 @@ struct stripe_c {
sector_t stripe_width; sector_t stripe_width;
uint32_t chunk_size; uint32_t chunk_size;
int chunk_size_shift;
/* Needed for handling events */ /* Needed for handling events */
struct dm_target *ti; struct dm_target *ti;
...@@ -163,6 +164,10 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -163,6 +164,10 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
ti->num_discard_requests = stripes; ti->num_discard_requests = stripes;
sc->chunk_size = chunk_size; sc->chunk_size = chunk_size;
if (chunk_size & (chunk_size - 1))
sc->chunk_size_shift = -1;
else
sc->chunk_size_shift = __ffs(chunk_size);
/* /*
* Get the stripe destinations. * Get the stripe destinations.
...@@ -202,7 +207,14 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector, ...@@ -202,7 +207,14 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
uint32_t *stripe, sector_t *result) uint32_t *stripe, sector_t *result)
{ {
sector_t chunk = dm_target_offset(sc->ti, sector); sector_t chunk = dm_target_offset(sc->ti, sector);
sector_t chunk_offset = sector_div(chunk, sc->chunk_size); sector_t chunk_offset;
if (sc->chunk_size_shift < 0)
chunk_offset = sector_div(chunk, sc->chunk_size);
else {
chunk_offset = chunk & (sc->chunk_size - 1);
chunk >>= sc->chunk_size_shift;
}
if (sc->stripes_shift < 0) if (sc->stripes_shift < 0)
*stripe = sector_div(chunk, sc->stripes); *stripe = sector_div(chunk, sc->stripes);
...@@ -211,7 +223,12 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector, ...@@ -211,7 +223,12 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
chunk >>= sc->stripes_shift; chunk >>= sc->stripes_shift;
} }
*result = (chunk * sc->chunk_size) + chunk_offset; if (sc->chunk_size_shift < 0)
chunk *= sc->chunk_size;
else
chunk <<= sc->chunk_size_shift;
*result = chunk + chunk_offset;
} }
static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector, static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector,
...@@ -225,7 +242,10 @@ static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector, ...@@ -225,7 +242,10 @@ static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector,
/* round down */ /* round down */
sector = *result; sector = *result;
*result -= sector_div(sector, sc->chunk_size); if (sc->chunk_size_shift < 0)
*result -= sector_div(sector, sc->chunk_size);
else
*result = sector & ~(sector_t)(sc->chunk_size - 1);
if (target_stripe < stripe) if (target_stripe < stripe)
*result += sc->chunk_size; /* next chunk */ *result += sc->chunk_size; /* next chunk */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment