dm-mpath: Miscellaneous HST path selector cleanups
Benjamin Marzinski
maintainercover dm-mpath: Miscellaneous HST path selector cleanups
These are just some minor cleanups for dm multipath's historical-service-time path selector.
Benjamin Marzinski (3):
dm-mpath: streamline setup work in the HST path selector
dm-mpath: standardize repeat_count handling in the HST path selector
dm-mpath: check values in hst_status while holding spinlock
drivers/md/dm-ps-historical-service-time.c | 61 ++++++---------------- 1 file changed, 16 insertions(+), 45 deletions(-)
Signature · 1 line
2.53.0
Benjamin Marzinski
maintainerPATCH 1/3 dm-mpath: streamline setup work in the HST path selector
fixed_power() is convoluted and does unnecessary work here, since hst_set_weights() calculates x^n for n = [1,64]. x^1 is x, and x^(n) is just x * x^(n-1), so all these values can be trivially computed from the previous value.
--- drivers/md/dm-ps-historical-service-time.c | 49 +++------------------- 1 file changed, 6 insertions(+), 43 deletions(-)
drivers/md/dm-ps-historical-service-time.c +6 -43
@@ -36,6 +36,7 @@#define HST_FIXED_SHIFT 10/* 10 bits of decimal precision */ #define HST_FIXED_MAX (ULLONG_MAX >> HST_FIXED_SHIFT)#define HST_FIXED_1 (1 << HST_FIXED_SHIFT) +#define HST_FIXED_POINT_5 (1 << (HST_FIXED_SHIFT - 1))#define HST_FIXED_95 972#define HST_MAX_INFLIGHT HST_FIXED_1#define HST_BUCKET_SHIFT 24/* Buckets are ~ 16ms */
@@ -66,46 +67,6 @@ struct path_info {u64 outstanding; }; -/** -* fixed_power - compute: x^n, in O(log n) time -* -* @x: base of the power -* @frac_bits: fractional bits of @x -* @n: power to raise @x to. -* -* By exploiting the relation between the definition of the natural power -* function: x^n := x*x*...*x (x multiplied by itself for n times), and -* the binary encoding of numbers used by computers: n := \Sum n_i * 2^i, -* (where: n_i \elem {0, 1}, the binary vector representing n), -* we find: x^n := x^(\Sum n_i * 2^i) := \Prod x^(n_i * 2^i), which is -* of course trivially computable in O(log_2 n), the length of our binary -* vector. -* -* (see: kernel/sched/loadavg.c) -*/ -static u64 fixed_power (u64 x,unsigned int frac_bits,unsigned int n) -{ -unsigned long result =1UL << frac_bits; - -if (n) { -for (;;) { -if (n &1 ) { - result *= x; - result +=1UL << (frac_bits -1 ); - result >>= frac_bits; - } - n >>=1 ; -if (!n) -break ; - x *= x; - x +=1UL << (frac_bits -1 ); - x >>= frac_bits; - } - } - -return result; -} -/* * Calculate the next value of an exponential moving average * a_1 = a_0 * e + a * (1 - e)
@@ -123,7 +84,7 @@ static u64 fixed_ema(u64 last, u64 next, u64 weight) { last *= weight; last += next * (HST_FIXED_1 - weight); - last +=1ULL << (HST_FIXED_SHIFT -1 ); + last +=HST_FIXED_POINT_5 ;return last >>HST_FIXED_SHIFT ; }
@@ -167,8 +128,10 @@ static void hst_set_weights(struct path_selector *ps, unsigned int base)if (base >=HST_FIXED_1 )return ; -for (i =0 ; i <HST_WEIGHT_COUNT -1 ; i++) - s->weights[i] =fixed_power (base,HST_FIXED_SHIFT , i +1 ); + s->weights[0 ] = base; +for (i =1 ; i <HST_WEIGHT_COUNT -1 ; i++) + s->weights[i] = (base * s->weights[i -1 ] + +HST_FIXED_POINT_5 ) >>HST_FIXED_SHIFT ; s->weights[HST_WEIGHT_COUNT -1 ] =0 ; }
Signature · 1 line
2.53.0
Benjamin Marzinski
maintainerPATCH 2/3 dm-mpath: standardize repeat_count handling in the HST path selector
In reply to Benjamin MarzinskiThe Historical Service Time path selector ignores the repeat_count argument just like all the other path selectors. But all of the other path_selectors explicitly print a warning message when the repeat_count is set greater than 1. Also, all of the other selectors print 1 for the repeat_count when printing the table. Standardize the HST path selector to match.
--- drivers/md/dm-ps-historical-service-time.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/md/dm-ps-historical-service-time.c +7 -2
@@ -31,7 +31,7 @@#define DM_MSG_PREFIX "multipath historical-service-time"#define HST_MIN_IO 1 -#define HST_VERSION "0.1.1" +#define HST_VERSION "0.2.0"#define HST_FIXED_SHIFT 10/* 10 bits of decimal precision */ #define HST_FIXED_MAX (ULLONG_MAX >> HST_FIXED_SHIFT)
@@ -216,7 +216,7 @@ static int hst_status(struct path_selector *ps, struct dm_path *path, pi->outstanding, pi->stale_after);break ;case STATUSTYPE_TABLE : -DMEMIT ("0 " ); +DMEMIT ("%u " , pi->repeat_count);break ;case STATUSTYPE_IMA : *result ='\0' ;
@@ -251,6 +251,11 @@ static int hst_add_path(struct path_selector *ps, struct dm_path *path,return -EINVAL ; } +if (repeat_count >1 ) { +DMWARN_LIMIT ("repeat_count > 1 is deprecated, using 1 instead" ); + repeat_count =1 ; + } +/* allocate the path */ pi =kmalloc_obj (*pi);if (!pi) {
Signature · 1 line
2.53.0
Benjamin Marzinski
maintainerPATCH 3/3 dm-mpath: check values in hst_status while holding spinlock
In reply to Benjamin MarzinskiTo keep the values of pi->historical_service_time, pi->outstanding, and pi->stale_after consistent, get them while holding a spin_lock in hst_status(), like all other accesses do.
--- drivers/md/dm-ps-historical-service-time.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/md/dm-ps-historical-service-time.c +3 -0
@@ -202,6 +202,7 @@ static int hst_status(struct path_selector *ps, struct dm_path *path, {unsigned int sz =0 ;struct path_info *pi; +unsigned long flags;if (!path) {struct selector *s = ps->context;
@@ -212,8 +213,10 @@ static int hst_status(struct path_selector *ps, struct dm_path *path,switch (type) {case STATUSTYPE_INFO : +spin_lock_irqsave (&pi->lock, flags);DMEMIT ("%llu %llu %llu " , pi->historical_service_time, pi->outstanding, pi->stale_after); +spin_unlock_irqrestore (&pi->lock, flags);break ;case STATUSTYPE_TABLE :DMEMIT ("%u " , pi->repeat_count);
Signature · 1 line
2.53.0
Mikulas Patocka
maintainerQuoted 13 lines · Benjamin Marzinski
These are just some minor cleanups for dm multipath's historical-service-time path selector.
Benjamin Marzinski (3):
dm-mpath: streamline setup work in the HST path selector
dm-mpath: standardizerepeat_counthandling in the HST path selector
dm-mpath: check values inhst_statuswhile holding spinlockdrivers/md/dm-ps-historical-service-time.c | 61 ++++++---------------- 1 file changed, 16 insertions(+), 45 deletions(-)Signature · 1 line
2.53.0
Hi
I accepted all three patches, thanks.
Mikulas