multipathd: make multipathd set priority to RLIMIT_RTPRIO
Subsystems (2)
Benjamin Marzinski
maintainerPATCH 1/1 multipathd: make multipathd set priority to RLIMIT_RTPRIO
With this change, if the SCHED_RT_PRIO compiler flag is not set, multipathd will call getrlimit(RLIMIT_RTPRIO, ...) and look at the hard limit. It it's 0, multipath will do nothing. Otherwise it will change its scheduling policy to SCHED_RR and its priority to the hard limit.
This allows users to change the priority of that multipathd runs with by adding
LimitRTPRIO=<prio>
to the [Service] section of the multipathd.service unit file. Setting LimitRTPRIO=0 will make multipathd run as a normal process, while setting LimitRTPRIO=infinity will make it use the maximum SCHED_RR prio, which is 99.
--- Makefile.inc | 7 +++++-- README.md | 2 +- multipathd/Makefile | 5 ++++- multipathd/main.c | 28 +++++++++++++++++++++------- 4 files changed, 31 insertions(+), 11 deletions(-)
Makefile.inc +5 -2
@@ -20,8 +20,11 @@ SCSI_DH_MODULES_PRELOAD := # Multipathd scheduling priority. Set value from 1 to 99 to make multipathd # change its scheduling policy to SCHED_RR and its priority to the specified -# value. set to 0 to stop multipathd from changing the scheduling policy and -# priority it was started with. +# value. Set to 0 to stop multipathd from changing the scheduling policy and +# priority it was started with. If undefined, multipathd will call +# getrlimit(RLIMIT_RTPRIO, ...) and look at the hard limit. It it's 0, +# multipath will do nothing. Otherwise it will change its scheduling policy +# to SCHED_RR and its priority to the hard limit. SCHED_RT_PRIO := 99 EXTRAVERSION := $(shell rev=$$(git rev-parse --short=7 HEAD 2>/dev/null); echo $${rev:+-g$$rev})
README.md +1 -1
@@ -99,7 +99,7 @@ The following variables can be passed to the `make` command line: Note that using libreadline may [make binary indistributable due to license incompatibility](https://github.com/opensvc/multipath-tools/issues/36). * `SCHED_RT_PRIO={0-99}`: for values {1-99} set the realtime priority - multipathd will attempt to run with. for value 0, disable multipathd + multipathd will attempt to run with. For value 0, disable multipathd changing itself to a realtime process. * `ENABLE_LIBDMMP=0`: disable building libdmmp * `ENABLE_DMEVENTS_POLL=0`: disable support for the device-mapper event
multipathd/Makefile +4 -1
@@ -21,6 +21,9 @@ CLI_LIBDEPS := -L$(mpathutildir) -lmpathutil -L$(mpathcmddir) -lmpathcmd \ LIBDEPS := -L$(multipathdir) -lmultipath -L$(mpathpersistdir) -lmpathpersist \ -ldevmapper $(CLI_LIBDEPS) +ifdef SCHED_RT_PRIO +PR_CPPFLAGS := -DSCHED_RT_PRIO=$(SCHED_RT_PRIO) +endif ifeq ($(READLINE),libedit) RL_CPPFLAGS := -DUSE_LIBEDIT RL_LIBDEPS := -ledit
@@ -58,7 +61,7 @@ cli_handlers.o: cli_handlers.c $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused-parameter -c -o $@ $< main.o: main.c - $(Q)$(CC) $(CPPFLAGS) -DSCHED_RT_PRIO=$(SCHED_RT_PRIO) $(CFLAGS) -c -o $@ $< + $(Q)$(CC) $(CPPFLAGS) $(PR_CPPFLAGS) $(CFLAGS) -c -o $@ $< install: $(Q)$(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir)
multipathd/main.c +21 -7
@@ -3171,14 +3171,29 @@ static voidsetscheduler (void) {int res; -static struct sched_param sched_param = { - .sched_priority =SCHED_RT_PRIO - }; +static struct sched_param sched_param; + +#ifdef SCHED_RT_PRIO +if (SCHED_RT_PRIO <=0 ) +return ; + sched_param.sched_priority =SCHED_RT_PRIO ; +#else +struct rlimit rlim; + +if (getrlimit (RLIMIT_RTPRIO , &rlim) <0 || rlim.rlim_max ==0 ) +return ; + sched_param.sched_priority = rlim.rlim_max >INT_MAX ?INT_MAX : + rlim.rlim_max; +#endif + res =sched_get_priority_max (SCHED_RR ); +if (res >0 && res < sched_param.sched_priority) + sched_param.sched_priority = res; - res =sched_setscheduler (0 ,SCHED_RR , &sched_param); + res =sched_setscheduler (0 ,SCHED_RR , &sched_param);if (res ==-1 ) -condlog (2 ,"Could not set SCHED_RR at priority 99" ); +condlog (2 ,"Could not set SCHED_RR at priority %d" , + sched_param.sched_priority);return ; }
@@ -3471,8 +3486,7 @@ child (__attribute__((unused)) void *param)if (!vecs) goto failed; -if (SCHED_RT_PRIO ) -setscheduler (); +setscheduler ();set_oom_adj ();#ifdef FPIN_EVENT_HANDLER if (conf->marginal_pathgroups ==MARGINAL_PATHGROUP_FPIN )
Signature · 1 line
2.43.0
Quoted 12 lines · Benjamin Marzinski
With this change, if the
SCHED_RT_PRIOcompiler flag is not set, multipathd will callgetrlimit(RLIMIT_RTPRIO, ...)and look at the hard
limit. It it's 0, multipath will do nothing. Otherwise it will change its scheduling policy toSCHED_RRand its priority to the hard limit.This allows users to change the priority of that multipathd runs with by
addingLimitRTPRIO=<prio>
Quoted 7 lines
to the [Service] section of the multipathd.service unit file. Setting LimitRTPRIO=0 will make multipathd run as a normal process, while setting LimitRTPRIO=infinity will make it use the maximum
SCHED_RRprio,
which is 99.Signed-off-by Benjamin Marzinski <[email protected]>
This looks good to me, but do we really need both the RLIMIT_RTPRIO and the SCHED_RT_PRIO mechanism?
Thanks,
Martin
Benjamin Marzinski
maintainerQuoted 19 lines · Martin Wilck
Quoted 18 lines · Benjamin Marzinski
With this change, if the
SCHED_RT_PRIOcompiler flag is not set, multipathd will callgetrlimit(RLIMIT_RTPRIO, ...)and look at the hard
limit. It it's 0, multipath will do nothing. Otherwise it will change its scheduling policy toSCHED_RRand its priority to the hard limit.This allows users to change the priority of that multipathd runs with by
addingLimitRTPRIO=<prio>
to the [Service] section of the multipathd.service unit file. Setting LimitRTPRIO=0 will make multipathd run as a normal process, while setting LimitRTPRIO=infinity will make it use the maximum
SCHED_RRprio,
which is 99.
Quoted 4 lines
Quoted 1 line
Signed-off-by Benjamin Marzinski <[email protected]>This looks good to me, but do we really need both the
RLIMIT_RTPRIOand theSCHED_RT_PRIOmechanism?
Not if https://github.com/dracutdevs/dracut/pull/2563 ever gets merged, we don't. Until then it seemed easier to keep a knob to let us control this ourselves, rather than try to sync with a change in dracut.
Obviously, I'm still not convinced that it really matters whether or not multipathd is running with SCHED_RR, so we probably could just say that until dracut gets updated, we just don't run in SCHED_RR in the initramfs. I'm fine with pulling the compiler flag if you want.
-Ben
Quoted 3 lines
Thanks,
Martin
Quoted 28 lines · Benjamin Marzinski
Quoted 27 lines · Martin Wilck
Quoted 25 lines · Benjamin Marzinski
With this change, if the
SCHED_RT_PRIOcompiler flag is not set, multipathd will callgetrlimit(RLIMIT_RTPRIO, ...)and look at the
hard
limit. It it's 0, multipath will do nothing. Otherwise it will change
its scheduling policy toSCHED_RRand its priority to the hard limit.This allows users to change the priority of that multipathd runs with
by
addingLimitRTPRIO=<prio>
to the [Service] section of the multipathd.service unit file. Setting
LimitRTPRIO=0 will make multipathd run as a normal process, while setting LimitRTPRIO=infinity will make it use the maximumSCHED_RR
prio,
which is 99.Signed-off-by Benjamin Marzinski <[email protected]>
Quoted 7 lines
Quoted 3 lines
This looks good to me, but do we really need both the
RLIMIT_RTPRIOand
theSCHED_RT_PRIOmechanism?Not if https://github.com/dracutdevs/dracut/pull/2563 ever gets merged,
we don't.
Unfortunately that PR has caused some regressions in the dracut CI which I haven't had time to analyze / fix yet.
Quoted 9 lines
Until then it seemed easier to keep a knob to let us control
this ourselves, rather than try to sync with a change in dracut.Obviously, I'm still not convinced that it really matters whether or not
multipathd is running withSCHED_RR, so we probably could just say that
until dracut gets updated, we just don't run inSCHED_RRin the initramfs. I'm fine with pulling the compiler flag if you want.
I would prefer to have just one way to configure this, unless we have really strong reasons to support both.
Thanks,
Martin