diff mbox

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

Message ID 20180525121929.10112-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson May 25, 2018, 12:19 p.m. UTC
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@chris-wilson.co.uk>
---
 lib/igt_core.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
diff mbox

Patch

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: