[igt-dev] [PATCH i-g-t] lib: Incrementally mlock()

Chris Wilson chris at chris-wilson.co.uk
Tue Feb 19 22:21:10 UTC 2019


As we already have the previous portion of the mmap mlocked, we only
need to mlock() the fresh portion for testing available memory.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Caz Yokoyama <caz at caz-nuc.ra.intel.com>
---
 lib/intel_os.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/intel_os.c b/lib/intel_os.c
index e1e31e230..961442a0d 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -250,22 +250,24 @@ intel_get_total_pinnable_mem(void)
 	}
 
 	for (uint64_t inc = 1024 << 20; inc >= 4 << 10; inc >>= 2) {
-		igt_debug("Testing mlock %'"PRIu64" B (%'"PRIu64" MiB)\n",
-			  *can_mlock, *can_mlock >> 20);
+		uint64_t locked = *can_mlock;
+
+		igt_debug("Testing mlock %'"PRIu64"B (%'"PRIu64"MiB) + %'"PRIu64"B\n",
+			  locked, locked >> 20, inc);
 
 		igt_fork(child, 1) {
-			for (uint64_t bytes = *can_mlock;
-			     bytes <= pin;
-			     bytes += inc) {
-				if (mlock(can_mlock, bytes))
+			uint64_t bytes = *can_mlock;
+
+			while (bytes <= pin) {
+				if (mlock(can_mlock + bytes, inc))
 					break;
 
-				*can_mlock = bytes;
+				*can_mlock = bytes += inc;
 				__sync_synchronize();
 			}
 		}
 		__igt_waitchildren();
-		igt_assert(!mlock(can_mlock, *can_mlock));
+		igt_assert(!mlock(can_mlock + locked, *can_mlock - locked));
 	}
 
 out:
-- 
2.20.1



More information about the igt-dev mailing list