From 6be2dc8ddfa332d129149aa3b13db14fa2cd6c0a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 19 Feb 2019 22:17:45 +0000 Subject: lib: Incrementally mlock() As we already have the previous portion of the mmap mlocked, we only need to mlock() the fresh portion for testing available memory. v2: Fixup the uint64_t pointer arithmetric and only use a single mmap to avoid subsequent mlock fail (for reasons unknown, but bet on mm/). Signed-off-by: Chris Wilson Cc: Caz Yokoyama Reviewed-by: Caz Yokoyama --- tests/eviction_common.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tests/eviction_common.c') diff --git a/tests/eviction_common.c b/tests/eviction_common.c index 321772ba..a3b9e416 100644 --- a/tests/eviction_common.c +++ b/tests/eviction_common.c @@ -133,23 +133,24 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops, uint64_t surface_size, uint64_t surface_count) { + uint64_t sz, pin, total; void *mem; - uint64_t sz, pin_total; intel_require_memory(surface_count, surface_size, CHECK_RAM); - sz = surface_size*surface_count; - pin_total = intel_get_total_pinnable_mem(); - igt_require(pin_total > sz); - - mem = mmap(NULL, pin_total, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0); + mem = intel_get_total_pinnable_mem(&total); igt_assert(mem != MAP_FAILED); + pin = *(uint64_t *)mem; + igt_assert(!munlock(mem, pin)); + + sz = surface_size * surface_count; + igt_require(pin > sz); igt_fork(child, 1) { uint32_t *bo; uint64_t n; int ret; - size_t lock = pin_total - sz; + size_t lock = pin - sz; bo = malloc(surface_count * sizeof(*bo)); igt_assert(bo); @@ -186,7 +187,7 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops, } igt_waitchildren(); - munmap(mem, pin_total); + munmap(mem, total); } static int swapping_evictions(int fd, struct igt_eviction_test_ops *ops, -- cgit v1.2.3