raw
current commit
261004.7 · deps: update V8 to 15.2.124.38

Zone Allocator in V8

The Zone allocator is a region-based memory manager used in V8 to support fast allocation of small chunks of memory. Chunks allocated in a Zone cannot be deallocated individually. Instead, the Zone supports deallocating all chunks in one fast operation.

This makes Zones ideal for holding temporary data structures that are needed only for a specific phase of execution, such as the Abstract Syntax Tree (AST) or compiler intermediate representations (IR), which can be discarded all at once after compilation is complete.

Notably, object pointers within a Zone can be relied on to stay live and available after allocation for as long as the Zone is live. This allows easier definition of complex data structures without having to worry about reachability, reference counting, or clean teardown of individual elements.

How it Works

The Zone allocator works by requesting large segments of memory from the OS or a memory pool and then satisfying allocation requests by simply moving a pointer within the current segment.

Segments

A Zone maintains a linked list of Segments. When a Zone is created, it doesn’t allocate any memory immediately. The first allocation triggers the allocation of a segment. Segments are requested via the AccountingAllocator.

Bump Pointer Allocation

Within a segment, allocation is extremely fast. It is a “bump pointer” allocation:

  1. Check if the requested size fits in the remaining space of the current segment.
  2. If it fits, return the current position and “bump” the position pointer forward by the requested size.
  3. If it doesn’t fit, expand the zone by allocating a new segment.

Expansion Strategy

When the current segment is full, the Zone calls Expand to get a new segment.

Key Classes

Zone Containers

To facilitate the use of Zones, V8 provides a set of containers that are specialized to use Zone allocation:

These containers ensure that their internal nodes and backing stores are allocated within the Zone.

Usage in the Codebase

The Zone allocator is used pervasively in the V8 compiler (src/compiler/).

Note: The Zone implementation is inherently not thread-safe.