All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: adjust oom_score
@ 2013-11-13 21:25 Daniel Vetter
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Vetter @ 2013-11-13 21:25 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter, Ben Widawsky

This way the igt test will always be killed first (hopefully),
preventing mayhem when one of the memory thrashing tests treatens to
take down the entire system.

To avoid any burden on test writers we adjust the oom score on
drm_open, any of the fork helpers and subtest init. That should cover
everything.

v2: Fix it up.

Cc: Ben Widawsky <ben@bwidawsk.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 lib/drmtest.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 75f49cd720ee..15ed84749b62 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -204,6 +204,16 @@ int drm_get_card(void)
 	return -1;
 }
 
+static void oom_adjust_for_doom(void)
+{
+	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));
+}
+
 /** Open the first DRM device we can find, searching up to 16 device nodes */
 static int __drm_open_any(void)
 {
@@ -222,6 +232,8 @@ static int __drm_open_any(void)
 		fd = -1;
 	}
 
+	oom_adjust_for_doom();
+
 	return fd;
 }
 
@@ -251,6 +263,8 @@ static int __drm_open_any_render(void)
 		return fd;
 	}
 
+	oom_adjust_for_doom();
+
 	return fd;
 }
 
@@ -844,6 +858,7 @@ int igt_subtest_init_parse_opts(int argc, char **argv,
 	}
 
 	igt_install_exit_handler(check_igt_exit);
+	oom_adjust_for_doom();
 
 out:
 	return ret;
@@ -1115,6 +1130,7 @@ bool __igt_fork_helper(struct igt_helper_process *proc)
 	case 0:
 		exit_handler_count = 0;
 		reset_helper_process_list();
+		oom_adjust_for_doom();
 
 		return true;
 	default:
@@ -1197,6 +1213,7 @@ bool __igt_fork(void)
 		test_child = true;
 		exit_handler_count = 0;
 		reset_helper_process_list();
+		oom_adjust_for_doom();
 
 		return true;
 	default:
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] lib: adjust oom_score
@ 2013-11-11 22:06 Daniel Vetter
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Vetter @ 2013-11-11 22:06 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter, Ben Widawsky

This way the igt test will always be killed first (hopefully),
preventing mayhem when one of the memory thrashing tests treatens to
take down the entire system.

To avoid any burden on test writers we adjust the oom score on
drm_open, any of the fork helpers and subtest init. That should cover
everything.

Cc: Ben Widawsky <ben@bwidawsk.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 lib/drmtest.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index d8fc60f656e4..7f13e0561935 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -203,6 +203,15 @@ int drm_get_card(void)
 	return -1;
 }
 
+static void oom_adjust_for_doom(void)
+{
+	int fd;
+	const char always_kill[] = "1000";
+
+	igt_assert(fd = open("/proc/self/oom_adj", O_WRONLY) != -1);
+	igt_assert(write(fd, always_kill, sizeof(always_kill)) == sizeof(always_kill));
+}
+
 /** Open the first DRM device we can find, searching up to 16 device nodes */
 static int __drm_open_any(void)
 {
@@ -221,6 +230,8 @@ static int __drm_open_any(void)
 		fd = -1;
 	}
 
+	oom_adjust_for_doom();
+
 	return fd;
 }
 
@@ -250,6 +261,8 @@ static int __drm_open_any_render(void)
 		return fd;
 	}
 
+	oom_adjust_for_doom();
+
 	return fd;
 }
 
@@ -843,6 +856,7 @@ int igt_subtest_init_parse_opts(int argc, char **argv,
 	}
 
 	igt_install_exit_handler(check_igt_exit);
+	oom_adjust_for_doom();
 
 out:
 	return ret;
@@ -1114,6 +1128,7 @@ bool __igt_fork_helper(struct igt_helper_process *proc)
 	case 0:
 		exit_handler_count = 0;
 		reset_helper_process_list();
+		oom_adjust_for_doom();
 
 		return true;
 	default:
@@ -1196,6 +1211,7 @@ bool __igt_fork(void)
 		test_child = true;
 		exit_handler_count = 0;
 		reset_helper_process_list();
+		oom_adjust_for_doom();
 
 		return true;
 	default:
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-13 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-13 21:25 [PATCH] lib: adjust oom_score Daniel Vetter
  -- strict thread matches above, loose matches on Subject: below --
2013-11-11 22:06 Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.