提交 c96053b7 编写于 作者: M Mikulas Patocka 提交者: Alasdair G Kergon

dm stripe: optimize sector division

Optimize sector division: If the number of stripes is a power of two,
we can do shift and mask instead of division.
Signed-off-by: NMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: NMike Snitzer <snitzer@redhat.com>
Signed-off-by: NAlasdair G Kergon <agk@redhat.com>
上级 65988525
...@@ -25,6 +25,8 @@ struct stripe { ...@@ -25,6 +25,8 @@ struct stripe {
struct stripe_c { struct stripe_c {
uint32_t stripes; uint32_t stripes;
int stripes_shift;
sector_t stripes_mask;
/* The size of this target / num. stripes */ /* The size of this target / num. stripes */
sector_t stripe_width; sector_t stripe_width;
...@@ -162,16 +164,21 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -162,16 +164,21 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
/* Set pointer to dm target; used in trigger_event */ /* Set pointer to dm target; used in trigger_event */
sc->ti = ti; sc->ti = ti;
sc->stripes = stripes; sc->stripes = stripes;
sc->stripe_width = width; sc->stripe_width = width;
if (stripes & (stripes - 1))
sc->stripes_shift = -1;
else {
sc->stripes_shift = ffs(stripes) - 1;
sc->stripes_mask = ((sector_t) stripes) - 1;
}
ti->split_io = chunk_size; ti->split_io = chunk_size;
ti->num_flush_requests = stripes; ti->num_flush_requests = stripes;
sc->chunk_shift = ffs(chunk_size) - 1;
sc->chunk_mask = ((sector_t) chunk_size) - 1; sc->chunk_mask = ((sector_t) chunk_size) - 1;
for (sc->chunk_shift = 0; chunk_size; sc->chunk_shift++)
chunk_size >>= 1;
sc->chunk_shift--;
/* /*
* Get the stripe destinations. * Get the stripe destinations.
...@@ -213,7 +220,13 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector, ...@@ -213,7 +220,13 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
sector_t offset = dm_target_offset(sc->ti, sector); sector_t offset = dm_target_offset(sc->ti, sector);
sector_t chunk = offset >> sc->chunk_shift; sector_t chunk = offset >> sc->chunk_shift;
*stripe = sector_div(chunk, sc->stripes); if (sc->stripes_shift < 0)
*stripe = sector_div(chunk, sc->stripes);
else {
*stripe = chunk & sc->stripes_mask;
chunk >>= sc->stripes_shift;
}
*result = (chunk << sc->chunk_shift) | (offset & sc->chunk_mask); *result = (chunk << sc->chunk_shift) | (offset & sc->chunk_mask);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册