mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: merge all treaps into one implementation
This change modifies the treap implementation to support holding all spans in a single treap, instead of keeping them all in separate treaps. This improves ergonomics for nearly all treap-related callsites. With that said, iteration is now more expensive, but it never occurs on the fast path, only on scavenging-related paths. This change opens up the opportunity for further optimizations, such as splitting spans without treap removal (taking treap removal off the span allocator's critical path) as well as improvements to treap iteration (building linked lists for each iteration type and managing them on insert/removal, since those operations should be less frequent). For #30333. Change-Id: I3dac97afd3682a37fda09ae8656a770e1369d0a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/174398 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
1ad2298c77
commit
9baa4301cf
4 changed files with 210 additions and 134 deletions
|
|
@ -339,7 +339,7 @@ func ReadMemStatsSlow() (base, slow MemStats) {
|
|||
slow.BySize[i].Frees = bySize[i].Frees
|
||||
}
|
||||
|
||||
for i := mheap_.scav.start(); i.valid(); i = i.next() {
|
||||
for i := mheap_.free.start(0, 0); i.valid(); i = i.next() {
|
||||
slow.HeapReleased += uint64(i.span().released())
|
||||
}
|
||||
|
||||
|
|
@ -522,11 +522,12 @@ type Span struct {
|
|||
*mspan
|
||||
}
|
||||
|
||||
func AllocSpan(base, npages uintptr) Span {
|
||||
func AllocSpan(base, npages uintptr, scavenged bool) Span {
|
||||
lock(&mheap_.lock)
|
||||
s := (*mspan)(mheap_.spanalloc.alloc())
|
||||
unlock(&mheap_.lock)
|
||||
s.init(base, npages)
|
||||
s.scavenged = scavenged
|
||||
return Span{s}
|
||||
}
|
||||
|
||||
|
|
@ -545,6 +546,17 @@ func (s Span) Pages() uintptr {
|
|||
return s.mspan.npages
|
||||
}
|
||||
|
||||
type TreapIterType int
|
||||
|
||||
const (
|
||||
TreapIterScav TreapIterType = TreapIterType(treapIterScav)
|
||||
TreapIterBits = treapIterBits
|
||||
)
|
||||
|
||||
func (s Span) MatchesIter(mask, match TreapIterType) bool {
|
||||
return s.mspan.matchesIter(treapIterType(mask), treapIterType(match))
|
||||
}
|
||||
|
||||
type TreapIter struct {
|
||||
treapIter
|
||||
}
|
||||
|
|
@ -575,12 +587,12 @@ type Treap struct {
|
|||
mTreap
|
||||
}
|
||||
|
||||
func (t *Treap) Start() TreapIter {
|
||||
return TreapIter{t.start()}
|
||||
func (t *Treap) Start(mask, match TreapIterType) TreapIter {
|
||||
return TreapIter{t.start(treapIterType(mask), treapIterType(match))}
|
||||
}
|
||||
|
||||
func (t *Treap) End() TreapIter {
|
||||
return TreapIter{t.end()}
|
||||
func (t *Treap) End(mask, match TreapIterType) TreapIter {
|
||||
return TreapIter{t.end(treapIterType(mask), treapIterType(match))}
|
||||
}
|
||||
|
||||
func (t *Treap) Insert(s Span) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue