-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
util/mon: pass reserved account by reference #83629
Conversation
494db82
to
09e4f6b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 57 of 57 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @michae2 and @yuzefovich)
pkg/sql/conn_executor.go
line 760 at r2 (raw file):
// also cannot close it before closeWrapper since we need to close the // internal monitors of the connExecutor first. defer reserved.Close(ctx)
- if you pull the
defer
out of the closure, you'll save some bytes.
defer reserved.Close(ctx)
defer func() { ... }()
return h.ex.run
- you can save the entire allocation by passing the outer variables as arg:
defer func(ctx context.Context, h ConnectionHandler) {...} (ctx, h)
This commit makes it so that we now pass the `reserved` memory account when starting up memory monitors by reference. Previously, due to passing by value, when the monitor is stopped, the copy of the value would get used so that the actual "reserved" memory account would get out of sync with its user. This is now fixed. However, this bug doesn't really have any production impact since we use this "reserved" feature in a handful of places and these "reserved" memory accounts are not reused between different usages. Additionally, this commit renames `MakeStandaloneBudget` to `NewStandaloneBudget` (since it now returns a reference) and adds a separate "start" method when the caller doesn't want to pre-reserve anything when starting up a monitor. Release note: None
This commit makes it more clear that the "reserved" memory account created for each connection is closed when that connection is closed. Previously, the account was already cleared (when "session root" monitor is stopped which happens when the connExecutor stops), so there was no leak in the accounting system because of it, yet it wasn't obvious - this commit makes it more obvious. Release note: None
581c07d
to
f1a8710
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTR!
bors r+
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz and @michae2)
pkg/sql/conn_executor.go
line 760 at r2 (raw file):
Previously, knz (kena) wrote…
- if you pull the
defer
out of the closure, you'll save some bytes.defer reserved.Close(ctx) defer func() { ... }() return h.ex.run
- you can save the entire allocation by passing the outer variables as arg:
defer func(ctx context.Context, h ConnectionHandler) {...} (ctx, h)
Done.
Build failed (retrying...): |
Build succeeded: |
util/mon: pass reserved account by reference
This commit makes it so that we now pass the
reserved
memory accountwhen starting up memory monitors by reference. Previously, due to
passing by value, when the monitor is stopped, the copy of the value
would get used so that the actual "reserved" memory account would get
out of sync with its user. This is now fixed. However, this bug doesn't
really have any production impact since we use this "reserved" feature
in a handful of places and these "reserved" memory accounts are not
reused between different usages.
Additionally, this commit renames
MakeStandaloneBudget
toNewStandaloneBudget
(since it now returns a reference) and addsa separate "start" method when the caller doesn't want to pre-reserve
anything when starting up a monitor.
Release note: None
sql: make sure to close the reserved account for each session
This commit makes it more clear that the "reserved" memory account
created for each connection is closed when that connection is closed.
Previously, the account was already cleared (when "session root" monitor
is stopped which happens when the connExecutor stops), so there was no
leak in the accounting system because of it, yet it wasn't obvious - this
commit makes it more obvious.
Release note: None