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

runtime: probably unwanted integer division in scavenger pacing #44036

Closed
dominikh opened this issue Feb 1, 2021 · 2 comments
Closed

runtime: probably unwanted integer division in scavenger pacing #44036

dominikh opened this issue Feb 1, 2021 · 2 comments
Assignees
Milestone

Comments

@dominikh
Copy link
Member

@dominikh dominikh commented Feb 1, 2021

I've stumbled across the following code, which IMO is incorrect:

// Set a lower bound on the fraction.
// Due to OS-related anomalies we may "sleep" for an inordinate amount
// of time. Let's avoid letting the ratio get out of hand by bounding
// the sleep time we use in our EWMA.
const minFraction = 1 / 1000
if fraction < minFraction {
fraction = minFraction
}

The value of minFraction is 0, which makes the check pointless.

/cc @mknyszek to confirm my suspicion, as I'm not familiar with any of this code.

@ALTree ALTree changed the title Probably unwanted integer division in scavenger pacing runtime: probably unwanted integer division in scavenger pacing Feb 1, 2021
@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Feb 1, 2021

Erg, yeah good catch, thank you. I like to think that constants are truly untyped, but that's wrong. :)

Luckily, it looks like we didn't hit this case much in practice or not any case that was important enough for someone to report a bug about it. This makes sense since the scavenger isn't quite as useful in the context of, say, a CLI tool, where it's more likely this case could happen (e.g. laptop lid closes during the section where we're measuring time). I'll send a fix, but it's probably not worth backporting.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 23, 2021

Change https://golang.org/cl/313249 mentions this issue: runtime: fix scavenge min fraction constant floor division

Loading

@mknyszek mknyszek self-assigned this Apr 23, 2021
@mknyszek mknyszek added this to the Go1.17 milestone Apr 23, 2021
@gopherbot gopherbot closed this in 14ade57 Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants