Skip to content
About
Main content
Query Engines

Memory & Resource Management

Who is allowed to hold how much memory, for how long, and what happens to the work when the answer is less than it asked for?

Who this mechanism is for: a developer who writes code, calls APIs and knows basic SQL, and who has seen an "" error, but has never studied how a database engine, a or an operating system actually decides who gets memory. You do not need to know what a , an or a memory grant is. Every technical term is explained the first time it appears, and again in the glossary at the end.

The story we will follow

Amara Okafor is a backend engineer at Voltara, a regional electricity utility. Voltara reads about one billion smart-meter readings per day (who used how much power, and when). Amara works on Meterbase, the in-house query engine that stores and analyses these readings. Meterbase runs on the Java virtual machine (JVM), has its own storage layer with a cache of disk pages, and runs on servers with 2 CPU sockets, 256 GB of RAM and local NVMe SSDs. Three kinds of work share these servers: a nightly billing batch, an analyst dashboard that sends thousands of short lookups, and ad-hoc big joins written by Yuki Tanaka, a data scientist. Dmitri Volkov is the site-reliability engineer (SRE) who is on call when something breaks at 3 am.

During one quarter Amara will meet five problems, one at the start of each article below. Each problem looks like a bug: a job killed for no reason, a program that freezes, a cache that suddenly stops working, a query that is six times slower after "only a little" extra work. Each one is actually a consequence of one fact about memory. At the end of each article we go back to Amara and solve her problem with the mechanisms of that part.

This is the main idea of this whole mechanism:

How this mechanism is organized

After that: a summary, hands-on labs, interview questions and a glossary.

A request: do not skip the arithmetic. Many results here are short formulas (for example usable frames = total − pinned − dirty). The shapes of these formulas, steep walls and sudden cliffs, are the real content.

What do I do, and what does each option cost?

Can I see it myself?

Can I reason about it under questioning?

Trade-offs

The tensions this mechanism takes a position on. Each recurs across mechanisms.

Show all 10 trade-offs
Recurring principles

Ideas this mechanism meets that keep coming back, mechanism after mechanism.

Show all 12 principles