[DTrace-devel] [PATCH v2] Set the lockmem limit to "unlimited" by default

eugene.loh at oracle.com eugene.loh at oracle.com
Mon Feb 12 18:08:56 UTC 2024


From: Eugene Loh <eugene.loh at oracle.com>

Commit d5a2077d ("Locked-memory limit") described the importance of
setting the locked-memory limit appropriately for DTrace, but it put
that burden on users, admittedly providing several mechanisms to do so.

Driven by commit 5a12c51c ("options: ensure lockmem is set before
retrieving probe info"), commit 7e159efa ("Forbid setting lockmem value
with a pragma") eliminated one such mechanism.

That pragma mechanism, however, had proven to be a popular way of
constructing D scripts that could run both under legacy DTrace, which
does not recognize the lockmem option, and DTrace on Linux, which
essentially requires the option.  That is, the mechanism allowed a
script to set the pragma conditionally based on DTrace version.

Further, it is difficult to size the amount of locked memory needed,
and so users end up just routinely setting the limit to "unlimited."

While there are good reasons not to change resource limits quietly, the
usability issues around lockmem have become nuisances.

Therefore, continue to support the lockmem option, but change the default
behavior to set the lockmem limit to "unlimited."

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_open.c                      | 13 ++++++-------
 test/unittest/misc/tst.lockmem-cmdline.r |  9 +++------
 test/unittest/misc/tst.lockmem-cmdline.x | 16 ----------------
 3 files changed, 9 insertions(+), 29 deletions(-)
 delete mode 100755 test/unittest/misc/tst.lockmem-cmdline.x

diff --git a/libdtrace/dt_open.c b/libdtrace/dt_open.c
index 708f1f50..a0a2cefb 100644
--- a/libdtrace/dt_open.c
+++ b/libdtrace/dt_open.c
@@ -1180,6 +1180,7 @@ dtrace_init(dtrace_hdl_t *dtp)
 {
 	int		i;
 	dtrace_optval_t	lockmem = dtp->dt_options[DTRACEOPT_LOCKMEM];
+	struct rlimit	rl;
 
 	/*
 	 * Initialize the BPF library handling.
@@ -1187,14 +1188,12 @@ dtrace_init(dtrace_hdl_t *dtp)
 	dt_dlib_init(dtp);
 
 	/*
-	 * Set the locked-memory limit if so directed by the user.
+	 * Set the locked-memory limit.
 	 */
-        if (lockmem != DTRACEOPT_UNSET) {
-		struct rlimit	rl;
-
-		rl.rlim_cur = rl.rlim_max = lockmem;
-		setrlimit(RLIMIT_MEMLOCK, &rl);
-        }
+	if (lockmem == DTRACEOPT_UNSET)
+		lockmem = RLIM_INFINITY;
+	rl.rlim_cur = rl.rlim_max = lockmem;
+	setrlimit(RLIMIT_MEMLOCK, &rl);
 
 	/*
 	 * Initialize consume handling.
diff --git a/test/unittest/misc/tst.lockmem-cmdline.r b/test/unittest/misc/tst.lockmem-cmdline.r
index 537d655d..a2d5ad5f 100644
--- a/test/unittest/misc/tst.lockmem-cmdline.r
+++ b/test/unittest/misc/tst.lockmem-cmdline.r
@@ -1,12 +1,9 @@
-1
 
              1234
 0
 
              1234
 0
--- @@stderr --
-dtrace: could not enable tracing: failed to create BPF map 'state':
-	The kernel locked-memory limit is possibly too low.  Set a
-	higher limit with the DTrace option '-xlockmem=N'.  Or, use
-	'ulimit -l N' (Kbytes).  Or, make N the string 'unlimited'.
+
+             1234
+0
diff --git a/test/unittest/misc/tst.lockmem-cmdline.x b/test/unittest/misc/tst.lockmem-cmdline.x
deleted file mode 100755
index a779416b..00000000
--- a/test/unittest/misc/tst.lockmem-cmdline.x
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-read MAJOR MINOR <<< `uname -r | grep -Eo '^[0-9]+\.[0-9]+' | tr '.' ' '`
-
-if [ $MAJOR -lt 5 ]; then
-        exit 0
-fi
-if [ $MAJOR -eq 5 -a $MINOR -lt 15 ]; then
-        exit 0
-fi
-
-# Somehow, UEKR6 (5.4.17) has problems with the the locked-memory limit,
-# but UEKR7 (5.15.0) does not
-
-echo "no locked-memory limit on newer kernels?"
-exit 1
-- 
2.18.4




More information about the DTrace-devel mailing list