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: mheap.busyList use unproper len when return list from h.busy #18944

Closed
zhaozhiqianghw opened this issue Feb 5, 2017 · 4 comments
Closed
Milestone

Comments

@zhaozhiqianghw
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.7.4

What operating system and processor architecture are you using (go env)?

linux amd64

The definition of mheap.busyList locate in mheap.go:943 as followed:

func (h *mheap) busyList(npages uintptr) *mSpanList {
if npages < uintptr(len(h.free)) {
return &h.busy[npages]
}
return &h.busylarge
}

When check if it can return the busy list using "len(free)", I think it's not proper.
Although the current version of Go set the same lenght of h.free and h.busy, it's different.

The same puzzle occurs at the definition of mheap.alloc_m @ mheap.go:592:
if large {
memstats.heap_objects++
atomic.Xadd64(&memstats.heap_live, int64(npage<<_PageShift))
// Swept spans are at the end of lists.
if s.npages < uintptr(len(h.free)) {
h.busy[s.npages].insertBack(s)
} else {
h.busylarge.insertBack(s)
}
}

So it's a mistake, or it's some design.

@ianlancetaylor ianlancetaylor added this to the Go1.9 milestone Feb 5, 2017
@ianlancetaylor
Copy link
Contributor

CC @aclements @RLH

@aclements
Copy link
Member

This is a little obtuse, but I wouldn't call it a bug. The free and busy lists must have the same length since we move short spans back and forth between these two lists.

It would be perfectly reasonable to change both of these to len(h.busy).

@zhaozhiqianghw
Copy link
Author

Yes, this is not a bug. It's better for reading.

@gopherbot
Copy link

CL https://golang.org/cl/36354 mentions this issue.

@golang golang locked and limited conversation to collaborators Mar 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants