Skip to content

pynixd: a builder that thrashes inside a capped cgroup reads as steady, because memory_full counts only under 25% host MemAvailable #1568

Closed

Description

@Lillecarl

pressure.py _verdict counts PSI memory_full only while host MemAvailable is under 25% of MemTotal (memory_full_below_available, from #1260). A builder whose builds run in a capped cgroup thrashes inside the cap with the host far above 25% free, and pynixd reads it as steady and raises its limit.

Measured 2026-11-22 on sg1-n1/n2/n3 (125 GB each, ~57 GB available): nix-daemon.service has MemoryHigh=20G, memory.current 21.5 GB, its memory.pressure full avg10 62-82. pynixd state showed memory_full 63-83 with reason steady (n1, n3) or slow_start (n2), limits 8-32, 7-11 builds each. A cc1 on /dev/null in linux-config took 497 s of system time; builds of seconds waited 20+ minutes.

Fix direction: judge room against the cgroup the builds run in (memory.high/memory.max and memory.current of the daemon's unit), and read that cgroup's memory.pressure, not the host's /proc/meminfo. #1260's swap-in case stays covered if the room test uses the cgroup's own headroom.

Related: #1499, #1544.


Assisted-By: Claude Opus 5.5

Activity

  1. added
    source: pynixd
    on Nov 22, 2026
  2. Lillecarl commented on Nov 22, 2026

    @Lillecarl
    ContributorAuthor

    The other half, from the nodes' owner (solid-kubernetes environments/sg1/nixos/modules/rs501a.nix): the 20G cap is deliberate. After an uncapped python3.14t-huggorm-bindings build (74 g++, ~2 GiB each) on sg1-n3 on 2026-11-20 15:03 UTC, the OOM killer took 60 pod processes and the node went NotReady. The cap is sized for the nodes' own cores = 8, max-jobs = 2.

    pynixd places 7-11 builds per node: its build pool is 32 slots and its limit ceiling 32, while the node's daemon declares max-jobs = 2. So the fix has two parts: cap a store's builds at the remote daemon's max-jobs (or its declared slots), and treat the daemon cgroup's memory.pressure / memory.current near memory.high as saturation.


    Assisted-By: Claude Opus 5.5

  3. Lillecarl commented on Nov 22, 2026

    @Lillecarl
    ContributorAuthor

    The thrash also starves the nodes' other tenants of disk. The node owner (solidk) measured on sg1-n1/n2/n3, 2026-11-22 ~14:20 CET, read-only, comparing cgroup io.stat over 10 s:

    • nix-daemon.service reads 530-730 MB/s per node and writes about 0; kubepods writes 1.5-13 MB/s.
    • workingset_refault_file in that cgroup is 1.0-2.7 billion pages: at the 20G memory.high it evicts compiler and header pages and reads them back.
    • Host PSI io full avg60 is 7-13%, so Ceph and the pods wait on the disk too.
    • Drive wear is fine (percentage_used 0%, media_errors 0).

    Assisted-By: Claude Opus 5.5

  4. Lillecarl commented on Nov 22, 2026

    @Lillecarl
    ContributorAuthor

    Three causes, all fixed on main (a9a1ef2, c0e5049, 1154a24; locks 3832c18, 6765a8e). dynhetz runs them; the sg1 nodes wait on a pynixd bump (solidk, after its running kubeapply).

    Measured on sg1-n1, 2026-11-22 13:00 UTC: builds run in nix-daemon.service/nix-build-uid-*. memory.current 21.5 GB against memory.high 20 GiB, anon 21.4 GB, file 13 MB, memory.pressure full avg10 59.85. There is no swap (MemorySwapMax=0), so reclaim drops code pages and the builds crawl.

    1. Slots. A proxying reverse builder declared its CPU count (32 after the ceiling). It now registers its own Nix's max-jobs and cores (nix config show): 2 and 8 on sg1.
    2. Cores (new). pynixd forwarded the client's cores = 0, which overrides the node's cores = 8, so each build had 48 CPUs. A declared cores is now a hard ceiling that pynixd always sends.
    3. Room and pressure. pressure.build_cgroup (the NixOS module defaults it to the daemon's unit) makes each sample carry the tightest memory.high/max over that cgroup and its ancestors, the room under it (page cache counts as free, shmem does not), and its memory.pressure. The limit verdict, memory_room (core choice) and pynixd state read the merged room. memory_full is the larger of the cgroup's and the host's.

    Other reverse builders: gx10-1759 declares max-jobs = 20, its current 20 slots. macbook (15 slots now) follows its own max-jobs once its pynixd updates; not checked.

    Open until the nodes run it: dynhetz should show 2 build slots per sg1 node, available_mb at or under ~20000, and builds there should get NIX_BUILD_CORES=8.


    Assisted-By: Claude Opus 5.5

  5. Lillecarl commented on Nov 22, 2026

    @Lillecarl
    ContributorAuthor

    Verified on all three nodes after solidk's rollout to 6765a8e (NixOSRollout rs501a, about 14:50 UTC). Read from dynhetz's pynixd state --section stores, 2026-11-22:

    node build slots in use available_mb memory_full
    sg1-n1 2 2 20311 0.0
    sg1-n2 2 2 19964 0.0
    sg1-n3 2 2 20251 0.0

    Each node declares its Nix max-jobs (2). available_mb is the room under the 20 GiB cap of nix-daemon.service, not the host's 57 GB. Before the fix, sg1-n2 had 32 slots and memory_full 83. NIX_BUILD_CORES=8 was measured in running builds on sg1-n1. n2 and n3 run the same code.


    Assisted-By: Claude Opus 5.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: pynixd

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions