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

Yokoyama, Caz caz.yokoyama at intel.com
Tue Feb 26 17:42:51 UTC 2019


Chris,
I am OK to give "Reviewed by: XXXX" to your patch.
However, I want to add following comment/modification which does not
affect the effect of your patch.

+				/*
+				 * This is a bug which mlocks far
beyond memory,
+				 * i.e. there is a hole between 3/4 of
avail and
+				 * (bytes * sizeof(*can_mlock)) where
+				 * sizeof(*can_mlock)=8. Because of the
hole, mlock()
+				 * may fail and get out of while loop.
+				 * However, We need the hole. Otherwise
OOM kills parent
+				 * process. Another mlock() below is
same.
+				 */
+				if (mlock((void *)can_mlock + (bytes *
sizeof(*can_mlock)),
+					  inc))
 					break;
-caz
P.S. Sorry for not clean thread sequence. I lost mails.

-----Original Message-----
From: igt-dev [mailto:igt-dev-bounces at lists.freedesktop.org] On Behalf
Of Chris Wilson
Sent: Tuesday, February 19, 2019 14:21
To: igt-dev at lists.freedesktop.org
Cc: Caz Yokoyama <caz at caz-nuc.ra.intel.com>
Subject: [igt-dev] [PATCH i-g-t] 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.

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

_______________________________________________
igt-dev mailing list
igt-dev at lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev



More information about the igt-dev mailing list