dtrace: add a knob to control maximum size of principal buffers

We had a hardcoded limit of 1/128-th of physical memory that was further
subdivided between all CPUs as principal buffers are allocated on the
per-CPU basis.  Actually, the buffers could use up 1/64-th of the
memmory because with the default switch policy there are two buffers per
CPU.

This commit allows to change that limit.

Note that the discussed limit is per dtrace command invocation.
The idea is to limit the size of a single malloc(9) call, not the total
memory size used by DTrace buffers.

Reviewed by:	markj
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D33648
This commit is contained in:
Andriy Gapon 2022-01-11 15:44:46 +02:00
parent 256c8c5df2
commit 7fdf0e8835
2 changed files with 7 additions and 1 deletions

View file

@ -207,6 +207,7 @@ hrtime_t dtrace_deadman_user = (hrtime_t)30 * NANOSEC;
hrtime_t dtrace_unregister_defunct_reap = (hrtime_t)60 * NANOSEC;
#ifndef illumos
int dtrace_memstr_max = 4096;
int dtrace_bufsize_max_frac = 128;
#endif
/*
@ -12205,7 +12206,8 @@ dtrace_buffer_alloc(dtrace_buffer_t *bufs, size_t size, int flags,
* ask to malloc, so let's place a limit here before trying
* to do something that might well end in tears at bedtime.
*/
if (size > physmem * PAGE_SIZE / (128 * (mp_maxid + 1)))
int bufsize_percpu_frac = dtrace_bufsize_max_frac * mp_ncpus;
if (size > physmem * PAGE_SIZE / bufsize_percpu_frac)
return (ENOMEM);
#endif

View file

@ -96,5 +96,9 @@ SYSCTL_QUAD(_kern_dtrace, OID_AUTO, dof_maxsize, CTLFLAG_RW,
SYSCTL_QUAD(_kern_dtrace, OID_AUTO, helper_actions_max, CTLFLAG_RW,
&dtrace_helper_actions_max, 0, "maximum number of allowed helper actions");
SYSCTL_INT(_kern_dtrace, OID_AUTO, bufsize_max, CTLFLAG_RWTUN,
&dtrace_bufsize_max_frac, 0,
"maximum fraction (1/n-th) of physical memory for principal buffers");
SYSCTL_INT(_security_bsd, OID_AUTO, allow_destructive_dtrace, CTLFLAG_RDTUN,
&dtrace_allow_destructive, 1, "Allow destructive mode DTrace scripts");