From 1fae9b63c4845eaac8600c6fba7e9947e5937cdd Mon Sep 17 00:00:00 2001 From: William Douglas Date: Sun, 7 Feb 2106 06:27:25 +15094728 Subject: [PATCH] Add nice and IO nice to avoid grinding the system to a halt on a coredump --- corewatcher.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/corewatcher.c b/corewatcher.c index 5e5bd69..4bc1b9e 100644 --- a/corewatcher.c +++ b/corewatcher.c @@ -48,6 +48,23 @@ #define g_timeout_add_seconds(a, b, c) g_timeout_add((a)*1000, b, c) #endif +#if defined(__i386__) +# define __NR_ioprio_set 289 +#elif defined(__x86_64__) +# define __NR_ioprio_set 251 +#elif defined(__arm__) +# define __NR_ioprio_set 314 +#elif defined (__powerpc__) +# define __NR_ioprio_set 273 +#else +# error "Unsupported arch" +#endif +#define IOPRIO_WHO_PROCESS 1 +#define IOPRIO_CLASS_RT 1 +#define IOPRIO_CLASS_IDLE 3 +#define IOPRIO_CLASS_SHIFT 13 +#define IOPRIO_IDLE_LOWEST (7 | (IOPRIO_CLASS_IDLE << IOPRIO_CLASS_SHIFT)) +#define IOPRIO_RT_LOWEST (7 | (IOPRIO_CLASS_RT << IOPRIO_CLASS_SHIFT)) #include "corewatcher.h" @@ -163,6 +180,11 @@ int main(int argc, char**argv) #ifdef PR_SET_TIMERSLACK prctl(PR_SET_TIMERSLACK,1000*1000*1000, 0, 0, 0); #endif + /* Be easier on the rest of the system */ + if (syscall(__NR_ioprio_set, IOPRIO_WHO_PROCESS, pid, + IOPRIO_IDLE_LOWEST) == -1) + perror("Can not set IO priority to lowest IDLE class"); + nice(15); read_config_file("/etc/corewatcher.conf"); -- 2.7.4