Skip to content

Commit

Permalink
Set the lockmem limit to "unlimited" by default
Browse files Browse the repository at this point in the history
Commit d5a2077 ("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 7e159ef ("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@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Feb 20, 2024
1 parent c6e76cc commit 474c4f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
13 changes: 6 additions & 7 deletions libdtrace/dt_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,21 +1180,20 @@ 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.
*/
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.
Expand Down
9 changes: 3 additions & 6 deletions test/unittest/misc/tst.lockmem-cmdline.r
Original file line number Diff line number Diff line change
@@ -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
16 changes: 0 additions & 16 deletions test/unittest/misc/tst.lockmem-cmdline.x

This file was deleted.

0 comments on commit 474c4f0

Please sign in to comment.