Replace usage of maxSystemThreads with maxSysmsgThreads.

Systrap will never create more stub-worker threads than
maxSysmsgThreads, so there's no need to allocate memory that
will never be used.

Also change initialization of maxSysmsgThreads to happen at
platform creation time, to account for the fact that gVisor
sets GOMAXPROCS at boot.

PiperOrigin-RevId: 633420808
This commit is contained in:
Konstantin Bogomolov
2024-05-13 20:40:55 -07:00
committed by gVisor bot
parent 113cf439b1
commit 211bb0f883
3 changed files with 14 additions and 9 deletions
+1 -1
View File
@@ -149,7 +149,7 @@ func stubInit() {
// Allocate maxGuestThreads plus ONE because each per-thread stack
// has to be aligned to sysmsg.PerThreadMemSize.
// Look at sysmsg/sighandler.c:sysmsg_addr() for more details.
mapLen, _ = hostarch.PageRoundUp(mapLen + sysmsg.PerThreadMemSize*(maxSystemThreads+1))
mapLen, _ = hostarch.PageRoundUp(mapLen + sysmsg.PerThreadMemSize*(uintptr(maxChildThreads+1)))
// Allocate context queue region
stubContextQueueRegion = mapLen
+9 -8
View File
@@ -101,15 +101,16 @@ type requestStub struct {
done chan *thread
}
// maxSysmsgThreads specifies the maximum number of system threads that a
// subprocess can create in context decoupled mode.
// TODO(b/268366549): Replace maxSystemThreads below.
var maxSysmsgThreads = runtime.GOMAXPROCS(0)
// maxSysmsgThreads is the maximum number of sysmsg threads that a subprocess
// can create. It is based on GOMAXPROCS and set once, so it must be set after
// GOMAXPROCS has been adjusted (see loader.go:Args.NumCPU).
var maxSysmsgThreads = 0
// maxChildThreads is the max number of all child system threads that a
// subprocess can create, including sysmsg threads.
var maxChildThreads = 0
const (
// maxSystemThreads specifies the maximum number of system threads that a
// subprocess may create in order to process the contexts.
maxSystemThreads = 4096
// maxGuestContexts specifies the maximum number of task contexts that a
// subprocess can handle.
maxGuestContexts = 4095
@@ -318,7 +319,7 @@ func newSubprocess(create func() (*thread, error), memoryFile *pgalloc.MemoryFil
sp := &subprocess{
requests: requests,
faultedContexts: make(map[*platformContext]struct{}),
sysmsgStackPool: pool.Pool{Start: 0, Limit: maxSystemThreads},
sysmsgStackPool: pool.Pool{Start: 0, Limit: uint64(maxChildThreads)},
threadContextPool: pool.Pool{Start: 0, Limit: maxGuestContexts},
memoryFile: memoryFile,
sysmsgThreads: make(map[uint32]*sysmsgThread),
+4
View File
@@ -318,6 +318,10 @@ func (*Systrap) MinUserAddress() hostarch.Addr {
func New() (*Systrap, error) {
// CPUID information has been initialized at this point.
archState.Init()
// GOMAXPROCS has been set at this point.
maxSysmsgThreads = runtime.GOMAXPROCS(0)
// Account for syscall thread.
maxChildThreads = maxSysmsgThreads + 1
mf, err := createMemoryFile()
if err != nil {