BEAM's Lightweight Processes: Minimizing Cache Pollution

Unlike heavyweight OS threads that often necessitate full TLB invalidation and can pollute CPU caches during context switches due to their large context and distinct memory spaces, BEAM's user-space scheduled, isolated processes minimize this overhead, thereby promoting better cache and TLB locality.

The top 3

  1. Isolated Heaps: BEAM's Cache-Friendly Design: Each BEAM lightweight process maintains its own private memory heap, a fundamental architectural difference from traditional OS threads that share memory. This design inherently prevents cross-process cache invalidation, ensuring that data relevant to one process does not evict another's cached data, thus minimizing cache pollution.
  2. Message Passing: No Shared Memory, No Cache Wars: BEAM processes communicate exclusively through asynchronous message passing, copying small immutable data directly between processes and using reference counting for large binaries. This model avoids shared memory, eliminating the need for locks and complex cache coherence protocols that typically cause significant cache thrashing and invalidation in concurrent systems.
  3. Per-Process GC: Eliminating Global Cache Pauses: BEAM's lightweight processes benefit from individual generational garbage collectors, each operating only on its small, isolated heap. This design avoids global "stop-the-world" pauses common in other VMs, which can cause widespread cache invalidations. By limiting GC impact to single processes, BEAM maintains better cache locality and more predictable latency across a large number of concurrent operations.

Sources

Open the full topic