Skip to contentSkip to conversation

multipath: optimizations for large mptable

PATCH In review [email protected] 2 participants 3 messages Aug 26, 2022 – Aug 29, 2022 Device mapper

lore
Share & tools
lore
#0 lore raw

v4 cover multipath: optimizations for large mptable

From: Martin Wilck <[email protected]>

We observe that multipath operations take a long time if the multipaths section in multipath.conf contains a lot of alias settings (10000+ in our case). This hurts in particular in udev rules, when multipath -u or multipath -U is invoked, but also for command line invocations like "multipath -ll".

This series provides a few optimizations for this use case. It speeds up simple multipath operations in the test case by a factor of 20.

Changes v3->v4:

02: more compilation fixes for msort.c to make it pass CI
(only re-posting this patch)

Changes v2->v3, after discussion with Benjamin Marzinski:

01, 02: added msort.c from glibc and adapted to our needs.
Numbering changes accordingly.
03, 04: (was 01, 02): remove pointer comparisons from v2 again, this was a
dumb idea. Use the stable msort algorithm instead.

Changes wrt v1, after suggestions from Benjamin Marzinski:

01, 02: Use pointer comparisons to achieve stable sorting with qsort 02: Fix return without popping the cleanup handler. The way I fixed this
leaves the possibility that some memory won't be freed if a thread is killed while executing vector_convert(). I think this is acceptible; avoiding it would complicate the code, with very small benefit.
02: Remove unnecessary checks and break loop if alias==NULL is encountered.

Martin Wilck (5):
libmultipath: add msort.c from glibc
libmultipath: modifications for msort.c
libmultipath: merge_mptable(): sort table by wwid
libmultipath: check_alias_settings(): pre-sort mptable by alias
multipath: optimize program startup for frequent invocations

 libmultipath/Makefile |   2 +-
 libmultipath/alias.c  |  37 +++++-
 libmultipath/config.c |  15 ++-
 libmultipath/msort.c  | 271 ++++++++++++++++++++++++++++++++++++++++++
 libmultipath/msort.h  |   6 +
 libmultipath/vector.c |   9 ++
 libmultipath/vector.h |   1 +
 multipath/main.c      |  33 ++---
 8 files changed, 352 insertions(+), 22 deletions(-)
 create mode 100644 libmultipath/msort.c
 create mode 100644 libmultipath/msort.h
Signature · 6 lines
2.37.1

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

PATCH v4 2/5 libmultipath: modifications for msort.c

From: Martin Wilck <[email protected]>

We don't want to fallback to qsort if memory is tight, as libc's routine does. Other than that, compile error fixes.

---
 libmultipath/Makefile |  2 +-
 libmultipath/msort.c  | 88 ++++++++++++-------------------------------
 libmultipath/msort.h  |  6 +++
 3 files changed, 32 insertions(+), 64 deletions(-)
 create mode 100644 libmultipath/msort.h
libmultipath/Makefile +1 -1
index fb03200..a70acab 100644
@@ -64,7 +64,7 @@ OBJS-O := parser.o vector.o devmapper.o \
 	log.o configure.o structs_vec.o sysfs.o \
 	lock.o file.o wwids.o prioritizers/alua_rtpg.o prkey.o \
 	io_err_stat.o dm-generic.o generic.o nvme-lib.o \
-	libsg.o valid.o strbuf.o
+	libsg.o valid.o strbuf.o msort.o
 
 OBJS := $(OBJS-O) $(OBJS-U)
 
libmultipath/msort.c +25 -63

143 lines not on this page · raw message

libmultipath/msort.h new file +6 -0
new file mode 100644
index 0000000..caef9b6
@@ -0,0 +1,6 @@
+#ifndef __MSORT_H
+#define __MSORT_H
+typedef int(*__compar_fn_t)(const void *, const void *);
+void msort (void *b, size_t n, size_t s, __compar_fn_t cmp);
+
+#endif
Signature · 6 lines
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on the v4 series
#2 lore raw
In reply to [email protected]
Quoted 1 line · On Fri, Aug 26, 2022 at 08:05:51PM +0200, [email protected] wrote:

From: Martin Wilck <[email protected]>

For the set:

Quoted 38 lines

We observe that multipath operations take a long time if the multipaths section in multipath.conf contains a lot of alias settings (10000+ in our case). This hurts in particular in udev rules, when multipath -u or multipath -U is invoked, but also for command line invocations like "multipath -ll".

This series provides a few optimizations for this use case. It speeds up simple multipath operations in the test case by a factor of 20.

Changes v3->v4:

02: more compilation fixes for msort.c to make it pass CI
(only re-posting this patch)

Changes v2->v3, after discussion with Benjamin Marzinski:

01, 02: added msort.c from glibc and adapted to our needs.
Numbering changes accordingly.
03, 04: (was 01, 02): remove pointer comparisons from v2 again, this was a
dumb idea. Use the stable msort algorithm instead.

Changes wrt v1, after suggestions from Benjamin Marzinski:

01, 02: Use pointer comparisons to achieve stable sorting with qsort 02: Fix return without popping the cleanup handler. The way I fixed this
leaves the possibility that some memory won't be freed if a thread is killed while executing vector_convert(). I think this is acceptible; avoiding it would complicate the code, with very small benefit.
02: Remove unnecessary checks and break loop if alias==NULL is encountered.

Martin Wilck (5):
libmultipath: add msort.c from glibc
libmultipath: modifications for msort.c
libmultipath: merge_mptable(): sort table by wwid
libmultipath: check_alias_settings(): pre-sort mptable by alias
multipath: optimize program startup for frequent invocations

Quoted 14 lines
 libmultipath/Makefile |   2 +-
 libmultipath/alias.c  |  37 +++++-
 libmultipath/config.c |  15 ++-
 libmultipath/msort.c  | 271 ++++++++++++++++++++++++++++++++++++++++++
 libmultipath/msort.h  |   6 +
 libmultipath/vector.c |   9 ++
 libmultipath/vector.h |   1 +
 multipath/main.c      |  33 ++---
 8 files changed, 352 insertions(+), 22 deletions(-)
 create mode 100644 libmultipath/msort.c
 create mode 100644 libmultipath/msort.h
Signature · 1 line
2.37.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel