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: mcentral.freeSpan bug for empty? #34316

Closed
LeoYang90 opened this issue Sep 16, 2019 · 5 comments
Closed

runtime: mcentral.freeSpan bug for empty? #34316

LeoYang90 opened this issue Sep 16, 2019 · 5 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@LeoYang90
Copy link

LeoYang90 commented Sep 16, 2019

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

$ go version
go version go1.13

Does this issue reproduce with the latest release?

Why would we remove mspan from empty to nonempty in mcentral if there is no free object in mspan?

Fortunately, nfreed is 0 when wasempty is 1 which make mheap_.central[spc].mcentral.freeSpan does not work, but still I think it is a bug for mcentral.freeSpan

go/src/runtime/mcentral.go:19
type mcentral struct {
	lock      mutex
	spanclass spanClass
	nonempty  mSpanList // list of spans with a free object, ie a nonempty free list
	empty     mSpanList // list of spans with no free objects (or cached in an mcache)

	// nmalloc is the cumulative count of objects allocated from
	// this mcentral, assuming all spans in mcaches are
	// fully-allocated. Written atomically, read under STW.
	nmalloc uint64
}

go/src/runtime/mgcsweep.go:364
func (s *mspan) sweep(preserve bool) bool {
    ...
    wasempty := s.nextFreeIndex() == s.nelems
    nalloc := uint16(s.countAlloc())
    nfreed := s.allocCount - nalloc
    ...
    if nfreed > 0 && spc.sizeclass() != 0 {
		c.local_nsmallfree[spc.sizeclass()] += uintptr(nfreed)
		res = mheap_.central[spc].mcentral.freeSpan(s, preserve, wasempty)
		// mcentral.freeSpan updates sweepgen
    } 
    ...
}

go/src/runtime/mcentral.go:228
func (c *mcentral) freeSpan(s *mspan, preserve bool, wasempty bool) bool {
	...

	// Move to nonempty if necessary.
	if wasempty {
		c.empty.remove(s)
		c.nonempty.insert(s)
	}

	...
}

I think it should be :

go/src/runtime/mcentral.go:228
func (c *mcentral) freeSpan(s *mspan, preserve bool, wasempty bool) bool {
	...

	// Move to nonempty if necessary.
	if wasempty {
		c.nonempty.remove(s)
                 c.empty.insert(s)
	}

	...
}

@ianlancetaylor
Copy link
Contributor

It seems that you are just asking a question, not reporting a bug. We don't use the issue tracker for discussions (see https://golang.org/wiki/Questions). This particular topic should be discussed on golang-dev@googlegroups.com. Thanks.

I believe the answer to this question is that the code is preserving invariants for the concurrent garbage collector.

@LeoYang90
Copy link
Author

I think this is a bug, but nfreed stops the bug effect.@ianlancetaylor

@ianlancetaylor
Copy link
Contributor

OK, if you think there is a bug, I will reopen it, but you need to provide much more explanation as to what you think the bug might be.

@ianlancetaylor ianlancetaylor changed the title mcentral.freeSpan confused? runtime: mcentral.freeSpan confused? Sep 16, 2019
@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 16, 2019
@LeoYang90 LeoYang90 changed the title runtime: mcentral.freeSpan confused? runtime: mcentral.freeSpan bug for empty? Sep 16, 2019
@LeoYang90
Copy link
Author

thinks.@ianlancetaylor

@agnivade agnivade added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 16, 2019
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Oct 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants