package discovery import ( "bufio" "os" "strconv" "strings" ) // MemoryTotalMB reports the machine's total RAM. // // It exists because placement had no idea how much a node could hold. A CPU // profile has no card to be free, so every ready node looked like a candidate: // a 14B model whose working set is 24 GB would have been placed just as // happily on a node with 8 GB, which reports itself perfectly healthy right up // until the OOM killer arrives. Labels were the stopgap; this is the fact they // were standing in for. // // Read from /proc/meminfo, which is Linux-only — every node is. On anything // else it returns 0, which callers treat as "unknown" and therefore no // constraint, exactly as an older agent that does not report it at all. func MemoryTotalMB() int { return memTotalMBFrom("/proc/meminfo") } func memTotalMBFrom(path string) int { f, err := os.Open(path) if err != nil { return 0 } defer f.Close() sc := bufio.NewScanner(f) for sc.Scan() { rest, ok := strings.CutPrefix(sc.Text(), "MemTotal:") if !ok { continue } fields := strings.Fields(rest) if len(fields) == 0 { return 0 } kb, err := strconv.Atoi(fields[0]) if err != nil { return 0 } // MemTotal is what the kernel can hand out, already short of the // installed total by the firmware's reservations. That is the right // number for deciding what fits. return kb / 1024 } return 0 }