A deep dive into Redis internals explaining how Redis tracks and caps memory usage. Rather than limiting by key count, Redis wraps standard malloc with a custom zmalloc implementation that atomically tracks total allocated bytes via a global counter. This allows Redis to know its exact memory consumption at any moment without expensive system calls. The zmalloc layer deliberately does not enforce limits itself — it only tracks usage. Enforcement happens separately in evict.c, which loops and evicts keys until used memory drops below the configured maxmemory threshold. The post also briefly discusses why a Go reimplementation caps by key count instead, since Go lacks easy manual memory management hooks.
•13m watch time
18 Impressions