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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dominikh
Copy link
Member

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
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 1, 2021
@mknyszek
Copy link
Contributor

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.

@gopherbot
Copy link

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

@mknyszek mknyszek self-assigned this Apr 23, 2021
@mknyszek mknyszek added this to the Go1.17 milestone Apr 23, 2021
@golang golang locked and limited conversation to collaborators Apr 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants