mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* weed: report the host transparent huge page policy at startup Go maps the heap with MADV_HUGEPAGE, so the host THP policy applies to a SeaweedFS process whether or not the operator asked for it, and the advice in the Go GC guide depends on the heap size. Operators had no way to see which mode a node actually runs in. Log enabled/defrag/khugepaged.max_ptes_none once at startup from the long-running commands, and print the Go toolchain in `weed version` so a support bundle identifies the runtime that produced the binary. Nothing changes the policy: THP is host-wide, and GODEBUG=disablethp=1 remains the only per-process control. Refs #5437 * build: declare Go 1.27.4, the toolchain the releases already use The 4.55 release binaries report go1.27.4 (`go version -m` on the published tarball), while go.mod still said 1.26.6, the Dockerfiles pinned golang:1.26, and the release workflows left the Go version to the action default of "the latest stable at build time". A source build, a container and a downloaded tarball therefore ran different toolchains from the same tag, and the next release could silently pick up another one. Set the go directive to 1.27.4 in the root module and in the four modules that build in CI, bump the 16 Dockerfiles, and pin goversion: 1.27.4 in the 16 release and dev action steps. `go mod tidy` now emits the two require blocks Go 1.27 expects; no dependency version changed. Go 1.27's gofmt realigns 8 files. * weed mini: report the THP policy after quieting stderr The startup line ran from the dispatch point before runMini applied quietMiniLogs, so every weed mini start on Linux printed it to stderr, which mini keeps for the welcome banner, warnings and errors. Log it from runMini after quietMiniLogs so it lands in the log file only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: report whether the Go heap can use huge pages The runtime advises only GC metadata with MADV_HUGEPAGE and leaves the heap arenas to the host default, so under enabled=madvise the heap stays on small pages. The log still printed go_heap_disabled=false there, which reads as "the heap uses THP". Report go_heap_thp, true only under enabled=always without GODEBUG=disablethp, and drop the struct comment that said the heap is mapped with MADV_HUGEPAGE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: count an inherited PR_SET_THP_DISABLE in go_heap_thp A launcher can disable THP for the process with prctl, and children inherit it, so enabled=always alone does not mean the heap gets huge pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: read GODEBUG disablethp the way the runtime does The runtime applies GODEBUG left to right, so with disablethp=1,disablethp=0 the heap keeps THP, while the helper stopped at the first disablethp=1. The helper also missed other nonzero values such as disablethp=2, which the runtime treats as disabled, and trimmed spaces around keys, which the runtime keeps. Take the last disablethp with an integer value, treat any nonzero value as disabled, and match keys exactly. The parser now takes the GODEBUG string, so it is tested without changing the environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: honor per-size THP policies in go_heap_thp Since Linux 6.8 each anonymous huge page size has its own policy in hugepages-<size>kB/enabled, and only "inherit" follows the top-level knob. A 64kB size set to "always" gives the unadvised heap huge pages under a top-level "madvise" or "never", and a 2048kB size set to "never" takes them away under "always", but the log judged only the top-level value. Read the per-size policies and report go_heap_thp=true when any size reaches the heap. Under a top-level "never", the "disabled by the host" line is now printed only when no size reaches the heap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: report go_heap_thp=unknown when the process setting is unreadable If PR_GET_THP_DISABLE fails, for example because a seccomp profile rejects it, the process THP setting is not known, but the log treated it as allowed and could print go_heap_thp=true. Print go_heap_thp=unknown in that case. It stays false when the host or GODEBUG already rules out heap huge pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: report go_heap_thp=unknown when a per-size THP policy is unreadable An unreadable hugepages-<size>kB/enabled was skipped, so the log could say the host disabled THP while that size allowed it. Keep it as an empty mode and report unknown unless a readable size already allows huge pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: take the Go version from go.mod in tests and releases posix-compliance pinned GO_VERSION 1.26 and built go 1.27.4 modules only through the GOTOOLCHAIN auto-switch; nine workflows used go-version ^1.26 and the kafka jobs ran in golang:1.26-alpine. Read the version from go.mod with go-version-file, as the other setup-go steps already do, moving checkout ahead of setup-go where it came after so the file exists. The posix report takes the version from the setup-go output. The release and dev builds pinned goversion 1.27.4 in 16 places. The pinned go-release-action reads the go directive when goversion is go.mod, so the binaries now follow go.mod without a second copy of the version. * weed: report the THP policy from every long-running command mount, worker, iam, master.follower, the filer sync/backup/remote/replicate daemons and the mq agent and kafka gateway keep serving after startup like the commands already listed; mount is likely where heap size matters most. fuse is not listed: its first process starts a child with the same arguments and waits, so logging at dispatch would print the line twice. It logs in runFuse just before handing over to runMount, which only the child reaches. --------- Co-authored-by: Konstantin Lebedev <whitefox@mayflower.work> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
309 lines
6.9 KiB
Go
309 lines
6.9 KiB
Go
package plugin
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/plugin_pb"
|
|
)
|
|
|
|
// queuedJob is one scheduled spec parked on a home worker's admin-side queue.
|
|
type queuedJob struct {
|
|
job *plugin_pb.JobSpec
|
|
home string
|
|
}
|
|
|
|
// workerJobQueues holds per-worker FIFOs for one dispatch batch.
|
|
// Home assignment is done once up front; run goroutines only pop/steal.
|
|
// leftover is the homeless FIFO: replica hostnames with no currently
|
|
// registered worker. Orphan grace does not apply here.
|
|
type workerJobQueues struct {
|
|
mu sync.Mutex
|
|
q map[string][]*queuedJob
|
|
leftover []*queuedJob
|
|
remaining int
|
|
missingSince map[string]time.Time
|
|
homes map[string]struct{}
|
|
}
|
|
|
|
func newWorkerJobQueues() *workerJobQueues {
|
|
return &workerJobQueues{
|
|
q: make(map[string][]*queuedJob),
|
|
missingSince: make(map[string]time.Time),
|
|
homes: make(map[string]struct{}),
|
|
}
|
|
}
|
|
|
|
func (qs *workerJobQueues) hasHome(workerID string) bool {
|
|
if qs == nil || workerID == "" {
|
|
return false
|
|
}
|
|
_, ok := qs.homes[workerID]
|
|
return ok
|
|
}
|
|
|
|
func (qs *workerJobQueues) push(home string, job *plugin_pb.JobSpec) {
|
|
if qs == nil || job == nil {
|
|
return
|
|
}
|
|
item := &queuedJob{job: job, home: home}
|
|
qs.mu.Lock()
|
|
defer qs.mu.Unlock()
|
|
qs.pushLocked(item, false)
|
|
}
|
|
|
|
func (qs *workerJobQueues) pushFront(item *queuedJob) {
|
|
if qs == nil || item == nil {
|
|
return
|
|
}
|
|
qs.mu.Lock()
|
|
defer qs.mu.Unlock()
|
|
qs.pushLocked(item, true)
|
|
}
|
|
|
|
func (qs *workerJobQueues) pushLocked(item *queuedJob, front bool) {
|
|
qs.remaining++
|
|
if item.home == "" {
|
|
if front {
|
|
qs.leftover = append([]*queuedJob{item}, qs.leftover...)
|
|
return
|
|
}
|
|
qs.leftover = append(qs.leftover, item)
|
|
return
|
|
}
|
|
if front {
|
|
qs.q[item.home] = append([]*queuedJob{item}, qs.q[item.home]...)
|
|
return
|
|
}
|
|
qs.q[item.home] = append(qs.q[item.home], item)
|
|
}
|
|
|
|
func (qs *workerJobQueues) isEmpty() bool {
|
|
if qs == nil {
|
|
return true
|
|
}
|
|
qs.mu.Lock()
|
|
defer qs.mu.Unlock()
|
|
return qs.remaining == 0
|
|
}
|
|
|
|
func (qs *workerJobQueues) queueLen(workerID string) int {
|
|
if qs == nil {
|
|
return 0
|
|
}
|
|
qs.mu.Lock()
|
|
defer qs.mu.Unlock()
|
|
return len(qs.q[workerID])
|
|
}
|
|
|
|
func (qs *workerJobQueues) leftoverLen() int {
|
|
if qs == nil {
|
|
return 0
|
|
}
|
|
qs.mu.Lock()
|
|
defer qs.mu.Unlock()
|
|
return len(qs.leftover)
|
|
}
|
|
|
|
func (qs *workerJobQueues) drain() []*queuedJob {
|
|
if qs == nil {
|
|
return nil
|
|
}
|
|
qs.mu.Lock()
|
|
defer qs.mu.Unlock()
|
|
out := make([]*queuedJob, 0, qs.remaining)
|
|
for id, qq := range qs.q {
|
|
out = append(out, qq...)
|
|
qs.q[id] = nil
|
|
}
|
|
out = append(out, qs.leftover...)
|
|
qs.leftover = nil
|
|
qs.remaining = 0
|
|
return out
|
|
}
|
|
|
|
func popFront(qq []*queuedJob) (*queuedJob, []*queuedJob) {
|
|
item := qq[0]
|
|
if len(qq) == 1 {
|
|
return item, nil
|
|
}
|
|
return item, qq[1:]
|
|
}
|
|
|
|
// assignJobsToWorkerQueues parks each job on the least-loaded replica-host
|
|
// worker. A home exists only if a currently registered worker's -address
|
|
// hostname matches a replica host. Otherwise the job is homeless: global
|
|
// leftover FIFO, no fake home, no K, no orphan grace. Single-threaded.
|
|
func (r *Plugin) assignJobsToWorkerQueues(
|
|
jobType string,
|
|
jobs []*plugin_pb.JobSpec,
|
|
_ schedulerPolicy,
|
|
) *workerJobQueues {
|
|
qs := newWorkerJobQueues()
|
|
executors, err := r.registry.ListExecutors(jobType)
|
|
queued := make(map[string]int, len(executors))
|
|
|
|
for _, job := range jobs {
|
|
if job == nil {
|
|
continue
|
|
}
|
|
if err != nil || len(executors) == 0 {
|
|
qs.push("", job)
|
|
continue
|
|
}
|
|
pref, _ := partitionByPreferredHost(executors, JobReplicaHosts(job))
|
|
if len(pref) == 0 {
|
|
// Never registered for that hostname: homeless, not an orphan.
|
|
qs.push("", job)
|
|
continue
|
|
}
|
|
for _, e := range pref {
|
|
if e != nil && e.WorkerID != "" {
|
|
qs.homes[e.WorkerID] = struct{}{}
|
|
}
|
|
}
|
|
sortExecutorsByLoad(pref, func(e *WorkerSession) int {
|
|
return r.executorWorkerLoad(e) + queued[e.WorkerID]
|
|
})
|
|
home := pref[0].WorkerID
|
|
qs.push(home, job)
|
|
queued[home]++
|
|
r.bindQueuedJobWorker(job, home)
|
|
}
|
|
return qs
|
|
}
|
|
|
|
// takeQueuedJob pops a job for a free worker.
|
|
// Home worker (hostname matched a replica / has a home-queue identity):
|
|
// 1. own home queue
|
|
// 2. steal from another home if len>=K, or orphan past OrphanRehomeGrace
|
|
// 3. homeless leftover FIFO
|
|
//
|
|
// No-home worker (no matching replica, no home-queue identity):
|
|
// 1. homeless leftover FIFO
|
|
// 2. only if leftover empty: steal (K / orphan), same rules
|
|
func (r *Plugin) takeQueuedJob(
|
|
qs *workerJobQueues,
|
|
jobType string,
|
|
policy schedulerPolicy,
|
|
) (item *queuedJob, targetID string) {
|
|
if qs == nil {
|
|
return nil, ""
|
|
}
|
|
executors, err := r.registry.ListExecutors(jobType)
|
|
if err != nil || len(executors) == 0 {
|
|
return nil, ""
|
|
}
|
|
pin := policy.LocalQueuePin
|
|
defer func() {
|
|
if item != nil && targetID != "" {
|
|
r.bindQueuedJobWorker(item.job, targetID)
|
|
}
|
|
}()
|
|
|
|
qs.mu.Lock()
|
|
defer qs.mu.Unlock()
|
|
if qs.remaining == 0 {
|
|
return nil, ""
|
|
}
|
|
|
|
var bestHome *WorkerSession
|
|
bestLoad := 0
|
|
for _, exec := range executors {
|
|
if len(qs.q[exec.WorkerID]) == 0 {
|
|
continue
|
|
}
|
|
if !r.executorHasCapacity(exec, jobType, policy) {
|
|
continue
|
|
}
|
|
load := r.executorWorkerLoad(exec)
|
|
if bestHome == nil || load < bestLoad || (load == bestLoad && exec.WorkerID < bestHome.WorkerID) {
|
|
bestHome = exec
|
|
bestLoad = load
|
|
}
|
|
}
|
|
if bestHome != nil {
|
|
id := bestHome.WorkerID
|
|
item, qs.q[id] = popFront(qs.q[id])
|
|
qs.remaining--
|
|
return item, id
|
|
}
|
|
|
|
var thief *WorkerSession
|
|
for _, exec := range executors {
|
|
if !r.executorHasCapacity(exec, jobType, policy) {
|
|
continue
|
|
}
|
|
if thief == nil || exec.WorkerID < thief.WorkerID {
|
|
thief = exec
|
|
}
|
|
}
|
|
if thief == nil {
|
|
return nil, ""
|
|
}
|
|
|
|
takeLeftover := func() (*queuedJob, string) {
|
|
if len(qs.leftover) == 0 {
|
|
return nil, ""
|
|
}
|
|
item, qs.leftover = popFront(qs.leftover)
|
|
qs.remaining--
|
|
return item, thief.WorkerID
|
|
}
|
|
if !qs.hasHome(thief.WorkerID) {
|
|
if item, id := takeLeftover(); item != nil {
|
|
return item, id
|
|
}
|
|
}
|
|
|
|
live := make(map[string]struct{}, len(executors))
|
|
for _, exec := range executors {
|
|
live[exec.WorkerID] = struct{}{}
|
|
delete(qs.missingSince, exec.WorkerID)
|
|
}
|
|
|
|
now := time.Now()
|
|
grace := policy.OrphanRehomeGrace
|
|
victimID := ""
|
|
victimLen := 0
|
|
victimOrphan := false
|
|
for id, qq := range qs.q {
|
|
if len(qq) == 0 {
|
|
delete(qs.missingSince, id)
|
|
continue
|
|
}
|
|
_, isLive := live[id]
|
|
orphan := !isLive
|
|
if isLive {
|
|
if pin > 0 && len(qq) < pin {
|
|
continue
|
|
}
|
|
} else {
|
|
if _, ok := qs.missingSince[id]; !ok {
|
|
qs.missingSince[id] = now
|
|
}
|
|
if grace > 0 && now.Sub(qs.missingSince[id]) < grace {
|
|
continue
|
|
}
|
|
}
|
|
better := victimID == ""
|
|
if !better && orphan != victimOrphan {
|
|
better = orphan
|
|
}
|
|
if !better && orphan == victimOrphan {
|
|
better = len(qq) > victimLen || (len(qq) == victimLen && id < victimID)
|
|
}
|
|
if better {
|
|
victimID = id
|
|
victimLen = len(qq)
|
|
victimOrphan = orphan
|
|
}
|
|
}
|
|
if victimID != "" {
|
|
item, qs.q[victimID] = popFront(qs.q[victimID])
|
|
qs.remaining--
|
|
return item, thief.WorkerID
|
|
}
|
|
return takeLeftover()
|
|
}
|