corosync/bz1948974-1-main-Add-suppor...

123 lines
4.4 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 57e6b86b53010dd2612b0a6a4e04917673062ecf Mon Sep 17 00:00:00 2001
From: Jan Friesse <jfriesse@redhat.com>
Date: Mon, 3 May 2021 15:29:04 +0200
Subject: [PATCH 3/7] main: Add support for cgroup v2
Support for cgroup v2 is very similar to cgroup v1 just checking (and
writing) different file.
Testing this feature is a bit harder than with cgroup v1 so it's
probably worh noting in this commit message.
1. Copy some service file (I've used httpd service) and set
CPUQuota=30% in the [service] section.
2. Check /sys/fs/cgroup/cgroup.subtree_control - there should be no
"cpu"
3. Start modified service
4. Check /sys/fs/cgroup/cgroup.subtree_control - there should be "cpu"
5. Start corosync - It should be able to get rt priority
When move_to_root_cgroup is disabled, behavior differs:
- If corosync is started before modified service, so
there is no "cpu" in /sys/fs/cgroup/cgroup.subtree_control
corosync starts without problem and gets rt priority.
Starting modified service later will never add "cpu" into
/sys/fs/cgroup/cgroup.subtree_control (because corosync is holding
rt priority and it is placed in the non-root cgroup by systemd).
- When corosync is started after modified service, so "cpu"
is in /sys/fs/cgroup/cgroup.subtree_control, corosync is not
able to get RT priority.
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
---
exec/main.c | 21 ++++++++++++++++-----
man/corosync.conf.5 | 14 ++++++++++----
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/exec/main.c b/exec/main.c
index aa6d9fbf..65ae5e4f 100644
--- a/exec/main.c
+++ b/exec/main.c
@@ -1173,6 +1173,7 @@ error_close:
static int corosync_move_to_root_cgroup(void) {
FILE *f;
int res = -1;
+ const char *cgroup_task_fname = NULL;
/*
* /sys/fs/cgroup is hardcoded, because most of Linux distributions are now
@@ -1183,15 +1184,25 @@ static int corosync_move_to_root_cgroup(void) {
*/
f = fopen("/sys/fs/cgroup/cpu/cpu.rt_runtime_us", "rt");
if (f == NULL) {
- log_printf(LOGSYS_LEVEL_DEBUG, "cpu.rt_runtime_us doesn't exists -> "
- "system without cgroup or with disabled CONFIG_RT_GROUP_SCHED");
+ /*
+ * Try cgroup v2
+ */
+ f = fopen("/sys/fs/cgroup/cgroup.procs", "rt");
+ if (f == NULL) {
+ log_printf(LOG_DEBUG, "cpu.rt_runtime_us or cgroup.procs doesn't exist -> "
+ "system without cgroup or with disabled CONFIG_RT_GROUP_SCHED");
- res = 0;
- goto exit_res;
+ res = 0;
+ goto exit_res;
+ } else {
+ cgroup_task_fname = "/sys/fs/cgroup/cgroup.procs";
+ }
+ } else {
+ cgroup_task_fname = "/sys/fs/cgroup/cpu/tasks";
}
(void)fclose(f);
- f = fopen("/sys/fs/cgroup/cpu/tasks", "w");
+ f = fopen(cgroup_task_fname, "w");
if (f == NULL) {
log_printf(LOGSYS_LEVEL_WARNING, "Can't open cgroups tasks file for writing");
diff --git a/man/corosync.conf.5 b/man/corosync.conf.5
index 25289ba4..1c9d2ad7 100644
--- a/man/corosync.conf.5
+++ b/man/corosync.conf.5
@@ -1,6 +1,6 @@
.\"/*
.\" * Copyright (c) 2005 MontaVista Software, Inc.
-.\" * Copyright (c) 2006-2020 Red Hat, Inc.
+.\" * Copyright (c) 2006-2021 Red Hat, Inc.
.\" *
.\" * All rights reserved.
.\" *
@@ -32,7 +32,7 @@
.\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
.\" * THE POSSIBILITY OF SUCH DAMAGE.
.\" */
-.TH COROSYNC_CONF 5 2021-04-09 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
+.TH COROSYNC_CONF 5 2021-05-03 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
.SH NAME
corosync.conf - corosync executive configuration file
@@ -800,8 +800,14 @@ meaning maximal / minimal priority (so minimal / maximal nice value).
.TP
move_to_root_cgroup
Should be set to yes (default) if corosync should try to move itself to root
-cgroup. This feature is available only for systems with cgroups with RT
-sched enabled (Linux with CONFIG_RT_GROUP_SCHED kernel option).
+cgroup. This feature is available only for systems with cgroups v1 with RT
+sched enabled (Linux with CONFIG_RT_GROUP_SCHED kernel option) and cgroups v2.
+
+It's worth noting that currently (May 3 2021) cgroup2 doesnt yet
+support control of realtime processes and the cpu controller can only be
+enabled when all RT processes are in the root cgroup. So when move_to_root_cgroup
+is disabled and systemd is used, it may be impossible to make systemd options
+like CPUQuota working correctly until corosync is stopped.
.TP
allow_knet_handle_fallback
--
2.27.0