Source File
mpagecache.go
Belonging Package
runtime
package runtime
import (
)
const pageCachePages = 8 * unsafe.Sizeof(pageCache{}.cache)
func ( *pageCache) ( uintptr) (uintptr, uintptr) {
if .cache == 0 {
return 0, 0
}
if == 1 {
:= uintptr(sys.TrailingZeros64(.cache))
:= (.scav >> ) & 1
.cache &^= 1 << // set bit to mark in-use
.scav &^= 1 << // clear bit to mark unscavenged
return .base + *pageSize, uintptr() * pageSize
}
return .allocN()
}
func ( *pageCache) ( *pageAlloc) {
assertLockHeld(.mheapLock)
if .empty() {
return
}
:= chunkIndex(.base)
:= chunkPageIndex(.base)
if := (offAddr{.base}); .lessThan(.searchAddr) {
.searchAddr =
}
.update(.base, pageCachePages, false, false)
* = pageCache{}
}
func ( *pageAlloc) () pageCache {
assertLockHeld(.mheapLock)
if chunkIndex(.searchAddr.addr()) >= .end {
return pageCache{}
}
:= pageCache{}
:= chunkIndex(.searchAddr.addr()) // chunk index
, := .find(1)
.searchAddr = maxSearchAddr
return pageCache{}
}
:= chunkIndex()
:= .chunkOf()
= pageCache{
base: alignDown(, 64*pageSize),
cache: ^.pages64(chunkPageIndex()),
scav: .scavenged.block64(chunkPageIndex()),
}
}
.update(.base, pageCachePages, false, true)
.searchAddr = offAddr{.base + pageSize*(pageCachePages-1)}
return
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |