Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-23.1.18-rc: util/mon: add cluster setting for disabling monitor tree tracking #121787

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/util/mon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
importpath = "github.com/cockroachdb/cockroach/pkg/util/mon",
visibility = ["//visibility:public"],
deps = [
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/sql/pgwire/pgcode",
"//pkg/sql/pgwire/pgerror",
Expand Down
20 changes: 16 additions & 4 deletions pkg/util/mon/bytes_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"math/bits"
"unsafe"

"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
Expand Down Expand Up @@ -264,11 +265,20 @@ type BytesMonitor struct {
settings *cluster.Settings
}

// enableMonitorTreeTracking indicates whether tracking of all children of a
// BytesMonitor (which is what powers TraverseTree) is enabled.
var enableMonitorTreeTracking = envutil.EnvOrDefaultBool(
// enableMonitorTreeTrackingEnvVar indicates whether tracking of all children of
// a BytesMonitor (which is what powers TraverseTree) is enabled.
var enableMonitorTreeTrackingEnvVar = envutil.EnvOrDefaultBool(
"COCKROACH_ENABLE_MONITOR_TREE", true)

// enableMonitorTreeTrackingSetting indicates whether tracking of all children
// of a BytesMonitor (which is what powers TraverseTree) is enabled.
var enableMonitorTreeTrackingSetting = settings.RegisterBoolSetting(
settings.TenantWritable,
"diagnostics.memory_monitor_tree.enabled",
"enable tracking of memory monitor tree",
true,
)

// MonitorState describes the current state of a single monitor.
type MonitorState struct {
// Level tracks how many "generations" away the current monitor is from the
Expand Down Expand Up @@ -499,7 +509,9 @@ func (mm *BytesMonitor) Start(ctx context.Context, pool *BytesMonitor, reserved

var effectiveLimit int64
if pool != nil {
if enableMonitorTreeTracking {
// mm.settings can be nil in tests in which case we use the default
// value of enableMonitorTreeTrackingSetting cluster setting (true).
if enableMonitorTreeTrackingEnvVar && (mm.settings == nil || enableMonitorTreeTrackingSetting.Get(&mm.settings.SV)) {
// If we have a "parent" monitor, then register mm as its child by
// making it the head of the doubly-linked list.
pool.mu.Lock()
Expand Down