-
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
server: catch incomplete available memory detection by gosigar #15841
Conversation
pkg/server/config.go
Outdated
@@ -237,6 +237,12 @@ func GetTotalMemory() (int64, error) { | |||
humanize.IBytes(mem.Total), humanize.Bytes(math.MaxInt64)) | |||
} | |||
totalMem := int64(mem.Total) | |||
checkTotal := func(x int64) error { |
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.
nit: consider making the signature here (int64, error)
. That way you can hold up the usual convention (that you return zero when there's an error) more explicitly.
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.
oh good idea. Done.
pkg/server/config.go
Outdated
} | ||
if cgAvlMem > mem.Total { | ||
if mem.Total > 0 && cgAvlMem > mem.Total { |
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.
mem.Total
is (intuitively, not by type) equal to totalMem
, right? I think it would add to clarity if mem
went out of scope after totalMem
was a thing (even at the cost of a type conversion). Just a suggestion, might be misreading this as well.
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.
It makes the code slightly more readable perhaps. I changed it as you suggested.
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.
sorry to have so many nits for such a small change - you're still free to opt out.
pkg/server/config.go
Outdated
} | ||
if cgAvlMem > mem.Total { | ||
if totalMem > 0 && int64(cgAvlMem) > totalMem { |
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.
looks like we could overflow cgAvlMem
here and in l. 284 during the conversion?
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.
Ah nevermind! You check above.
pkg/server/config.go
Outdated
} | ||
var cgAvlMem uint64 | ||
if cgAvlMem, err = strconv.ParseUint(strings.TrimSpace(string(buf)), 10, 64); err != nil { | ||
if log.V(1) { | ||
log.Infof(context.TODO(), "can't parse available memory from cgroups (%s), using system memory %s instead", err, | ||
humanizeutil.IBytes(totalMem)) | ||
} | ||
return totalMem, nil | ||
return checkTotal(totalMem) | ||
} | ||
if cgAvlMem > math.MaxInt64 { | ||
if log.V(1) { | ||
log.Infof(context.TODO(), "available memory from cgroups is too large and unsupported %s using system memory %s instead", |
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.
this sentence would look weird because cgAvlMem pops up randomly.
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.
What do you mean "looks weird"?
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.
the first %s
is outside of the flow of the sentence. It would look better in parentheses, or moved up to read "available memory %s from cgroups is too large, ...". Still only a nit.
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.
Oh now I understand. Thanks for clarifying. Done.
Has this been reported upstream?
On May 10, 2017 8:15 AM, "kena" <[email protected]> wrote:
@knz <https://github.com/knz> requested your review on:
cockroachdb/cockroach#15841
<#15841> server: catch
incomplete available memory detection by gosigar.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15841 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABdsPPG45jJhp0HJ8n2j-8B79g05CXjXks5r4apegaJpZM4NWk3i>
.
|
FWIW I wasn't encountering this on my OpenBSD VM. I'm going to do some more digging when I have some spare time. 👍 in the meantime. |
@benesch perhaps the syscall(s) used in gosigar is sensitive to some configuration, which the gosigar openbsd support's author didn't take into account. If I were you I'd make an inventory of the syscalls in |
LGTM but we should like to the upstream issue since we don't want to keep this extra layer of paranoia on top of gosigar forever. Thanks for fixing! Please consider nominating for 1.0.1. Reviewed 1 of 1 files at r4. pkg/server/config.go, line 284 at r4 (raw file):
why not Comments from Reviewable |
If gosigar is told by a syscall there is 0 available memory, consider this information as false even if there was no error. Upstream issue: elastic/gosigar#72
I have linked the upstream issue. TFYR! Review status: all files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. pkg/server/config.go, line 284 at r4 (raw file): Previously, tamird (Tamir Duberstein) wrote…
Done. Comments from Reviewable |
Reviewed 1 of 1 files at r5. Comments from Reviewable |
If gosigar is told by a syscall there is 0 available memory, consider
this information as false even if there was no error.
Fixes #15839.