From d592fb9d40084de0d4bd107e817233b2ac5bb1b9 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 9 Mar 2017 12:27:32 +0000 Subject: igt/evictions: Isolate the mlock check in a separate process The initial mlock() is to check we can assigned all of memory to ourselves -- without the kernel killing us. Move that check to an isolated process so that we sacrifice the child. Signed-off-by: Chris Wilson --- tests/eviction_common.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'tests/eviction_common.c') diff --git a/tests/eviction_common.c b/tests/eviction_common.c index e39555de..300eb03d 100644 --- a/tests/eviction_common.c +++ b/tests/eviction_common.c @@ -133,8 +133,8 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops, uint64_t surface_size, uint64_t surface_count) { + unsigned int *can_mlock; uint64_t sz, pin; - void *locked; intel_require_memory(surface_count, surface_size, CHECK_RAM); @@ -148,17 +148,22 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops, (long long)pin/(1024*1024), (long long)(pin + sz)/(1024*1024)); - locked = malloc(pin + sz); - if (locked != NULL && mlock(locked, pin + sz)) { - free(locked); - locked = NULL; - } else { - munlock(locked, pin + sz); - free(locked); + can_mlock = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + igt_assert(can_mlock != MAP_FAILED); + + igt_fork(child, 1) { + void *locked; + + locked = malloc(pin + sz); + if (locked != NULL && !mlock(locked, pin + sz)) + *can_mlock = 1; } - igt_require(locked); + igt_waitchildren(); + igt_require(*can_mlock); + munmap(can_mlock, 4096); igt_fork(child, 1) { + void *locked; uint32_t *bo; uint64_t n; int ret; -- cgit v1.2.3