Skip to content

Memory sizing reads /proc/meminfo and ignores cgroup limits (containers, CI runners, systemd scopes) #3072

Open

Description

@THEtheChad

Part of #3057.

Summary

LightCraft sizes its memory use from /proc/meminfo (and the macOS / Windows equivalents) and never looks at cgroup limits. Inside a container, a Flatpak or systemd scope with MemoryMax, or a CI runner with a memory limit, the process may get far less than the machine has:

  • The engine sizes its budgets for the whole machine.
  • Merge plans for 75 % of physical RAM.
  • cargo xtask ci picks build jobs and test threads for memory it can't use.

A run that thinks it has room then gets killed when it hits the limit.

Evidence (main bb08a69)

  • crates/engine/src/memory.rs:41: total_ram() reads MemTotal:.
  • crates/engine/src/merge.rs:279: (ram * 0.75 - crate::memory::budget() as f64).max(0.0).
  • crates/engine/src/export.rs:1738: too_big_for_memory(…, crate::memory::total_ram()).
  • xtask/src/main.rs:160: available_ram_mb() reads MemAvailable: and feeds ci_jobs (:149).
  • No cgroup reading anywhere: a search for memory.max or /sys/fs/cgroup in crates, apps and xtask finds nothing.

Proposed fix

  • Limit (Linux, std only, never panics):
    • effective_total() = min(MemTotal, cgroup v2 memory.max), with the cgroup found through /proc/self/cgroup.
    • Return None / no limit when either value is absent or max.
  • Available memory: available() = min(MemAvailable, memory.max − memory.current).
  • Callers: use them in engine::memory, merge, export and xtask.
  • Where the code lives: lightcraft-sysmem today only hands freed memory back to the allocator. Either widen its role, or keep one copy in engine and one in xtask.

Activity

  1. ticket-craft commented on Oct 26, 2026

    @ticket-craft

    Thanks! This ticket describes several separate problems:

    • Engine and merge plan memory from total RAM, ignoring cgroup limits
    • cargo xtask ci sizes build jobs and test threads from MemAvailable, ignoring cgroup limits

    It helps a lot if each one has its own ticket, so they can be tracked and fixed separately.

    Possibly related: #3057, #3059 and #3066.

  2. added 7 commits that reference this issue on Oct 27, 2026
  3. added 4 commits that reference this issue on Oct 30, 2026
  4. 52 remaining items

  5. FredApps commented on Nov 18, 2026

    @FredApps
    Contributor

    Yes for Linux: honouring cgroup v2 memory.max / memory.current is a real fix for Flatpak, systemd scopes and CI runners, and std-only with a fallback to today's behaviour when there's no limit sounds right.

    For Windows job-object limits: fine in principle, and crates/sysmem is the right home for the unsafe, but please land the Linux part first and keep the Win32 calls in their own small PR so they can be reviewed separately.

  6. added 12 commits that reference this issue on Nov 20, 2026
  7. THEtheChad commented on Nov 20, 2026

    @THEtheChad
    ContributorAuthor

    @FredApps thanks. #3118 is the Linux part: std only, no new dependencies. It reads cgroup v2 memory.max / memory.current (and v1 memory.limit_in_bytes / memory.usage_in_bytes where a host still mounts v1) for the process's cgroup and every ancestor up to the mount root, and takes the tightest. With no limit, or nothing readable, it returns today's numbers (MemTotal / MemAvailable). It is rebased onto main and ready for review.

    The Win32 calls stay in #3654, which follows once #3118 merges. Its own diff is the win32 module in crates/sysmem (two read-only calls, GlobalMemoryStatusEx and QueryInformationJobObject, each with a // SAFETY: comment), the safe code that interprets the job limit, and a one-line switch in the engine. xtask's Windows sizing (#3705) stays separate in #3710, after that. Both stay draft until their parent merges.

    The Windows CI leg didn't test lightcraft-sysmem or xtask, so the job-object tests had never run in CI. #4582 adds both to it. I have run them natively on Windows on #3654's and #3710's heads, and they pass.

  8. added a commit that references this issue on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions