summaryrefslogtreecommitdiff
path: root/tests/eviction_common.c
diff options
context:
space:
mode:
authorMichał Winiarski <michal.winiarski@intel.com>2018-06-11 17:52:44 +0200
committerMichał Winiarski <michal.winiarski@intel.com>2018-06-13 12:43:23 +0200
commite4908004547b63131352fbc0ddcdb1d3d55480e0 (patch)
tree3874b2162f31cbb914891c6ea234f02f1977be5b /tests/eviction_common.c
parent30e501adedf2c89839ef1d654a0281155cfbc589 (diff)
igt/evictions: Avoid getting killed by the reaper in mlock
We're little bit too enthusiastic in our initial attempt to lock all available memory. Let's use the mlock probe from lib rather than trying to lock everything that sysinfo.freeram has to offer. Note that we're only tweaking the initial step - it's still possible that we're going to get killed later on. v2: Just increment lock instead of modifying addr passed to mlock Signed-off-by: Michał Winiarski <michal.winiarski@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Ewelina Musial <ewelina.musial@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Ewelina Musial <ewelina.musial@intel.com>
Diffstat (limited to 'tests/eviction_common.c')
-rw-r--r--tests/eviction_common.c54
1 files changed, 21 insertions, 33 deletions
diff --git a/tests/eviction_common.c b/tests/eviction_common.c
index 300eb03d..8535dfca 100644
--- a/tests/eviction_common.c
+++ b/tests/eviction_common.c
@@ -133,47 +133,33 @@ 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 *mem;
+ uint64_t sz, pin_total;
intel_require_memory(surface_count, surface_size, CHECK_RAM);
sz = surface_size*surface_count;
- pin = intel_get_avail_ram_mb();
- pin *= 1024 * 1024;
- igt_require(pin > sz);
- pin -= sz;
+ pin_total = intel_get_total_pinnable_mem();
+ igt_require(pin_total > sz);
- igt_debug("Pinning [%'lld, %'lld] MiB\n",
- (long long)pin/(1024*1024),
- (long long)(pin + sz)/(1024*1024));
-
- can_mlock = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
- igt_assert(can_mlock != MAP_FAILED);
+ mem = mmap(NULL, pin_total, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);
+ igt_assert(mem != MAP_FAILED);
igt_fork(child, 1) {
- void *locked;
-
- locked = malloc(pin + sz);
- if (locked != NULL && !mlock(locked, pin + sz))
- *can_mlock = 1;
- }
- igt_waitchildren();
- igt_require(*can_mlock);
- munmap(can_mlock, 4096);
-
- igt_fork(child, 1) {
- void *locked;
uint32_t *bo;
uint64_t n;
int ret;
+ size_t lock = pin_total - sz;
- bo = malloc(surface_count*sizeof(*bo));
+ bo = malloc(surface_count * sizeof(*bo));
igt_assert(bo);
+ lock -= ALIGN(surface_count * sizeof(*bo), 4096);
- locked = malloc(pin);
- if (locked == NULL || mlock(locked, pin))
- exit(ENOSPC);
+ igt_debug("Locking %'"PRIu64" B (%'"PRIu64" MiB)\n",
+ lock, lock >> 20);
+ igt_assert(!mlock(mem, lock));
+ igt_info("Locked %'"PRIu64" B (%'"PRIu64" MiB)\n",
+ lock, lock >> 20);
for (n = 0; n < surface_count; n++)
bo[n] = ops->create(fd, surface_size);
@@ -188,17 +174,19 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops,
* our pages into memory), start a memory hog to
* force evictions.
*/
-
- locked = malloc(surface_size);
- if (locked == NULL || mlock(locked, surface_size))
- free(locked);
+ lock += surface_size;
+ igt_assert(!mlock(mem, lock));
+ igt_debug("Total locked %'"PRIu64" B (%'"PRIu64" MiB)\n",
+ lock,
+ lock >> 20);
}
for (n = 0; n < surface_count; n++)
ops->close(fd, bo[n]);
}
-
igt_waitchildren();
+
+ munmap(mem, pin_total);
}
static int swapping_evictions(int fd, struct igt_eviction_test_ops *ops,