diff options
author | Bryan Cantrill <bryan@joyent.com> | 2011-07-08 14:24:15 -0700 |
---|---|---|
committer | Bryan Cantrill <bryan@joyent.com> | 2011-07-08 14:24:15 -0700 |
commit | 6fb4854bed54ce82bd8610896b64ddebcd4af706 (patch) | |
tree | 44174bca0ecde59d19ec2cf507cdd03bfd6fafbc /usr/src | |
parent | ec57c73d4fc9c578fb346a0ee62c842c5b66fb97 (diff) | |
download | illumos-gate-6fb4854bed54ce82bd8610896b64ddebcd4af706.tar.gz |
1452 DTrace buffer autoscaling should be less violent
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Approved by: Garrett D'Amore <garrett@nexenta.com>
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize1.d | 8 | ||||
-rw-r--r-- | usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize2.d | 8 | ||||
-rw-r--r-- | usr/src/lib/libdtrace/common/dt_options.c | 27 | ||||
-rw-r--r-- | usr/src/uts/common/dtrace/dtrace.c | 33 |
4 files changed, 24 insertions, 52 deletions
diff --git a/usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize1.d b/usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize1.d index 396a808116..ca8ad44a62 100644 --- a/usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize1.d +++ b/usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize1.d @@ -24,8 +24,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * ASSERTION: * Checks that setting "bufresize" to "auto" will cause buffer @@ -34,14 +32,8 @@ * SECTION: Buffers and Buffering/Buffer Resizing Policy; * Options and Tunables/bufsize; * Options and Tunables/bufresize - * - * NOTES: - * We use the undocumented "preallocate" option to make sure dtrace(1M) - * has enough space in its heap to allocate a buffer as large as the - * kernel's trace buffer. */ -#pragma D option preallocate=100t #pragma D option bufresize=auto #pragma D option bufsize=100t diff --git a/usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize2.d b/usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize2.d index 50b814b1bf..ddb97c89ec 100644 --- a/usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize2.d +++ b/usr/src/cmd/dtrace/test/tst/common/buffering/tst.resize2.d @@ -24,8 +24,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * ASSERTION: * Checks that setting "bufresize" to "auto" will cause buffer @@ -34,14 +32,8 @@ * SECTION: Buffers and Buffering/Buffer Resizing Policy; * Options and Tunables/aggsize; * Options and Tunables/bufresize - * - * NOTES: - * We use the undocumented "preallocate" option to make sure dtrace(1M) - * has enough space in its heap to allocate a buffer as large as the - * kernel's trace buffer. */ -#pragma D option preallocate=100t #pragma D option bufresize=auto #pragma D option aggsize=100t diff --git a/usr/src/lib/libdtrace/common/dt_options.c b/usr/src/lib/libdtrace/common/dt_options.c index 5353bfae52..426f8cb73c 100644 --- a/usr/src/lib/libdtrace/common/dt_options.c +++ b/usr/src/lib/libdtrace/common/dt_options.c @@ -24,8 +24,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/resource.h> #include <sys/mman.h> #include <sys/types.h> @@ -837,30 +835,6 @@ dt_options_load(dtrace_hdl_t *dtp) return (0); } -/*ARGSUSED*/ -static int -dt_opt_preallocate(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) -{ - dtrace_optval_t size; - void *p; - - if (arg == NULL || dt_optval_parse(arg, &size) != 0) - return (dt_set_errno(dtp, EDT_BADOPTVAL)); - - if (size > SIZE_MAX) - size = SIZE_MAX; - - if ((p = dt_zalloc(dtp, size)) == NULL) { - do { - size /= 2; - } while ((p = dt_zalloc(dtp, size)) == NULL); - } - - dt_free(dtp, p); - - return (0); -} - typedef struct dt_option { const char *o_name; int (*o_func)(dtrace_hdl_t *, const char *, uintptr_t); @@ -899,7 +873,6 @@ static const dt_option_t _dtrace_ctoptions[] = { { "linktype", dt_opt_linktype }, { "nolibs", dt_opt_cflags, DTRACE_C_NOLIBS }, { "pgmax", dt_opt_pgmax }, - { "preallocate", dt_opt_preallocate }, { "pspec", dt_opt_cflags, DTRACE_C_PSPEC }, { "stdc", dt_opt_stdc }, { "strip", dt_opt_dflags, DTRACE_D_STRIP }, diff --git a/usr/src/uts/common/dtrace/dtrace.c b/usr/src/uts/common/dtrace/dtrace.c index 1a0599ca31..b6be08379f 100644 --- a/usr/src/uts/common/dtrace/dtrace.c +++ b/usr/src/uts/common/dtrace/dtrace.c @@ -10288,14 +10288,17 @@ dtrace_buffer_activate(dtrace_state_t *state) static int dtrace_buffer_alloc(dtrace_buffer_t *bufs, size_t size, int flags, - processorid_t cpu) + processorid_t cpu, int *factor) { cpu_t *cp; dtrace_buffer_t *buf; + int allocated = 0, desired = 0; ASSERT(MUTEX_HELD(&cpu_lock)); ASSERT(MUTEX_HELD(&dtrace_lock)); + *factor = 1; + if (size > dtrace_nonroot_maxsize && !PRIV_POLICY_CHOICE(CRED(), PRIV_ALL, B_FALSE)) return (EFBIG); @@ -10320,7 +10323,8 @@ dtrace_buffer_alloc(dtrace_buffer_t *bufs, size_t size, int flags, ASSERT(buf->dtb_xamot == NULL); - if ((buf->dtb_tomax = kmem_zalloc(size, KM_NOSLEEP)) == NULL) + if ((buf->dtb_tomax = kmem_zalloc(size, + KM_NOSLEEP | KM_NORMALPRI)) == NULL) goto err; buf->dtb_size = size; @@ -10331,7 +10335,8 @@ dtrace_buffer_alloc(dtrace_buffer_t *bufs, size_t size, int flags, if (flags & DTRACEBUF_NOSWITCH) continue; - if ((buf->dtb_xamot = kmem_zalloc(size, KM_NOSLEEP)) == NULL) + if ((buf->dtb_xamot = kmem_zalloc(size, + KM_NOSLEEP | KM_NORMALPRI)) == NULL) goto err; } while ((cp = cp->cpu_next) != cpu_list); @@ -10345,16 +10350,19 @@ err: continue; buf = &bufs[cp->cpu_id]; + desired += 2; if (buf->dtb_xamot != NULL) { ASSERT(buf->dtb_tomax != NULL); ASSERT(buf->dtb_size == size); kmem_free(buf->dtb_xamot, size); + allocated++; } if (buf->dtb_tomax != NULL) { ASSERT(buf->dtb_size == size); kmem_free(buf->dtb_tomax, size); + allocated++; } buf->dtb_tomax = NULL; @@ -10362,6 +10370,8 @@ err: buf->dtb_size = 0; } while ((cp = cp->cpu_next) != cpu_list); + *factor = desired / (allocated > 0 ? allocated : 1); + return (ENOMEM); } @@ -12260,7 +12270,7 @@ dtrace_dstate_init(dtrace_dstate_t *dstate, size_t size) if (size < (min = dstate->dtds_chunksize + sizeof (dtrace_dynhash_t))) size = min; - if ((base = kmem_zalloc(size, KM_NOSLEEP)) == NULL) + if ((base = kmem_zalloc(size, KM_NOSLEEP | KM_NORMALPRI)) == NULL) return (ENOMEM); dstate->dtds_size = size; @@ -12622,7 +12632,7 @@ dtrace_state_buffer(dtrace_state_t *state, dtrace_buffer_t *buf, int which) { dtrace_optval_t *opt = state->dts_options, size; processorid_t cpu; - int flags = 0, rval; + int flags = 0, rval, factor, divisor = 1; ASSERT(MUTEX_HELD(&dtrace_lock)); ASSERT(MUTEX_HELD(&cpu_lock)); @@ -12652,7 +12662,7 @@ dtrace_state_buffer(dtrace_state_t *state, dtrace_buffer_t *buf, int which) flags |= DTRACEBUF_INACTIVE; } - for (size = opt[which]; size >= sizeof (uint64_t); size >>= 1) { + for (size = opt[which]; size >= sizeof (uint64_t); size /= divisor) { /* * The size must be 8-byte aligned. If the size is not 8-byte * aligned, drop it down by the difference. @@ -12670,7 +12680,7 @@ dtrace_state_buffer(dtrace_state_t *state, dtrace_buffer_t *buf, int which) return (E2BIG); } - rval = dtrace_buffer_alloc(buf, size, flags, cpu); + rval = dtrace_buffer_alloc(buf, size, flags, cpu, &factor); if (rval != ENOMEM) { opt[which] = size; @@ -12679,6 +12689,9 @@ dtrace_state_buffer(dtrace_state_t *state, dtrace_buffer_t *buf, int which) if (opt[DTRACEOPT_BUFRESIZE] == DTRACEOPT_BUFRESIZE_MANUAL) return (rval); + + for (divisor = 2; divisor < factor; divisor <<= 1) + continue; } return (ENOMEM); @@ -12778,7 +12791,8 @@ dtrace_state_go(dtrace_state_t *state, processorid_t *cpu) goto out; } - spec = kmem_zalloc(nspec * sizeof (dtrace_speculation_t), KM_NOSLEEP); + spec = kmem_zalloc(nspec * sizeof (dtrace_speculation_t), + KM_NOSLEEP | KM_NORMALPRI); if (spec == NULL) { rval = ENOMEM; @@ -12789,7 +12803,8 @@ dtrace_state_go(dtrace_state_t *state, processorid_t *cpu) state->dts_nspeculations = (int)nspec; for (i = 0; i < nspec; i++) { - if ((buf = kmem_zalloc(bufsize, KM_NOSLEEP)) == NULL) { + if ((buf = kmem_zalloc(bufsize, + KM_NOSLEEP | KM_NORMALPRI)) == NULL) { rval = ENOMEM; goto err; } |