From 6cfd8fb93484b5683f4a59f84b5bf5b0dde208a2 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 9 Jul 2026 09:45:43 +0900 Subject: internal/pkg: loadavg target in container environment This exposes preferred loadavg target to the container initial process. Signed-off-by: Ophestra --- internal/pkg/pkg.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'internal/pkg/pkg.go') diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index ea493d39..99a54462 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -281,6 +281,10 @@ func (c *common) GetMessage() message.Msg { return c.cache.msg } // value must not affect cure outcome. func (c *common) GetJobs() int { return c.cache.attr.Jobs } +// GetLoad returns the preferred load average target, when applicable. Its +// value must not affect cure outcome. +func (c *common) GetLoad() int { return c.cache.attr.Load } + // GetWorkDir returns a pathname to a directory which [Artifact] is expected to // write its output to. This is not the final resting place of the [Artifact] // and this pathname should not be directly referred to in the final contents. @@ -2684,6 +2688,8 @@ type CacheAttr struct { Flags int // Preferred job count, when applicable. Jobs int + // Preferred loadavg target, when applicable. + Load int // Omit the [lockedfile] lock. skipLock bool @@ -2716,15 +2722,19 @@ func Open( panic("attempting to open cache with incomplete variant setup") } - if attr == nil { - attr = new(CacheAttr) + var a CacheAttr + if attr != nil { + a = *attr } - if attr.Cures < 1 { - attr.Cures = runtime.NumCPU() + if a.Cures < 1 { + a.Cures = runtime.NumCPU() + } + if a.Jobs < 1 { + a.Jobs = runtime.NumCPU() } - if attr.Jobs < 1 { - attr.Jobs = runtime.NumCPU() + if a.Load < 1 { + a.Load = runtime.NumCPU() + 2 } for _, name := range []string{ @@ -2746,8 +2756,8 @@ func Open( c := Cache{ parent: ctx, - cures: make(chan struct{}, attr.Cures), - attr: *attr, + cures: make(chan struct{}, a.Cures), + attr: a, msg: msg, base: base, @@ -2764,7 +2774,7 @@ func Open( } c.toplevel.Store(newToplevel(ctx)) - if !attr.skipLock || !testing.Testing() { + if !a.skipLock || !testing.Testing() { if unlock, err := lockedfile.MutexAt( base.Append(fileLock).String(), ).Lock(); err != nil { @@ -2825,7 +2835,7 @@ func Open( } } else if s := string(p); s == "" { if extension != "" { - if attr.Flags&CPromoteVariant == 0 { + if a.Flags&CPromoteVariant == 0 { c.unlock() return nil, ErrWouldPromote } -- cgit v1.3.1