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

Comments

@LeoYang90
Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Sep 16, 2019

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

This comment has been minimized.

Copy link
Author

commented Sep 16, 2019

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 16, 2019

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
@LeoYang90 LeoYang90 changed the title runtime: mcentral.freeSpan confused? runtime: mcentral.freeSpan bug for empty? Sep 16, 2019
@LeoYang90

This comment has been minimized.

Copy link
Author

commented Sep 16, 2019

@gopherbot

This comment has been minimized.

Copy link

commented Oct 16, 2019

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.)

@gopherbot gopherbot closed this Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.