Skip to contentSkip to conversation

mdadm/systemd: change KillMode from none to mixed in service files

PATCH In review Coly Li 5 participants 10 messages Dec 1, 2021 – Dec 8, 2021 MD RAID

lore
Share & tools
lore

Coly Li

author
#0 lore raw

PATCH 1/1 mdadm/systemd: change KillMode from none to mixed in service files

For mdadm's systemd configuration, current systemd KillMode is "none" in following service files,
- [email protected]
- [email protected]

This "none" mode is strongly recommended againsted by systemd developers (see man 5 system.kill for "KillMode=" section), and is considering to remove in future systemd version.

A proper KillMode is "mixed", which is explained in the system.kill man page as,
"If set to mixed, the SIGTERM signal (see below) is sent to the main process while the subsequent SIGKILL signal (see below) is sent to all remaining processes of the unit's control group."

This patch changes KillMode in above listed service files from "none" to "mixed", to follow systemd recommendation and avoid potential unnecessary issue.

---
 systemd/[email protected] | 2 +-
 systemd/[email protected]               | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
systemd/[email protected] +1 -1
index 5c667d2..5fe9d99 100644
@@ -14,4 +14,4 @@ ExecStart=BINDIR/mdadm --grow --continue /dev/%I
 StandardInput=null
 StandardOutput=null
 StandardError=null
-KillMode=none
+KillMode=mixed
systemd/[email protected] +1 -1
index 85a3a7c..5ef1bf5 100644
@@ -25,4 +25,4 @@ Type=forking
 # it out) and systemd will remove it when transitioning from
 # initramfs to rootfs.
 #PIDFile=/run/mdadm/%I.pid
-KillMode=none
+KillMode=mixed
Signature · 1 line
2.31.1
#1 lore raw

Hi Coly,

Quoted 3 lines

This patch changes KillMode in above listed service files from "none" to "mixed", to follow systemd recommendation and avoid potential unnecessary issue.

What about mdmonitor.service? Should we add it there too? Now it is not defined.

Quoted 1 line
Cc Jes Sorensen <[email protected]>

Not sure if it a problem but Jes uses: [email protected] for communication with linux-raid.

Thanks,
Mariusz

author
#2 lore raw
Quoted 7 lines · mtkaczyk

Hi Coly,

Quoted 3 lines

This patch changes KillMode in above listed service files from "none" to "mixed", to follow systemd recommendation and avoid potential unnecessary issue.

What about mdmonitor.service? Should we add it there too? Now it is not defined.

It was overlooked when I did grep KillMode. Yes, I agree mdmonitor.service should have a KillMode key word as well.

Let me post a v2 version.

Quoted 3 lines
Quoted 1 line
Cc Jes Sorensen <[email protected]>

Not sure if it a problem but Jes uses: [email protected] for communication with linux-raid.

Copied. Thanks for the hint.

Coly Li

#3 lore raw

Hi all,

Quoted 6 lines · Coly Li
Quoted 5 lines · mtkaczyk

Hi Coly,

Quoted 3 lines

This patch changes KillMode in above listed service files from "none" to "mixed", to follow systemd recommendation and avoid potential unnecessary issue.

Quoted 7 lines
Quoted 2 lines

What about mdmonitor.service? Should we add it there too? Now it is not defined.

It was overlooked when I did grep KillMode. Yes, I agree mdmonitor.service should have a KillMode key word as well.

Let me post a v2 version.

JFYI, when KillMode is not set, it defaults to KillMode=control-group, see https://www.freedesktop.org/software/systemd/man/systemd.kill.html.

Therefore, it shouldn't be necessary to explicitly add it (as long as control-group is working in case of mdmonitor.service, of course).

Best
Benjamin

Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Cc Jes Sorensen <[email protected]>

Not sure if it a problem but Jes uses: [email protected] for communication with linux-raid.

Copied. Thanks for the hint.

Coly Li

Signature · 9 lines
Benjamin Brunner
Engineering Manager System Boot and Init
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5
90409 Nürnberg
Germany

HRB 36809, AG Nürnberg
Geschäftsführer: Ivo Totev
author
#4 lore raw
Quoted 12 lines · Benjamin Brunner

Hi all,

Quoted 9 lines · Coly Li
Quoted 7 lines · mtkaczyk

Hi Coly,

Quoted 3 lines

This patch changes KillMode in above listed service files from "none" to "mixed", to follow systemd recommendation and avoid potential unnecessary issue.

What about mdmonitor.service? Should we add it there too? Now it is not defined.

Quoted 7 lines
Quoted 4 lines

It was overlooked when I did grep KillMode. Yes, I agree mdmonitor.service should have a KillMode key word as well.

Let me post a v2 version.

JFYI, when KillMode is not set, it defaults to KillMode=control-group, see https://www.freedesktop.org/software/systemd/man/systemd.kill.html.

Therefore, it shouldn't be necessary to explicitly add it (as long as control-group is working in case of mdmonitor.service, of course).

Hi Benjamin,

Please correct me if I am wrong, I see the difference of the KillMode is,
-- KillMode=mixed stops the processes more gentally, it kill the main process with SIGTERM and the remaining processes with SIGKILL. -- KillMode=control-group kills all in-cgroup processes with SIGKILL, which I feel a bit cruel for the main process.

IMHO both method (explicit mixed mode or implicit control-group mode) should works for the fixing issue, but I feel removing the KillMode lines might be better as you indicated since the files can be a bit simpler. Do I understand you correct ?

Thanks.

Coly Li

#5 lore raw
Quoted 24 lines · Coly Li
Quoted 15 lines · Benjamin Brunner

Hi all,

Quoted 12 lines · Coly Li
Quoted 7 lines · mtkaczyk

Hi Coly,

Quoted 3 lines

This patch changes KillMode in above listed service files from "none" to "mixed", to follow systemd recommendation and avoid potential unnecessary issue.

What about mdmonitor.service? Should we add it there too? Now it is not defined.

It was overlooked when I did grep KillMode. Yes, I agree mdmonitor.service should have a KillMode key word as well.

Quoted 7 lines
Quoted 2 lines

Let me post a v2 version.

JFYI, when KillMode is not set, it defaults to KillMode=control-group, see https://www.freedesktop.org/software/systemd/man/systemd.kill.html.

Therefore, it shouldn't be necessary to explicitly add it (as long as control-group is working in case of mdmonitor.service, of course).

Quoted 7 lines

Hi Benjamin,

Please correct me if I am wrong, I see the difference of the KillMode is, -- KillMode=mixed stops the processes more gentally, it kill the main process with SIGTERM and the remaining processes with SIGKILL. -- KillMode=control-group kills all in-cgroup processes with SIGKILL, which I feel a bit cruel for the main process.

There is no point sending SIGTERM to a process which doesn't respond to it. mdmon is the only mdadm service which handles SIGTERM. So it might make sense to uise KillMode=mixed for that.
For anything else, SIGKILL via KillMode=control-group is perfectly acceptable.

NeilBrown

Quoted 11 lines

IMHO both method (explicit mixed mode or implicit control-group mode) should works for the fixing issue, but I feel removing the KillMode lines might be better as you indicated since the files can be a bit simpler. Do I understand you correct ?

Thanks.

Coly Li

author
#6 lore raw
Quoted 30 lines · NeilBrown
Quoted 22 lines · Coly Li
Quoted 14 lines · Benjamin Brunner

Hi all,

Quoted 11 lines · Coly Li
Quoted 7 lines · mtkaczyk

Hi Coly,

Quoted 3 lines

This patch changes KillMode in above listed service files from "none" to "mixed", to follow systemd recommendation and avoid potential unnecessary issue.

What about mdmonitor.service? Should we add it there too? Now it is not defined.

It was overlooked when I did grep KillMode. Yes, I agree mdmonitor.service should have a KillMode key word as well.

Quoted 7 lines
Quoted 2 lines

Let me post a v2 version.

JFYI, when KillMode is not set, it defaults to KillMode=control-group, see https://www.freedesktop.org/software/systemd/man/systemd.kill.html.

Therefore, it shouldn't be necessary to explicitly add it (as long as control-group is working in case of mdmonitor.service, of course).

Quoted 7 lines

Hi Benjamin,

Please correct me if I am wrong, I see the difference of the KillMode is, -- KillMode=mixed stops the processes more gentally, it kill the main process with SIGTERM and the remaining processes with SIGKILL. -- KillMode=control-group kills all in-cgroup processes with SIGKILL, which I feel a bit cruel for the main process.

Quoted 5 lines

There is no point sending SIGTERM to a process which doesn't respond to it. mdmon is the only mdadm service which handles SIGTERM. So it might make sense to uise KillMode=mixed for that.
For anything else, SIGKILL via KillMode=control-group is perfectly acceptable.

Hi Neil,

Thanks for the hint. So it seems remove the KillMode= lines from the systemd files might be best choice.

Hi Benjamin,

How do you think about removing the KillMode= lines to use SIGKILL as default action ?

Thanks.

Coly Li

#7 lore raw

Hi,

Quoted 37 lines · Coly Li
Quoted 30 lines · NeilBrown
Quoted 22 lines · Coly Li
Quoted 14 lines · Benjamin Brunner

Hi all,

Quoted 11 lines · Coly Li
Quoted 7 lines · mtkaczyk

Hi Coly,

Quoted 3 lines

This patch changes KillMode in above listed service files from "none" to "mixed", to follow systemd recommendation and avoid potential unnecessary issue.

What about mdmonitor.service? Should we add it there too? Now it is not defined.

It was overlooked when I did grep KillMode. Yes, I agree mdmonitor.service should have a KillMode key word as well.

Quoted 7 lines
Quoted 2 lines

Let me post a v2 version.

JFYI, when KillMode is not set, it defaults to KillMode=control-group, see https://www.freedesktop.org/software/systemd/man/systemd.kill.html.

Therefore, it shouldn't be necessary to explicitly add it (as long as control-group is working in case of mdmonitor.service, of course).

Quoted 7 lines

Hi Benjamin,

Please correct me if I am wrong, I see the difference of the KillMode is, -- KillMode=mixed stops the processes more gentally, it kill the main process with SIGTERM and the remaining processes with SIGKILL. -- KillMode=control-group kills all in-cgroup processes with SIGKILL, which I feel a bit cruel for the main process.

Quoted 5 lines

There is no point sending SIGTERM to a process which doesn't respond to it.  mdmon is the only mdadm service which handles SIGTERM.  So it might make sense to uise KillMode=mixed for that.
For anything else, SIGKILL via KillMode=control-group is perfectly acceptable.

Quoted 8 lines

Hi Neil,

Thanks for the hint. So it seems remove the KillMode= lines from the systemd files might be best choice.

Hi Benjamin,

How do you think about removing the KillMode= lines to use SIGKILL as default action ?

From my PoV, this should be fine. To be on the safe side, I've added Franck Bui, our systemd maintainer, to the list of recipients.

Franck, could you have a look as well, please?

Thanks,
Benjamin

Quoted 4 lines

Thanks.

Coly Li

Signature · 9 lines
Benjamin Brunner
Engineering Manager System Boot and Init
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5
90409 Nürnberg
Germany

HRB 36809, AG Nürnberg
Geschäftsführer: Ivo Totev
#8 lore raw

Hi,

Quoted 5 lines · Benjamin Brunner
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Please correct me if I am wrong, I see the difference of the KillMode is, -- KillMode=mixed stops the processes more gentally, it kill the main process with SIGTERM and the remaining processes with SIGKILL. -- KillMode=control-group kills all in-cgroup processes with SIGKILL, which I feel a bit cruel for the main process.

I think there's a miss-understanding here.

Regardless of whether "mixed" or "control-group" mode (or any other mode actually) is used, the process used to kill processes part of a service is always the same, only the list of the killed processes differs.

The process is as follow:

1. send the signal specified by KillSignal= to the list of processes (if any), TERM is the default
2. wait until either the target of process(es) exit or a timeout expires
3. if the timeout expires send the signal specified by FinalKillSignal=, KILL is the default

For "control-group", all remaining processes will receive the SIGTERM signal (by default) and if there are still processes after a period f time, they will get the SIGKILL signal.

For "mixed", only the main process will receive the SIGTERM signal, and if there are still processes after a period of time, all remaining processes (including the main one) will receive the SIGKILL signal.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

There is no point sending SIGTERM to a process which doesn't respond to it.  mdmon is the only mdadm service which handles SIGTERM.  So it might make sense to uise KillMode=mixed for that.
For anything else, SIGKILL via KillMode=control-group is perfectly acceptable.

I don't know enough mdadm to suggest a mode but maybe the clarification above will help you figuring this out.

That said it sounds a bit strange that some processes don't respond to SIGTERM. Is that done because some services need to run lately during the shutdown process ?

Thanks.

#9 lore raw
Quoted 37 lines · Franck Bui

Hi,

Quoted 5 lines · Benjamin Brunner
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Please correct me if I am wrong, I see the difference of the KillMode is, -- KillMode=mixed stops the processes more gentally, it kill the main process with SIGTERM and the remaining processes with SIGKILL. -- KillMode=control-group kills all in-cgroup processes with SIGKILL, which I feel a bit cruel for the main process.

I think there's a miss-understanding here.

Regardless of whether "mixed" or "control-group" mode (or any other mode actually) is used, the process used to kill processes part of a service is always the same, only the list of the killed processes differs.

The process is as follow:

1. send the signal specified by KillSignal= to the list of processes (if any), TERM is the default
2. wait until either the target of process(es) exit or a timeout expires
3. if the timeout expires send the signal specified by FinalKillSignal=, KILL is the default

For "control-group", all remaining processes will receive the SIGTERM signal (by default) and if there are still processes after a period f time, they will get the SIGKILL signal.

For "mixed", only the main process will receive the SIGTERM signal, and if there are still processes after a period of time, all remaining processes (including the main one) will receive the SIGKILL signal.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

There is no point sending SIGTERM to a process which doesn't respond to it.  mdmon is the only mdadm service which handles SIGTERM.  So it might make sense to uise KillMode=mixed for that.
For anything else, SIGKILL via KillMode=control-group is perfectly acceptable.

Quoted 5 lines

I don't know enough mdadm to suggest a mode but maybe the clarification above will help you figuring this out.

That said it sounds a bit strange that some processes don't respond to SIGTERM. Is that done because some services need to run lately during the shutdown process ?

When I wrote that they don't respond to SIGTERM, I meant that they don't take any special action. They don't ignore SIGTERM, so they will exit when they are sent it. i.e. it doesn't matter whether they get SIGTERM or SIGKILL - either way they will exit.

NeilBrown