Skip to content

GLM loader: F_NOCACHE does not evict checkpoint pages an earlier download left in the file cache #583

Closed

Description

@BobClawblaw

What happens

glm/weights.zig's runCopies opens the shards with F_NOCACHE, so the reads don't fill the file cache. That doesn't evict pages that are already cached, though. Right after tensorfold pull, or after any earlier read of the checkpoint, much of it is still in the cache. On a 256 GB M5 Ultra, measured with mincore over GLM-5.3-Flash-MLX-4bit-MTP's shards, 69.6 GiB of the 169 GiB checkpoint was cached before a load.

The load then needs that cached copy and about 168 GiB of fresh GPU buffers at the same time. macOS kept the clean file pages and compressed the new buffers instead. It reached critical pressure, with 145 GiB in the compressor and 0.3 GiB of truly free pages, while the clean cache stayed put. (This was with the one-Mac limit raised, #498 / #580. The wiring in #581 addresses the compressor side.)

Suggestion

Before runCopies, drop each shard's cached pages: mmap it read-only shared, msync(addr, len, MS_INVALIDATE), munmap. That needs no root, unlike purge. On the same machine, dropping the 69.6 GiB took 0.5 s, and mincore reported 0.0 GiB cached afterwards. File-backed memory went from 107 to 39.6 GiB.

Our recipe does this in Python before starting the server (mac/pagecache.py in https://github.com/BobClawblaw/glm53-flash-mlx4bit-m5-ultra). It would fit in the loader for every family that reads large checkpoints with F_NOCACHE. Happy to send a PR if you want it there.

Activity

  1. ashhart commented on Oct 10, 2026

    @ashhart
    Owner

    Thanks, this matches the code, and it's been on our minds: the loader's own reads went through the page cache despite F_NOCACHE (they weren't aligned), and a 160 GB load on a Mac we test on ran out of free memory that way. Main's e82ab69 reads the checkpoint through aligned buffers around the page cache and waits while free memory is under 3% of RAM. Pages a pull cached before the load still stay, as you found. Up to 70% of RAM that leaves enough room; past it, which will take an explicit GLM_LOAD_LIMIT_GB (see #580), dropping a shard's cached pages first, with msync and MS_INVALIDATE as you measured, makes sense, and we'd take it as a small change to that path, measured with and without it on the same Mac. Closing this as answered; the cached-page drop can come as that small change.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions