Skip to contentSkip to conversation

multipath-tools: Prioritizer based on a latency algorithm

PATCH Superseded Yang Feng 2 participants 4 messages Jun 9, 2017 – Jun 16, 2017 Device mapper

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Yang Feng

author
#0 lore raw

v5 cover multipath-tools: Prioritizer based on a latency algorithm

This patch value is in the following:
1. In the Storage-Backup environment of HyperCluster, includes one storage array near to the host and one remote storage array, and the two storage arrays have the same hardware.The same LUN is writed or readed by the two storage arrays. However, usually, the average latency of the paths of the remote storage array is much higher than the near storage array's. Apparently, the prioritizer can be a good automatic solution. And the current selectors don't solve it, IOs will send to the paths of the remote storage array, IOPS will be influenced unavoidably.

2. In the environment of single storage array, the prioritizer can automatically separate the paths who's latency is much higher, IOs will not send to this paths. But the current selectors don't solve this problem, IOPS will be influenced unavoidably.

Changes from v4:
* Argument "latency_interval" is set by using logarithmic scale, where base number is 10. Fix according to Martin's reviews.
* The value of "MAX_LATENCY_INTERVAL" is set 10 from 60.

Changes from v3:
* Delete Copyright time "2021", Fix according to Xose's reviews.
* Add version for GPL, Fix according to Xose's reviews.

Changes from v2:
* Reorganize the commit comment and patch format.
* Added Benjamin, Martin and Xose's Reviewed-by.

Changes from v1:
* The value of "MIN_IO_NUM" is set 2 from 10.
* Fix according to Benjamin, Martin and Xose's reviews.

Yang Feng (1):
multipath-tools: Prioritizer based on a latency algorithm

 libmultipath/prio.h                      |   1 +
 libmultipath/prioritizers/Makefile       |   4 +
 libmultipath/prioritizers/path_latency.c | 282 +++++++++++++++++++++++++++++++
 multipath/multipath.conf.5               |  20 +++
 4 files changed, 307 insertions(+)
 create mode 100644 libmultipath/prioritizers/path_latency.c
Signature · 1 line
2.6.4.windows.1
author
#1 lore raw

PATCH v5 1/1 multipath-tools: Prioritizer based on a latency algorithm

libmultipath/prioritizers: Prioritizer for device mapper multipath, where the corresponding priority values of specific paths are provided by a latency algorithm. And the latency algorithm is dependent on the following arguments(latency_interval and io_num).
The principle of the algorithm is illustrated as follows:
1. By sending a certain number "cons_num" of read IOs to the current path continuously, the IOs' average latency can be calculated.
2. According to the average latency of each path and the weight value "latency_interval", the priority "rc" of each path can be provided.

latency_interval latency_interval latency_interval latency_interval

 |------------------|------------------|------------------|...|------------------|
 |  priority rank 1 |  priority rank 2 |  priority rank 3 |...|  priority rank x |
 |------------------|------------------|------------------|...|------------------|

Priority Rank Partitioning

---
 libmultipath/prio.h                      |   1 +
 libmultipath/prioritizers/Makefile       |   4 +
 libmultipath/prioritizers/path_latency.c | 282 +++++++++++++++++++++++++++++++
 multipath/multipath.conf.5               |  20 +++
 4 files changed, 307 insertions(+)
 create mode 100644 libmultipath/prioritizers/path_latency.c
libmultipath/prio.h +1 -0
index 0193c52..c97fe39 100644
@@ -29,6 +29,7 @@ struct path;
 #define PRIO_RDAC		"rdac"
 #define PRIO_WEIGHTED_PATH	"weightedpath"
 #define PRIO_SYSFS		"sysfs"
+#define PRIO_PATH_LATENCY	"path_latency"
 
 /*
  * Value used to mark the fact prio was not defined
libmultipath/prioritizers/Makefile +4 -0
index 36b42e4..ca47cdf 100644
@@ -18,6 +18,7 @@ LIBS = \
 	libpriorandom.so \
 	libpriordac.so \
 	libprioweightedpath.so \
+	libpriopath_latency.so \
 	libpriosysfs.so
 
 all: $(LIBS)
@@ -25,6 +26,9 @@ all: $(LIBS)
 libprioalua.so: alua.o alua_rtpg.o
 	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -o $@ $^
 
+libpriopath_latency.so: path_latency.o  ../checkers/libsg.o
+	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -o $@ $^ -lm
+
 libprio%.so: %.o
 	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -o $@ $^
 
libmultipath/prioritizers/path_latency.c new file +282 -0

282 lines not on this page · raw message

multipath/multipath.conf.5 +20 -0
index 5939688..1507406 100644
@@ -293,6 +293,10 @@ Generate a random priority between 1 and 10.
 Generate the path priority based on the regular expression and the
 priority provided as argument. Requires prio_args keyword.
 .TP
+.I path_latency
+Generate the path priority based on a latency algorithm.
+Requires prio_args keyword.
+.TP
 .I datacore
 .\" XXX
 ???. Requires prio_args keyword.
@@ -333,6 +337,22 @@ these values can be looked up through sysfs or by running \fImultipathd show pat
 "%N:%R:%n:%r"\fR. For example: 0x200100e08ba0aea0:0x210100e08ba0aea0:.*:.* , .*:.*:iqn.2009-10.com.redhat.msp.lab.ask-06:.*
 .RE
 .TP 12
+.I path_latency
+Needs a value of the form
+\fI"<latency_interval>|<io_num>"\fR
+.RS
+.TP 8
+.I latency_interval
+The interval values of average latency between two different neighbour ranks of path priority, used to partition
+different priority ranks. Form: XXs, or XXXus, or XXXms. Unit: Second, or Microsecond, or Millisecond. Valid Values:
+Integer, using logarithmic scale and base number is 10, s [1, 10], ms [1, 10000], us [1, 10000000], For example:
+If latency_interval=10ms, the paths will be grouped in priority groups with path latency 0-10ms, 10-20ms, 20-30ms, etc.
+.TP
+.I io_num
+The number of read IOs sent to the current path continuously, used to calculate the average path latency.
+Valid Values: Integer, [2, 200].
+.RE
+.TP 12
 .I alua
 If \fIexclusive_pref_bit\fR is set, paths with the \fIpreferred path\fR bit
 set will always be in their own path group.
Signature · 1 line
2.6.4.windows.1
#2 lore raw

Hello Yang,

thanks for your work, and apologies for making you wait so long. I still have some suggestions. Please see below.

On Fri, 2017-06-09 at 17:58 +0800, Yang Feng wrote

Quoted 28 lines

libmultipath/prioritizers: Prioritizer for device mapper multipath, where the corresponding priority values of specific paths are provided
by a latency algorithm. And the latency algorithm is dependent on the following arguments(latency_interval and io_num).
The principle of the algorithm is illustrated as follows:
1. By sending a certain number "cons_num" of read IOs to the current path continuously, the IOs' average latency can be calculated.
2. According to the average latency of each path and the weight value "latency_interval", the priority "rc" of each path can be provided.

latency_interval latency_interval latency_interval laten
cy_interval

 |------------------|------------------|------------------|...|----
--------------|
 |  priority rank 1 |  priority rank 2 |  priority rank 3
|...|  priority rank x |
 |------------------|------------------|------------------|...|----
--------------|

Priority Rank Partitioning

libmultipath/prioritizers/path_latency.c line 40

Quoted 2 lines
libmultipath/prioritizers/path_latency.c new file +2 -0
+#define MAX_LATENCY_INTERVAL    10            /*unit: s*/
+#define MIN_LATENCY_INTERVAL    1             /*unit: us, or ms, or s*/

Why not use the same unit or both values?

Quoted 4 lines
libmultipath/prioritizers/path_latency.c new file +3 -0
+static inline long long timeval_to_us(const struct timespec *tv)
+{
+	return ((long long) tv->tv_sec * USEC_PER_SEC) + (tv-
Quoted 1 line

tv_nsec >> 10);

Please calculate correctly, divide by 1000.

Review

Quoted 9 lines

+int check_args_valid(int io_num, long long latency_interval, int type)

libmultipath/prioritizers/path_latency.c new file +4 -0
+{
+    if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM))
+    {
+        condlog(0, "args io_num is more than the valid values

range");

(quoted diff) +2 -0
+        return 0;
+    }

Please write "outside the valid range" rather than "more than the valid values range".

In general, when you use condlog(), please prefix all messages with a string that clearly identifies the path_latency prioritizer, e.g. PRIO_PATH_LATENCY.
I know we're not currently doing that consistently in multipath-tools, but that shouldn't be a reason for not doing when adding new code.

Review

Quoted 9 lines
(quoted diff) +2 -0
+
+    /* check value is set by using logarithmic scale, and base

number is 10 */

libmultipath/prioritizers/path_latency.c new file +3 -0
+    if ((latency_interval % BASE_NUMBER) != 0)
+    {
+        condlog(0, "args latency_interval is not set by using

logarithmic scale , where base number is 10");

(quoted diff) +2 -0
+        return 0;
+    }

This is not what I meant with "logarithmic scale". See below.

Review

Quoted 10 lines
libmultipath/prioritizers/path_latency.c new file +4 -0
+
+    /* s:[1, 10], ms:[1, 10000], us:[1, 10000000] */
+    if ((latency_interval < MIN_LATENCY_INTERVAL)
+        || (latency_interval > (MAX_LATENCY_INTERVAL * USEC_PER_SEC

/ conversion_ratio[type])))

(quoted diff) +2 -0
+    {
+        condlog(0, "args latency_interval is more than the valid

values range");

(quoted diff) +2 -0
+        return 0;
+    }

Again, please use "outside".

Quoted 17 lines

+/* In multipath.conf, args form: io_num|latency_interval. For example,

libmultipath/prioritizers/path_latency.c new file +15 -0
+*  args is "20|10ms", this function can get 20, 10.
+*/
+static int get_interval_and_ionum(char *args,
+                                        int *ionum,
+                                        long long *interval)
+{
+    char source[MAX_CHAR_SIZE];
+    char vertica = '|';
+    char *endstrbefore = NULL;
+    char *endstrafter = NULL;
+    int type;
+    unsigned int size = strlen(args);
+    long long ratio;
+
+    if ((args == NULL) || (ionum == NULL) || (interval == NULL))

libmultipath/prioritizers/path_latency.c line 166

Quoted 10 lines
libmultipath/prioritizers/path_latency.c new file +10 -0
+    {
+        condlog(0, "args string is NULL");
+        return 0;
+    }
+
+    if ((size < 1) || (size > MAX_CHAR_SIZE-1))
+    {
+        condlog(0, "args string's size is too long");
+        return 0;
+    }

"too long" is not correct for the first (more likely) error condition.

libmultipath/prioritizers/path_latency.c line 174

Quoted 8 lines
libmultipath/prioritizers/path_latency.c new file +8 -0
+
+    memcpy(source, args, size+1);
+
+    if (!isdigit(source[0]))
+    {
+        condlog(0, "args io_num string's first char is not digit");
+        return 0;
+    }

It would be ok to catch all these errors with a single line of code such as "path_latency: invalid prio_args format: %s".

Quoted 69 lines
libmultipath/prioritizers/path_latency.c new file +11 -0
+
+    *ionum = (int)strtoul(source, &endstrbefore, 10);
+    if (endstrbefore[0] != vertica)
+    {
+        condlog(0, "segmentation char is invalid");
+        return 0;
+    }
+
+    if (!isdigit(endstrbefore[1]))
+    {
+        condlog(0, "args latency_interval string's first char is not

digit");

libmultipath/prioritizers/path_latency.c new file +4 -0
+        return 0;
+    }
+
+    *interval = (long long)strtol(&endstrbefore[1], &endstrafter,

10);

libmultipath/prioritizers/path_latency.c new file +19 -0
+    type = get_interval_type(endstrafter);
+    if (type == INTERVAL_INVALID)
+    {
+        condlog(0, "args latency_interval type is invalid");
+        return 0;
+    }
+
+    if (check_args_valid(*ionum, *interval, type) == 0)
+    {
+        return 0;
+    }
+
+	ratio = get_conversion_ratio(type);
+    *interval *= (long long)ratio;
+
+    return 1;
+}
+
+long long calc_standard_deviation(long long *path_latency, int size,

long long avglatency)

libmultipath/prioritizers/path_latency.c new file +7 -0
+{
+    int index;
+    long long total = 0;
+
+    for (index = 0; index < size; index++)
+    {
+        total += (path_latency[index] - avglatency) *

(path_latency[index] - avglatency);

libmultipath/prioritizers/path_latency.c new file +23 -0
+    }
+
+    total /= (size-1);
+
+    return (long long)sqrt((double)total);
+}
+
+int getprio (struct path *pp, char *args, unsigned int timeout)
+{
+    int rc, temp;
+    int index = 0;
+    int io_num;
+    long long latency_interval;
+    long long avglatency;
+    long long standard_deviation;
+    long long toldelay = 0;
+    long long before, after;
+    struct timespec tv;
+
+	if (pp->fd < 0)
+		return -1;
+
+    if (get_interval_and_ionum(args, &io_num, &latency_interval) ==

0)

libmultipath/prioritizers/path_latency.c line 242

Quoted 4 lines
libmultipath/prioritizers/path_latency.c new file +4 -0
+    {
+        condlog(0, "%s: get path_latency args fail", pp->dev);
+        return DEFAULT_PRIORITY;
+    }

Could you just assume reasonable defaults for the path latency algorithm rather than returning a constant?

Quoted 30 lines
libmultipath/prioritizers/path_latency.c new file +24 -0
+
+    memset(path_latency, 0, sizeof(path_latency));
+
+    temp = io_num;
+    while (temp-- > 0)
+    {
+        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+        before = timeval_to_us(&tv);
+
+        if (do_readsector0(pp->fd, timeout) == 2)
+        {
+            condlog(0, "%s: path down", pp->dev);
+            return -1;
+        }
+
+        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+        after = timeval_to_us(&tv);
+
+        path_latency[index] = after - before;
+        toldelay += path_latency[index++];
+    }
+
+    avglatency = toldelay/(long long)io_num;
+    condlog(4, "%s: average latency is (%lld)", pp->dev,

avglatency);

libmultipath/prioritizers/path_latency.c new file +4 -0
+
+    if (avglatency > THRES_USEC_VALUE)
+    {
+        condlog(0, "%s: average latency (%lld) is more than

thresold", pp->dev, avglatency);

Review

Quoted 2 lines
(quoted diff) +2 -0
+        return DEFAULT_PRIORITY;
+    }

Why don't you put simply put this in the highest latency bin? See below.

Quoted 12 lines
(quoted diff) +2 -0
+
+    /* warn the user if the latency_interval set is smaller than (2

* standard deviation), or equal */
+ standard_deviation = calc_standard_deviation(path_latency,
index, avglatency);

(quoted diff) +2 -0
+    if (latency_interval <= (2 * standard_deviation))
+        condlog(3, "%s: args latency_interval set is smaller than 2

* standard deviation (%lld us), or equal",

libmultipath/prioritizers/path_latency.c new file +3 -0
+            pp->dev, standard_deviation);
+
+	rc = (int)(THRES_USEC_VALUE - (avglatency/(long

long)latency_interval));

libmultipath/prioritizers/path_latency.c line 282

Quoted 2 lines
libmultipath/prioritizers/path_latency.c new file +2 -0
+    return rc;
+}

Hm, I think you misunderstood my "logarithmic scale" idea. By dividing the average by the interval size, you get ordinary linear scaling again. That doesn't help the problem.

Here is a sample program illustrating what I meant. It uses math.h functions, but that shouldn't be a problem; we're running in user space. The chosen interval size, corresponding to a factor of 1.995, is probably a good choice for many scenarios. Your could represent the range between 1us and 10s with 34 prio values, and still be able to differentiate paths with, say, 1.5 and 3 us latency.

If you use this, you should also use double type for calculating the average and stddev, and you must be careful to calculate the standard deviation for the logarithms, as interval size is not constant any more (only on logarithmic scale).

#include <stdio.h>
#include <math.h>

/*
* For a given positive value x, return a "prio" between 0 and n
* using logarithmically scaled intervals between minval and maxval. */

int log_prio(double x,
unsigned long minval, unsigned long maxval, unsigned n)

{
	double lx, lmin, lmax;
	if (x <= minval)
		return n;
	if (x >= maxval)
		return 0;
	lx = log10(x);
	lmin = log10(minval);
	lmax = log10(maxval);
	return n - (n - 1) * (lx - lmin) / (lmax - lmin);
}

int main(void)

{
	int minval = 1;
	int maxval = 1000;
	int n = 11;
	double x;
	for (x = minval/2.; x < maxval*2.; x *= sqrt(2.))
		printf("%f: %d\n", x, log_prio(x, minval, maxval, n));
	return 0;
}

Regards,
Martin

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
author
#3 lore raw

Hi Martin,

Thanks for your reviews.
Please find my replys.
And the patch v6 will be sent later.

Regards,
Yang

---

Quoted 6 lines

libmultipath/prioritizers/path_latency.c line 40

Quoted 3 lines
libmultipath/prioritizers/path_latency.c new file +2 -0
+#define MAX_LATENCY_INTERVAL    10            /*unit: s*/
+#define MIN_LATENCY_INTERVAL    1             /*unit: us, or ms, or s*/

Why not use the same unit or both values?

It's easy to check the valid range of the "latency_interval" value. For unit: us, or ms, or s, the min digital value is the same, is 1. And for all unit, the max conversion value is the same, is 10 seconds.

Quoted 7 lines
Quoted 4 lines
libmultipath/prioritizers/path_latency.c new file +3 -0
+static inline long long timeval_to_us(const struct timespec *tv)
+{
+	return ((long long) tv->tv_sec * USEC_PER_SEC) + (tv-
Quoted 1 line

tv_nsec >> 10);

Please calculate correctly, divide by 1000.

Thanks, it will be fixed.

Quoted 4 lines
Quoted 4 lines

+int check_args_valid(int io_num, long long latency_interval, int type)

(quoted diff) +2 -0
+{
+    if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM))
Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+    {
+        condlog(0, "args io_num is more than the valid values

range");

(quoted diff) +2 -0
+        return 0;
+    }

Please write "outside the valid range" rather than "more than the valid values range".

Thanks, it will be fixed.

Quoted 6 lines

In general, when you use condlog(), please prefix all messages with a string that clearly identifies the path_latency prioritizer, e.g. PRIO_PATH_LATENCY.
I know we're not currently doing that consistently in multipath-tools, but that shouldn't be a reason for not doing when adding new code.

Good, thanks, it will be fixed.

Quoted 23 lines

Review

Quoted 9 lines
(quoted diff) +2 -0
+
+    /* check value is set by using logarithmic scale, and base

number is 10 */

libmultipath/prioritizers/path_latency.c new file +3 -0
+    if ((latency_interval % BASE_NUMBER) != 0)
+    {
+        condlog(0, "args latency_interval is not set by using

logarithmic scale , where base number is 10");

(quoted diff) +2 -0
+        return 0;
+    }

This is not what I meant with "logarithmic scale". See below.

Review

Quoted 10 lines
libmultipath/prioritizers/path_latency.c new file +4 -0
+
+    /* s:[1, 10], ms:[1, 10000], us:[1, 10000000] */
+    if ((latency_interval < MIN_LATENCY_INTERVAL)
+        || (latency_interval > (MAX_LATENCY_INTERVAL * USEC_PER_SEC

/ conversion_ratio[type])))

(quoted diff) +2 -0
+    {
+        condlog(0, "args latency_interval is more than the valid

values range");

(quoted diff) +2 -0
+        return 0;
+    }
Quoted 2 lines

Again, please use "outside".

Thanks, it will be fixed.

Quoted 30 lines
Quoted 17 lines

+/* In multipath.conf, args form: io_num|latency_interval. For example,

libmultipath/prioritizers/path_latency.c new file +15 -0
+*  args is "20|10ms", this function can get 20, 10.
+*/
+static int get_interval_and_ionum(char *args,
+                                        int *ionum,
+                                        long long *interval)
+{
+    char source[MAX_CHAR_SIZE];
+    char vertica = '|';
+    char *endstrbefore = NULL;
+    char *endstrafter = NULL;
+    int type;
+    unsigned int size = strlen(args);
+    long long ratio;
+
+    if ((args == NULL) || (ionum == NULL) || (interval == NULL))

libmultipath/prioritizers/path_latency.c line 166

Quoted 10 lines
libmultipath/prioritizers/path_latency.c new file +10 -0
+    {
+        condlog(0, "args string is NULL");
+        return 0;
+    }
+
+    if ((size < 1) || (size > MAX_CHAR_SIZE-1))
+    {
+        condlog(0, "args string's size is too long");
+        return 0;
+    }

"too long" is not correct for the first (more likely) error condition.

Quoted 12 lines

libmultipath/prioritizers/path_latency.c line 174

Quoted 8 lines
libmultipath/prioritizers/path_latency.c new file +8 -0
+
+    memcpy(source, args, size+1);
+
+    if (!isdigit(source[0]))
+    {
+        condlog(0, "args io_num string's first char is not digit");
+        return 0;
+    }

It would be ok to catch all these errors with a single line of code such as "path_latency: invalid prio_args format: %s".

OK, it will be fixed.

Quoted 68 lines
Quoted 68 lines
libmultipath/prioritizers/path_latency.c new file +11 -0
+
+    *ionum = (int)strtoul(source, &endstrbefore, 10);
+    if (endstrbefore[0] != vertica)
+    {
+        condlog(0, "segmentation char is invalid");
+        return 0;
+    }
+
+    if (!isdigit(endstrbefore[1]))
+    {
+        condlog(0, "args latency_interval string's first char is not

digit");

libmultipath/prioritizers/path_latency.c new file +4 -0
+        return 0;
+    }
+
+    *interval = (long long)strtol(&endstrbefore[1], &endstrafter,

10);

libmultipath/prioritizers/path_latency.c new file +19 -0
+    type = get_interval_type(endstrafter);
+    if (type == INTERVAL_INVALID)
+    {
+        condlog(0, "args latency_interval type is invalid");
+        return 0;
+    }
+
+    if (check_args_valid(*ionum, *interval, type) == 0)
+    {
+        return 0;
+    }
+
+	ratio = get_conversion_ratio(type);
+    *interval *= (long long)ratio;
+
+    return 1;
+}
+
+long long calc_standard_deviation(long long *path_latency, int size,

long long avglatency)

libmultipath/prioritizers/path_latency.c new file +7 -0
+{
+    int index;
+    long long total = 0;
+
+    for (index = 0; index < size; index++)
+    {
+        total += (path_latency[index] - avglatency) *

(path_latency[index] - avglatency);

libmultipath/prioritizers/path_latency.c new file +23 -0
+    }
+
+    total /= (size-1);
+
+    return (long long)sqrt((double)total);
+}
+
+int getprio (struct path *pp, char *args, unsigned int timeout)
+{
+    int rc, temp;
+    int index = 0;
+    int io_num;
+    long long latency_interval;
+    long long avglatency;
+    long long standard_deviation;
+    long long toldelay = 0;
+    long long before, after;
+    struct timespec tv;
+
+	if (pp->fd < 0)
+		return -1;
+
+    if (get_interval_and_ionum(args, &io_num, &latency_interval) ==
Quoted 9 lines

libmultipath/prioritizers/path_latency.c line 242

Quoted 5 lines

0)

libmultipath/prioritizers/path_latency.c new file +4 -0
+    {
+        condlog(0, "%s: get path_latency args fail", pp->dev);
+        return DEFAULT_PRIORITY;
+    }

Could you just assume reasonable defaults for the path latency algorithm rather than returning a constant?

En, I think returning a DEFAULT_PRIORITY "0" is no problem. If return a assumed value, then the user can be confused, because the defaults is not set.

Quoted 27 lines
Quoted 27 lines
libmultipath/prioritizers/path_latency.c new file +24 -0
+
+    memset(path_latency, 0, sizeof(path_latency));
+
+    temp = io_num;
+    while (temp-- > 0)
+    {
+        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+        before = timeval_to_us(&tv);
+
+        if (do_readsector0(pp->fd, timeout) == 2)
+        {
+            condlog(0, "%s: path down", pp->dev);
+            return -1;
+        }
+
+        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+        after = timeval_to_us(&tv);
+
+        path_latency[index] = after - before;
+        toldelay += path_latency[index++];
+    }
+
+    avglatency = toldelay/(long long)io_num;
+    condlog(4, "%s: average latency is (%lld)", pp->dev,

avglatency);

libmultipath/prioritizers/path_latency.c new file +2 -0
+
+    if (avglatency > THRES_USEC_VALUE)
Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+    {
+        condlog(0, "%s: average latency (%lld) is more than

thresold", pp->dev, avglatency);

(quoted diff) +2 -0
+        return DEFAULT_PRIORITY;
+    }

Why don't you put simply put this in the highest latency bin? See below.

Thanks, it will be fixed.

Quoted 54 lines
Quoted 12 lines
(quoted diff) +2 -0
+
+    /* warn the user if the latency_interval set is smaller than (2

* standard deviation), or equal */
+ standard_deviation = calc_standard_deviation(path_latency,
index, avglatency);

(quoted diff) +2 -0
+    if (latency_interval <= (2 * standard_deviation))
+        condlog(3, "%s: args latency_interval set is smaller than 2

* standard deviation (%lld us), or equal",

libmultipath/prioritizers/path_latency.c new file +3 -0
+            pp->dev, standard_deviation);
+
+	rc = (int)(THRES_USEC_VALUE - (avglatency/(long

long)latency_interval));

libmultipath/prioritizers/path_latency.c line 282

Quoted 2 lines
libmultipath/prioritizers/path_latency.c new file +2 -0
+    return rc;
+}

Hm, I think you misunderstood my "logarithmic scale" idea. By dividing the average by the interval size, you get ordinary linear scaling again. That doesn't help the problem.

Here is a sample program illustrating what I meant. It uses math.h functions, but that shouldn't be a problem; we're running in user space. The chosen interval size, corresponding to a factor of 1.995, is probably a good choice for many scenarios. Your could represent the range between 1us and 10s with 34 prio values, and still be able to differentiate paths with, say, 1.5 and 3 us latency.

If you use this, you should also use double type for calculating the average and stddev, and you must be careful to calculate the standard deviation for the logarithms, as interval size is not constant any more (only on logarithmic scale).

#include <stdio.h>
#include <math.h>

/*
* For a given positive value x, return a "prio" between 0 and n
* using logarithmically scaled intervals between minval and maxval. */

int log_prio(double x,
unsigned long minval, unsigned long maxval, unsigned n)

{
	double lx, lmin, lmax;
	if (x <= minval)
		return n;
	if (x >= maxval)
		return 0;
	lx = log10(x);
	lmin = log10(minval);
	lmax = log10(maxval);
	return n - (n - 1) * (lx - lmin) / (lmax - lmin);
}

int main(void)

Quoted 10 lines
{
	int minval = 1;
	int maxval = 1000;
	int n = 11;
	double x;
	for (x = minval/2.; x < maxval*2.; x *= sqrt(2.))
		printf("%f: %d\n", x, log_prio(x, minval, maxval, n));
	return 0;
}

OK, the argument "latency_interval" will be delete, instead, the argument "base_num" will be added for logarithmic scale.
And min value will be set 1 us, max value will be set 10000000 us (or 10 s).

Quoted 3 lines

Regards,
Martin