[igt-dev] [PATCH i-g-t 1/2] lib: Prioritise oom targetting our children.

Chris Wilson chris at chris-wilson.co.uk
Fri May 25 12:19:28 UTC 2018


We are not nice parents and would sacrifice any one of our children so
that the core process can report the failure neatly.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/igt_core.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index e292ca24c..2bee0831b 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -564,17 +564,27 @@ static void print_usage(const char *help_str, bool output_on_stderr)
 		fprintf(f, "%s\n", help_str);
 }
 
-
 static void oom_adjust_for_doom(void)
 {
+	const char always_kill[] = "900"; /* leave room for children! */
 	int fd;
-	const char always_kill[] = "1000";
 
 	fd = open("/proc/self/oom_score_adj", O_WRONLY);
 	igt_assert(fd != -1);
 	igt_assert(write(fd, always_kill, sizeof(always_kill)) == sizeof(always_kill));
 	close(fd);
+}
 
+static void oom_adjust_for_greater_doom(void)
+{
+	const char always_kill[] = "1000";
+	int fd;
+
+	fd = open("/proc/self/oom_score_adj", O_WRONLY);
+	if (fd != -1) {
+		igt_ignore_warn(write(fd, always_kill, sizeof(always_kill)));
+		close(fd);
+	}
 }
 
 #ifdef HAVE_GLIB
@@ -1618,7 +1628,7 @@ bool __igt_fork_helper(struct igt_helper_process *proc)
 		igt_assert(0);
 	case 0:
 		reset_helper_process_list();
-		oom_adjust_for_doom();
+		oom_adjust_for_greater_doom();
 
 		return true;
 	default:
@@ -1721,7 +1731,7 @@ bool __igt_fork(void)
 		test_child = true;
 		exit_handler_count = 0;
 		reset_helper_process_list();
-		oom_adjust_for_doom();
+		oom_adjust_for_greater_doom();
 
 		return true;
 	default:
-- 
2.17.0



More information about the igt-dev mailing list