|
|
acdf5d |
From 261d784c7b0e8c2b33ae8701b12397f2cc6e695b Mon Sep 17 00:00:00 2001
|
|
|
acdf5d |
From: Jan Friesse <jfriesse@redhat.com>
|
|
|
acdf5d |
Date: Mon, 16 Mar 2020 16:57:09 +0100
|
|
|
acdf5d |
Subject: [PATCH 2/2] Add ability to move process into root cgroup
|
|
|
acdf5d |
|
|
|
acdf5d |
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
|
|
|
acdf5d |
---
|
|
|
acdf5d |
spausedd.8 | 8 +++++---
|
|
|
acdf5d |
spausedd.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
|
|
|
acdf5d |
2 files changed, 53 insertions(+), 5 deletions(-)
|
|
|
acdf5d |
|
|
|
acdf5d |
diff --git a/spausedd.8 b/spausedd.8
|
|
|
acdf5d |
index 6c35666..b23e590 100644
|
|
|
acdf5d |
--- a/spausedd.8
|
|
|
acdf5d |
+++ b/spausedd.8
|
|
|
acdf5d |
@@ -1,5 +1,5 @@
|
|
|
acdf5d |
.\"
|
|
|
acdf5d |
-.\" Copyright (c) 2018-2019, Red Hat, Inc.
|
|
|
acdf5d |
+.\" Copyright (c) 2018-2020, Red Hat, Inc.
|
|
|
acdf5d |
.\"
|
|
|
acdf5d |
.\" Permission to use, copy, modify, and/or distribute this software for any
|
|
|
acdf5d |
.\" purpose with or without fee is hereby granted, provided that the above
|
|
|
acdf5d |
@@ -15,7 +15,7 @@
|
|
|
acdf5d |
.\"
|
|
|
acdf5d |
.\" Author: Jan Friesse <jfriesse@redhat.com>
|
|
|
acdf5d |
.\"
|
|
|
acdf5d |
-.Dd Mar 21, 2018
|
|
|
acdf5d |
+.Dd Nov 11, 2020
|
|
|
acdf5d |
.Dt SPAUSEDD 8
|
|
|
acdf5d |
.Os
|
|
|
acdf5d |
.Sh NAME
|
|
|
acdf5d |
@@ -66,7 +66,9 @@ Run on foreground (do not demonize - default).
|
|
|
acdf5d |
Show help.
|
|
|
acdf5d |
.It Fl p
|
|
|
acdf5d |
Do not set RR scheduler.
|
|
|
acdf5d |
-.It Fl t Ar steal_threshold
|
|
|
acdf5d |
+.It Fl P
|
|
|
acdf5d |
+Do not move process to root cgroup.
|
|
|
acdf5d |
+.It Fl m Ar steal_threshold
|
|
|
acdf5d |
Set steal threshold percent. (default is 10 if kernel information is used and
|
|
|
acdf5d |
100 if VMGuestLib is used).
|
|
|
acdf5d |
.It Fl t Ar timeout
|
|
|
acdf5d |
diff --git a/spausedd.c b/spausedd.c
|
|
|
acdf5d |
index 0a6fe65..6a194cd 100644
|
|
|
acdf5d |
--- a/spausedd.c
|
|
|
acdf5d |
+++ b/spausedd.c
|
|
|
acdf5d |
@@ -273,6 +273,42 @@ utils_set_rr_scheduler(void)
|
|
|
acdf5d |
#endif
|
|
|
acdf5d |
}
|
|
|
acdf5d |
|
|
|
acdf5d |
+static void
|
|
|
acdf5d |
+utils_move_to_root_cgroup(void)
|
|
|
acdf5d |
+{
|
|
|
acdf5d |
+ FILE *f;
|
|
|
acdf5d |
+
|
|
|
acdf5d |
+ /*
|
|
|
acdf5d |
+ * /sys/fs/cgroup is hardcoded, because most of Linux distributions are now
|
|
|
acdf5d |
+ * using systemd and systemd uses hardcoded path of cgroup mount point.
|
|
|
acdf5d |
+ *
|
|
|
acdf5d |
+ * This feature is expected to be removed as soon as systemd gets support
|
|
|
acdf5d |
+ * for managing RT configuration.
|
|
|
acdf5d |
+ */
|
|
|
acdf5d |
+ f = fopen("/sys/fs/cgroup/cpu/cpu.rt_runtime_us", "rt");
|
|
|
acdf5d |
+ if (f == NULL) {
|
|
|
acdf5d |
+ log_printf(LOG_DEBUG, "cpu.rt_runtime_us doesn't exists -> "
|
|
|
acdf5d |
+ "system without cgroup or with disabled CONFIG_RT_GROUP_SCHED");
|
|
|
acdf5d |
+ return ;
|
|
|
acdf5d |
+ }
|
|
|
acdf5d |
+ (void)fclose(f);
|
|
|
acdf5d |
+
|
|
|
acdf5d |
+ f = fopen("/sys/fs/cgroup/cpu/tasks", "w");
|
|
|
acdf5d |
+ if (f == NULL) {
|
|
|
acdf5d |
+ log_printf(LOG_WARNING, "Can't open cgroups tasks file for writing");
|
|
|
acdf5d |
+ return ;
|
|
|
acdf5d |
+ }
|
|
|
acdf5d |
+
|
|
|
acdf5d |
+ if (fprintf(f, "%jd\n", (intmax_t)getpid()) <= 0) {
|
|
|
acdf5d |
+ log_printf(LOG_WARNING, "Can't write spausedd pid into cgroups tasks file");
|
|
|
acdf5d |
+ }
|
|
|
acdf5d |
+
|
|
|
acdf5d |
+ if (fclose(f) != 0) {
|
|
|
acdf5d |
+ log_printf(LOG_WARNING, "Can't close cgroups tasks file");
|
|
|
acdf5d |
+ return ;
|
|
|
acdf5d |
+ }
|
|
|
acdf5d |
+}
|
|
|
acdf5d |
+
|
|
|
acdf5d |
/*
|
|
|
acdf5d |
* Signal handlers
|
|
|
acdf5d |
*/
|
|
|
acdf5d |
@@ -603,13 +639,14 @@ poll_run(uint64_t timeout)
|
|
|
acdf5d |
static void
|
|
|
acdf5d |
usage(void)
|
|
|
acdf5d |
{
|
|
|
acdf5d |
- printf("usage: %s [-dDfhp] [-m steal_th] [-t timeout]\n", PROGRAM_NAME);
|
|
|
acdf5d |
+ printf("usage: %s [-dDfhpP] [-m steal_th] [-t timeout]\n", PROGRAM_NAME);
|
|
|
acdf5d |
printf("\n");
|
|
|
acdf5d |
printf(" -d Display debug messages\n");
|
|
|
acdf5d |
printf(" -D Run on background - daemonize\n");
|
|
|
acdf5d |
printf(" -f Run foreground - do not daemonize (default)\n");
|
|
|
acdf5d |
printf(" -h Show help\n");
|
|
|
acdf5d |
printf(" -p Do not set RR scheduler\n");
|
|
|
acdf5d |
+ printf(" -P Do not move process to root cgroup\n");
|
|
|
acdf5d |
printf(" -m steal_th Steal percent threshold\n");
|
|
|
acdf5d |
printf(" -t timeout Set timeout value (default: %u)\n", DEFAULT_TIMEOUT);
|
|
|
acdf5d |
}
|
|
|
acdf5d |
@@ -622,14 +659,16 @@ main(int argc, char **argv)
|
|
|
acdf5d |
long long int tmpll;
|
|
|
acdf5d |
uint64_t timeout;
|
|
|
acdf5d |
int set_prio;
|
|
|
acdf5d |
+ int move_to_root_cgroup;
|
|
|
acdf5d |
|
|
|
acdf5d |
foreground = 1;
|
|
|
acdf5d |
timeout = DEFAULT_TIMEOUT;
|
|
|
acdf5d |
set_prio = 1;
|
|
|
acdf5d |
+ move_to_root_cgroup = 1;
|
|
|
acdf5d |
max_steal_threshold = DEFAULT_MAX_STEAL_THRESHOLD;
|
|
|
acdf5d |
max_steal_threshold_user_set = 0;
|
|
|
acdf5d |
|
|
|
acdf5d |
- while ((ch = getopt(argc, argv, "dDfhpm:t:")) != -1) {
|
|
|
acdf5d |
+ while ((ch = getopt(argc, argv, "dDfhpPm:t:")) != -1) {
|
|
|
acdf5d |
switch (ch) {
|
|
|
acdf5d |
case 'D':
|
|
|
acdf5d |
foreground = 0;
|
|
|
acdf5d |
@@ -659,6 +698,9 @@ main(int argc, char **argv)
|
|
|
acdf5d |
usage();
|
|
|
acdf5d |
exit(1);
|
|
|
acdf5d |
break;
|
|
|
acdf5d |
+ case 'P':
|
|
|
acdf5d |
+ move_to_root_cgroup = 0;
|
|
|
acdf5d |
+ break;
|
|
|
acdf5d |
case 'p':
|
|
|
acdf5d |
set_prio = 0;
|
|
|
acdf5d |
break;
|
|
|
acdf5d |
@@ -677,6 +719,10 @@ main(int argc, char **argv)
|
|
|
acdf5d |
|
|
|
acdf5d |
utils_mlockall();
|
|
|
acdf5d |
|
|
|
acdf5d |
+ if (move_to_root_cgroup) {
|
|
|
acdf5d |
+ utils_move_to_root_cgroup();
|
|
|
acdf5d |
+ }
|
|
|
acdf5d |
+
|
|
|
acdf5d |
if (set_prio) {
|
|
|
acdf5d |
utils_set_rr_scheduler();
|
|
|
acdf5d |
}
|
|
|
acdf5d |
--
|
|
|
acdf5d |
2.18.2
|
|
|
acdf5d |
|