Ask
141
@keg_line_ken ·

llama.cpp with -ngl 99 still eats 5gb of system ram, where is it going llama.cpp

8B model, Q4_K_M, -ngl 99 so everything should be on the GPU. nvidia-smi says 6.9GB on the card, which matches what I expect.

But the process RSS is 5.4GB. On a 16GB box running two other things, that is the difference between fine and swapping, and it does swap - I can hear it.

If all the layers are on the GPU, what is holding 5GB of host memory?

7 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @muslin_mira · 3mo ago · 2 replies

    Most of it is not really "used". The model file is memory-mapped, so the pages you have read count towards RSS but they are page cache backed by the file on disk - the kernel will drop them the instant something else needs the memory. A 4.7GB GGUF that has been fully read shows up as roughly 4.7GB of RSS and costs you almost nothing.

    Prove it to yourself: run with --no-mmap and watch RSS become genuinely smaller after load, while startup gets slower. Or look at PSS instead of RSS - smem -k -P llama will show you a much more honest number.

    If it is actually swapping, that is a separate problem and it is usually the other two things on the box, not this.

    42
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @keg_line_ken · 3mo ago

      PSS is 1.1GB. So I have been reading the wrong column for about a year. The swapping is a Postgres container with no memory limit, which is embarrassing but at least it is fixable.

      12
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @hornworm_hunt · 3mo ago · 2 replies

    The genuinely host-resident parts, so you know what is left after mmap:

    • the compute buffer for the largest batch, which scales with batch size and context
    • the KV cache, but only if you passed --no-kv-offload, otherwise it is on the card
    • vocab and tokenizer structures, small
    • whatever your OS decided to keep of the file

    On an 8B with default settings the real host cost is a few hundred MB. If you measure more than that after --no-mmap, something else is going on.

    27
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @keg_line_ken · 3mo ago

      --no-mmap gave me 480MB resident and about 9 seconds of extra startup. So the 5.4GB was almost entirely page cache, as advertised.

      10
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @soy_pour_sasha · 3mo ago

    Related and worth knowing before it bites: with mmap the first generation after a cold start is slow because the pages get faulted in as they are touched. If you are benchmarking and your first run is always terrible and every later run is fine, that is this, not the model warming up in any meaningful sense.

    19
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @epoxy_puddle · 3mo ago

    "I can hear it" is the most reliable performance monitoring tool I own and I am not being sarcastic.

    11
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @teardown_tues · 3mo ago

    Since the real complaint is swapping: set the container memory limits, and if you are on Linux with fast storage consider zram over a swapfile. Any inference workload that touches swap during generation goes from tolerable to unusable within one token.

    16
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report