Inferensys

Glossary

Cache Thrashing

A pathological state where the cache is constantly evicting and reloading entries due to a working set that exceeds the available memory, causing performance to collapse.
Finance professional using AI FP&A copilot on laptop, board presentation visible on screen, home office work session.
PERFORMANCE PATHOLOGY

What is Cache Thrashing?

Cache thrashing is a pathological performance state where a cache is forced to constantly evict and reload entries because the active working set of data exceeds the available cache capacity, causing throughput to collapse.

Cache thrashing occurs when the total memory footprint of frequently accessed data—the working set—is larger than the cache itself. The eviction policy continuously removes entries that are still needed, only to reload them moments later. This creates a vicious cycle where the CPU or inference engine spends more time managing cache misses than performing useful computation, often reducing throughput by an order of magnitude.

In sovereign inference caching, thrashing is triggered when the diversity of incoming queries overwhelms the semantic cache's vector index. Instead of serving low-latency hits, the system thrashes between embedding lookup, eviction, and recomputation. Mitigation requires increasing cache memory, implementing cache tiering to absorb working set fluctuations, or deploying adaptive caching policies that detect thrashing and dynamically adjust TTLs to stabilize the hit ratio.

PERFORMANCE PATHOLOGY

Core Characteristics of Cache Thrashing

Cache thrashing is a catastrophic performance state where the working set of active queries exceeds the available cache memory, forcing the system into a perpetual cycle of eviction and reloading. The cache provides no benefit while consuming significant CPU and I/O overhead.

01

The Eviction Death Spiral

Thrashing occurs when the working set—the collection of entries actively being accessed—is larger than the cache capacity. Every new request forces an eviction of an entry that will be needed again almost immediately. The cache hit ratio collapses toward 0%, yet the system incurs the full overhead of cache lookups, eviction processing, and reloading from the origin. This creates a negative net benefit: the cache makes the system slower than having no cache at all.

02

Root Cause: Working Set Exceeds Capacity

The primary trigger is a mismatch between cache size and access patterns. Key scenarios include:

  • Rapid context switching between many distinct inference contexts that collectively exceed memory
  • Highly random access patterns with low temporal locality, where entries are accessed once and never again
  • Cache pollution from one-shot queries that displace frequently reused entries
  • Memory pressure from the host system forcing the cache process to swap, compounding latency
03

Thrashing vs. Normal Misses

A healthy cache experiences compulsory misses (first access) and capacity misses (working set near limit). Thrashing is distinct: it is a non-linear phase transition where the miss rate suddenly spikes as the working set crosses the capacity threshold. Unlike normal operation where increasing cache size improves hit rate, a thrashing cache may show zero improvement from small size increases until the working set fits entirely. The system exhibits high CPU utilization with low throughput—a classic thrashing signature.

04

Detection Metrics

Identify thrashing through these telemetry signals:

  • Hit ratio drops below 20% and continues declining under steady load
  • Eviction rate spikes dramatically while the cache size remains at maximum
  • Average TTL of evicted entries drops to seconds or milliseconds—entries are evicted before they can be reused
  • Origin load increases to near-direct-access levels despite the cache layer being present
  • P99 latency increases due to the combined cost of cache miss + eviction + reload
05

Mitigation Strategies

Resolving thrashing requires structural changes:

  • Increase cache memory to exceed the working set size, moving past the phase transition point
  • Implement cache tiering with a larger, slower secondary cache to absorb the working set overflow
  • Apply admission policies that reject caching for one-hit-wonder entries, preventing cache pollution
  • Use probabilistic eviction like TinyLFU that estimates entry frequency to protect frequently accessed items
  • Partition the cache by tenant or query type to isolate thrashing workloads from stable ones
06

Sovereign Infrastructure Implications

In sovereign deployments with fixed, pre-provisioned hardware, thrashing is especially dangerous because elastic scaling is restricted. An air-gapped GPU cluster cannot burst to cloud resources. Mitigation must be proactive:

  • Workload characterization before deployment to right-size cache allocations
  • Circuit breakers that detect thrashing and temporarily bypass the cache to serve directly from the model, preserving throughput at the cost of latency
  • Semantic cache compaction using Product Quantization to fit more embeddings in the same memory footprint
CACHE THRASHING DIAGNOSTICS

Frequently Asked Questions

Cache thrashing represents a critical failure mode in sovereign inference caching layers where the working set exceeds available memory, causing performance to collapse. The following questions address the root causes, detection methods, and remediation strategies for this pathological state.

Cache thrashing is a pathological performance state where a caching layer spends more compute cycles evicting and reloading entries than actually serving cached responses. It occurs when the working set—the set of data actively accessed by the application—significantly exceeds the available cache memory capacity. In sovereign inference environments, this manifests when the volume of distinct LLM query embeddings surpasses the allocated memory for the semantic cache. The system enters a vicious cycle: a new request forces eviction of a recently cached entry, which is then immediately requested again, triggering another eviction. The cache hit ratio plummets toward zero, while backend model inference latency spikes as every request becomes a cache miss. This is distinct from simple capacity pressure; thrashing specifically describes the oscillating state where evictions directly cause subsequent misses in rapid succession.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.