Scenario

LRU thrash in a small pool, then a crash

L3SeniorIncident25 minDebuggingML depth

RolesInference EngineeringAgent Systems Engineering

Engine
SGLang 0.5.22
Model
Qwen/Qwen3-0.6B
Hardware
the shared second L4 of a two-GPU node, with no clock lock

Situation

A coding assistant keeps a session for each user and resends the whole history on every turn. The team serves a small model with SGLang on a GPU that another team also uses, so they set --max-total-tokens 8192 to leave the neighbour room. In a load test with 24 sessions of 6 turns at 8 users at once, the first turns are fast. From the fourth turn the first token takes up to 716 ms, and the metrics endpoint shows the cache hit rate falling toward zero.

Then two kinds of failure appear. In some runs the server stops with CUDA error: an illegal memory access was encountered. In other runs the log stops with no error while the GPU stays at 100 percent and every client waits. The team suspects the eviction policy and asks whether to switch from lru to lfu.

Questions

  1. What does eviction remove, what does it never remove, and how does lru pick the victim?
  2. Read the per-turn hit rates of the first row. Describe the pattern in words and name the mechanism behind it.
  3. At the same pool size, lfu and slru kept the late turns alive. What does that tell you about the working set, and what else fixes it?
  4. Both failures stop in one call of the scheduler. Which two changes made the fault disappear, and what does each one cost?
  5. Order the fixes: a larger pool, a different policy, graphs off, launch blocking. Which do you ship, which do you test, and which never goes to production?

Commit to a cause after each listing. Write it down before you read the next one.

Evidence

1/5

the engine, the model and the multi-turn trace

Count the sessions and the turns, and note that each turn resends the whole history.

evidence/trace-and-pool.txt
Engine: SGLang 0.5.22. Model: Qwen/Qwen3-0.6B.
Trace: 24 sessions, each with its own system prompt, 6 turns of ShareGPT questions, 64-token answers, thinking off. Sessions run round robin at concurrency 8. Each turn resends the whole history.
Hit rate = cached prompt tokens / prompt tokens, from the cache report.
The 8,192-token lru row holds two clean runs of the same config: run 1 and run 2 gave 0.19 each over the whole trace. The summary keeps one set of per-turn rates and one clock for the pair.

Source: manuals/sglang-101/capture/gpu/out-l4/eviction-multiturn.txt, lines 4-7

2/5

the hit rate over the whole trace and per turn, by pool size and policy

Follow the per-turn column of the first row from turn 4 to turn 6, then compare the rows below it.

evidence/hit-rate-by-turn.txt
pool, policy                 whole trace   hit rate per turn 1 to 6                        median SM clock
8,192 tokens, lru            0.19, 0.19    0.11, 0.31, 0.58, 0.39, 0.016, 0.013            615 MHz
8,192 tokens, lru, no graph  0.19          the same shape                                  1,905 MHz
8,192 tokens, lfu            0.375         0.11, 0.31, 0.58, 0.53, 0.34, 0.25              1,140 MHz
8,192 tokens, slru           0.367         0.11, 0.31, 0.58, 0.53, 0.31, 0.26              960 MHz
16,384 tokens, lru           0.685         rises to 0.83 at turn 6                         810 MHz
16,384 tokens, lfu           0.687         rises to 0.84 at turn 6                         945 MHz
default pool, lru            0.687         rises to 0.835 at turn 6                        960 MHz

Source: manuals/sglang-101/capture/gpu/out-l4/eviction-multiturn.txt, lines 9-16

3/5

the median time to first token at turns 5 and 6

Compare the three lines, which come from one GPU with no clock lock.

evidence/ttft-at-late-turns.txt
Median TTFT at turns 5 and 6:
8,192 lru: run 1 gave 699 and 449 ms, run 2 gave 716 and 355 ms
8,192 lfu or slru: 143 to 214 ms
16,384 or default pool: 56 to 160 ms

Source: manuals/sglang-101/capture/gpu/out-l4/eviction-multiturn.txt, lines 18-21

4/5

the server command, the trace, and the tally of aborts and hangs by variant

Read the clean column against the runs column for each variant.

evidence/aborts-and-hangs.txt
Server: sglang serve --model-path Qwen/Qwen3-0.6B --mem-fraction-static 0.55 --context-length 4096 --enable-cache-report --max-total-tokens 8192 --radix-eviction-policy lru
Trace: 24 sessions x 6 turns, round robin at concurrency 8, greedy, 64-token answers. The context grows each turn, so the 8,192-token pool evicts heavily from turn 4 on.
Hang rule: no new log line for 5 minutes, or 15 minutes in total. The scheduler stack was saved with py-spy before the server was stopped.

variant                                          runs   aborts   hangs   clean
lru, CUDA graph and overlap on (default)         6      1        3       2
lru, CUDA_LAUNCH_BLOCKING=1                      3      0        0       3
lru, --disable-cuda-graph                        4      0        0       4
lru, --enable-hierarchical-cache                 3      1        0       2
lru, HiCache, CUDA_LAUNCH_BLOCKING=1             2      0        0       2

Source: manuals/sglang-101/capture/gpu/out-l4/small-pool-crash.txt, lines 5-14

5/5

the abort, the hang, and what hid the fault

Both failures stop in the same call, and the last three lines say what made the fault disappear.

evidence/where-it-stopped.txt
The abort:
torch.AcceleratorError: CUDA error: an illegal memory access was encountered
Last Python frames: scheduler.py process_batch_result, then batch_result_processor.py process_batch_result_decode, then torch/cuda/streams.py synchronize (copy_done.synchronize() on the decode result).

The hang: the py-spy stack sits in the same synchronize call, under process_batch_result_decode, under event_loop_overlap. The GPU stays at 100 percent and the log stops.

The fault did not appear with kernel launches serialized (0 of 5) or with CUDA graphs off (0 of 4).
With launch blocking on, the fault did not occur, so no traceback names the faulting kernel.
Nothing was filed upstream.

Source: manuals/sglang-101/capture/gpu/out-l4/small-pool-crash.txt, lines 18-26

The answer

Show the walkthrough

Eviction removes cached tokens that no running request holds, from the leaves of the radix tree. It never removes the KV of a running request. With the default policy the leaf with the oldest last access goes first. That rule assumes that the next request looks like the recent ones.

The trace in the first listing breaks that assumption. Twenty-four sessions take turns at a concurrency of 8, and every turn resends a history that grows. The second listing shows what the pool did with it. With 8,192 tokens and lru, the hit rate per turn was 0.11, 0.31 and 0.58 for the first three turns, then 0.39, 0.016 and 0.013. By turn 5 the cycle of 24 growing histories was larger than the pool. The policy evicted each session's prefix just before that session came back, so almost every late turn paid a full prefill. Over the whole trace the hit rate was 0.19 in both clean runs.

The same pool with lfu reached 0.375 over the trace and kept 0.34 and 0.25 at turns 5 and 6. With slru it was 0.367, with 0.31 and 0.26. So the frequency policies helped exactly where the pool was too small for the sessions that return. The rows below show the real fix. At 16,384 tokens, lru reached 0.685 and the hit rate rose to 0.83 at turn 6. The default pool gave 0.687. Every policy we ran at the larger pools landed near 0.69. The third listing turns this into time. At turns 5 and 6 the median first token was 699 and 449 ms in one lru run and 716 and 355 ms in the other, 143 to 214 ms with lfu or slru, and 56 to 160 ms with the larger pools. The card had no clock lock, so compare these numbers only with each other.

The fourth listing is the failure tally. With the defaults, CUDA graphs and the overlap scheduler on, 6 runs gave 1 abort, 3 hangs and 2 clean runs. With CUDA_LAUNCH_BLOCKING=1, 3 of 3 were clean. With --disable-cuda-graph, 4 of 4 were clean. When hierarchical caching was on, 1 of 3 still aborted. The fifth listing shows that the abort and every hang stopped in the same place, the synchronize call that waits for the copy of a decode result, under the overlap event loop. The fault did not appear with launches serialized or with graphs off, so no traceback names the kernel. Nothing was filed upstream.

Show the resolution

Two problems sat on top of each other. The pool was smaller than the working set of the sessions that return, so lru thrashed from turn 4 on. Under that heavy eviction, the default path with CUDA graphs and the overlap scheduler hit the memory fault or hung in 4 of 6 runs.

Grow the pool first. At 16,384 tokens the same trace reached a hit rate of 0.685 with the default policy, and the late turns kept 56 to 160 ms to the first token. If a cap such as --max-total-tokens sets the pool, raise the cap. If memory sets it, on a shared card that means a larger --mem-fraction-static or an FP8 KV cache, not a new policy. Then read max_total_num_tokens in the startup log to confirm the new size. Then measure the policy again. On this trace a different policy paid only at the pool size that was too small.

For the crash, ship --disable-cuda-graph as the workaround while the pool is small. On our L4 with an 8B model, graphs saved about 1 percent of each decode step, so measure the cost on your model. A larger pool stopped the thrash, but we did not count crashes at the larger pools, so treat it as untested for the fault. Keep CUDA_LAUNCH_BLOCKING=1 for debugging only.

Show the wrong turns
  • “Switch to lfu and ship it.”

    A frequency policy keeps yesterday's popular prompt in memory and makes today's prompt pay for it. It helped here only because the pool was too small, and the larger pool made every policy equal.

  • “Set CUDA_LAUNCH_BLOCKING=1 in production.”

    It hid the fault in 5 of 5 runs, and it makes every kernel launch wait for the one before it. Use it to debug, never to serve.

  • “Turn on hierarchical caching to stop the crash.”

    With the host tier on, 1 of 3 runs still aborted. The host tier keeps evicted prefixes, it does not change the path that faulted.

  • “Raise the running-request cap so the sessions do not wait.”

    More running requests hold more of the pool, so eviction gets heavier, and the hit rate falls further.

Show the general rule

When a hit rate falls on later turns while early turns are fine, the working set has outgrown the cache. Size the cache before you tune its policy, because a policy only chooses which part of a too-small set to lose. And when a fault appears only under one load shape, change the execution path one switch at a time, and keep the switch that serializes work for the debugger, not for the users.

Taught in

The SGLang manual measures the trace and the policies in the eviction and HiCache page, records the crash in the operating page, sizes the pool in the memory fraction page and weighs the graphs in the CUDA graphs page, and the RadixAttention lesson builds the tree that the policies walk.