Basis Lab

What a Container Actually Is

Half a Processor and 512 MB, and Why Only One of Them Kills

Last timeA Different Root Directory

A quota inside a window gives a container half a processor and a memory limit gives it 512 MB, and the two edges behave nothing alike: one defers work in silence, the other kills a process.

A container given half a processor and 512 MB of memory can run out of both in

the same minute, and you will hear about only one of them. That asymmetry is the

most useful thing on this page, and it is not a quirk of any particular tool. It

follows from what processor time and memory are: one of them can be handed out

in smaller portions and the other one cannot.

Both limits work the same way up to the moment they bite. The kernel keeps a

counter, a limit is a number compared against that counter, and the comparison

happens on the group of processes rather than on the one process you started.

What is being counted, and for whom

The accounting comes first and exists on its own. For every group of processes

the kernel maintains a running total of processor time consumed and of memory

charged, and those totals are readable whether or not anything is capped. A

limit adds no machinery: it is a number put beside a counter, with a rule for

what happens when the counter reaches it.

Two details about the counting matter later. The unit is the group, so a

container that forks a worker pool is one account and not nine, and processor

time spent by any thread in it is charged to the same quota. And memory charged

to the group includes page cache the group caused to be read, not only the

memory the program asked for, which is why a counter can read higher than the

program thinks it is holding.

This is also where the numbers to use come from. The counters can be read for

weeks with nothing limited at all, and the observed peak plus a margin is a far

better limit than a round number that sounded safe.

Half a processor is two numbers

A share of a processor is written as a quota of microseconds inside a repeating

window of microseconds. The group may run until it has spent its quota, and then

it waits for the window to end.

The lesson stops here

9 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01One Kernel, Many Processes, and No Boot Sequence Anywhere
  2. 02Six Views a Process Can Be Given Instead of Yoursopening only
  3. 03A Different Root Directory, and Why It Is Not a Wallopening only
  4. 04Half a Processor and 512 MB, and Why Only One of Them Killsyou are here
  5. 05Layers, and Why One Line Rebuilds Sixty Megabytesopening only
  6. 06Why the File It Wrote Is Owned by Rootopening only
  7. 07Follow One Request In, and Name Every Translation on the Wayopening only
  8. 08The Boundary Is a View, and the Kernel Underneath It Is Sharedopening only

Read alongside