blob: c1ca507b588553be038ec9d38dcf7ffaf593e265 [file] [log] [blame] [view]
Kalvin Lee5f8555b2022-05-16 21:30:201# Glossary
2
3This page describes some core terminology used in PartitionAlloc.
4A weak attempt is made to present terms "in conceptual order" s.t.
5each term depends mainly upon previously defined ones.
6
Kalvin Lee2c238972024-03-11 02:55:017### Partition
8
9A heap that is separated and protected both from other
10partitions and from non-PartitionAlloc memory. Each partition holds
11multiple buckets.
Kalvin Lee8338a462022-07-29 02:19:2512
13*** promo
14**NOTE**: In code (and comments), "partition," "root," and even
15"allocator" are all conceptually the same thing.
16***
17
Kalvin Lee5f8555b2022-05-16 21:30:2018## Pages
19
Kalvin Lee2c238972024-03-11 02:55:0120### System Page
21
22A memory page defined by the CPU/OS. Commonly
23referred to as a "virtual page" in other contexts. This is typically
244KiB, but it can be larger. PartitionAlloc supports up to 64KiB,
25though this constant isn't always known at compile time (depending
26on the OS).
27
28### Partition Page
29
30The most common granularity used by
31PartitionAlloc. Consists of exactly 4 system pages.
32
33### Super Page
34
35A 2MiB region, aligned on a 2MiB boundary. Not to
36be confused with OS-level terms like "large page" or "huge page",
37which are also commonly 2MiB. These have to be fully committed /
38uncommitted in memory, whereas super pages can be partially committed
39with system page granularity.
40
41### Extent
42
43An extent is a run of consecutive super pages (belonging
44to a single partition). Extents are to super pages what slot spans are
45to slots (see below).
Kalvin Lee5f8555b2022-05-16 21:30:2046
47## Slots and Spans
48
Kalvin Lee2c238972024-03-11 02:55:0149### Slot
50
51An indivisible allocation unit. Slot sizes are tied to
52buckets. For example, each allocation that falls into the bucket
53(224, 256] would be satisfied with a slot of size 256. This
54applies only to normal buckets, not to direct map.
55
56### Slot Span
57
58A run of same-sized slots that are contiguous in
59memory. Slot span size is a multiple of partition page size, but it
60isn't always a multiple of slot size, although we try hard for this
61to be the case.
62
63### Small Bucket
64
65Allocations up to 4 partition pages. In these
66cases, slot spans are always between 1 and 4 partition pages in
67size. For each slot span size, the slot span is chosen to minimize
68number of pages used while keeping the rounding waste under a
69reasonable limit.
70
71* For example, for a slot size 96, 64B waste is deemed acceptable
72 when using a single partition page, but for slot size
73 384, the potential waste of 256B wouldn't be, so 3 partition pages
74 are used to achieve 0B waste.
75* PartitionAlloc may avoid waste by lowering the number of committed
76 system pages compared to the number of reserved pages. For
77 example, for the slot size of 896B we'd use a slot span of 2
78 partition pages of 16KiB, i.e. 8 system pages of 4KiB, but commit
79 only up to 7, thus resulting in perfect packing.
80
81### Single-Slot Span
82
83Allocations above 4 partition pages (but
mikt1397a7c2025-05-02 04:35:4684≤`BucketIndexLookup::kMaxBucketSize`). This is because each slot span is guaranteed to
Kalvin Lee2c238972024-03-11 02:55:0185hold exactly one slot.
86
87*** promo
88Fun fact: there are sizes ≤4 partition pages that result in a
89slot span having exactly 1 slot, but nonetheless they're still
90classified as small buckets. The reason is that single-slot spans
91are often handled by a different code path, and that distinction
92is made purely based on slot size, for simplicity and efficiency.
93***
Kalvin Lee5f8555b2022-05-16 21:30:2094
Kalvin Lee13892252023-04-13 07:29:2395## Buckets
96
Kalvin Lee2c238972024-03-11 02:55:0197### Bucket
98
99A collection of regions in a partition that contains
100similar-sized objects. For example, one bucket may hold objects of
101size (224, 256], another (256, 320], etc. Bucket size
102brackets are geometrically spaced,
mikt1397a7c2025-05-02 04:35:46103[going up to `BucketIndexLookup::kMaxBucketSize`][max-bucket-comment].
104See [Bucket Distribution in PartitionAlloc](./buckets.md) for details.
Kalvin Lee2c238972024-03-11 02:55:01105
106*** promo
107Plainly put, all slots (ergo the resulting spans) of a given size
108class are logically chained into one bucket.
109***
Kalvin Leee42e1432023-04-13 07:52:41110
111![A bucket, spanning multiple super pages, collects spans whose
Kalvin Leea9287812023-11-21 00:12:05112 slots are of a particular size class.](./src/partition_alloc/dot/bucket.png)
Kalvin Leee42e1432023-04-13 07:52:41113
Kalvin Lee2c238972024-03-11 02:55:01114### Normal Bucket
115
116Any bucket whose size ceiling does not exceed
mikt1397a7c2025-05-02 04:35:46117`BucketIndexLookup::kMaxBucketSize`. This is the common case in PartitionAlloc, and
Kalvin Lee2c238972024-03-11 02:55:01118the "normal" modifier is often dropped in casual reference.
119
120### Direct Map (Bucket)
121
mikt1397a7c2025-05-02 04:35:46122Any allocation whose size exceeds `BucketIndexLookup::kMaxBucketSize`.
Kalvin Lee13892252023-04-13 07:29:23123
Kalvin Lee5f8555b2022-05-16 21:30:20124## Other Terms
125
Kalvin Lee2c238972024-03-11 02:55:01126### Object
127
128A chunk of memory returned to the allocating invoker
129of the size requested. It doesn't have to span the entire slot,
130nor does it have to begin at the slot start. This term is commonly
131used as a parameter name in PartitionAlloc code, as opposed to
132`slot_start`.
133
134### Thread Cache
135
136A [thread-local structure][pa-thread-cache] that
137holds some not-too-large memory chunks, ready to be allocated. This
138speeds up in-thread allocation by reducing a lock hold to a
139thread-local storage lookup, improving cache locality.
140
141### Pool
142
143A large (and contiguous on 64-bit) virtual address region, housing
144super pages, etc. from which PartitionAlloc services allocations. The
145primary purpose of the pools is to provide a fast answer to the
146question, "Did PartitionAlloc allocate the memory for this pointer
147from this pool?" with a single bit-masking operation.
148
149* The regular pool is a general purpose pool that contains allocations that
Bartek Nowierskif2d03ca2022-10-04 10:08:57150 aren't protected by BackupRefPtr.
Kalvin Lee2c238972024-03-11 02:55:01151* The BRP pool contains all allocations protected by BackupRefPtr.
152* [64-bit only] The configurable pool is named generically, because its
Bartek Nowierskif2d03ca2022-10-04 10:08:57153 primary user (the [V8 Sandbox][v8-sandbox]) can configure it at runtime,
154 providing a pre-existing mapping. Its allocations aren't protected by
155 BackupRefPtr.
Kalvin Lee2c238972024-03-11 02:55:01156* [64-bit only] The thread isolated pool is returning memory protected with
Stephen Roettger3554d012023-05-10 09:06:54157 per-thread permissions. At the moment, this is implemented for pkeys on x64.
158 It's primary user is [V8 CFI][v8-cfi].
Kalvin Lee67bcfa52022-10-03 02:58:50159
Kalvin Lee9dae9c02023-07-11 08:19:30160![The singular AddressPoolManager mediates access to the separate pools
Kalvin Leea9287812023-11-21 00:12:05161 for each PartitionRoot.](./src/partition_alloc/dot/address-space.png)
Kalvin Lee9dae9c02023-07-11 08:19:30162
Kalvin Lee67bcfa52022-10-03 02:58:50163*** promo
Bartek Nowierskif2d03ca2022-10-04 10:08:57164Pools are downgraded into a logical concept in 32-bit environments,
165tracking a non-contiguous set of allocations using a bitmap.
Kalvin Lee67bcfa52022-10-03 02:58:50166***
167
Kalvin Lee2c238972024-03-11 02:55:01168### Payload
169
170The usable area of a super page in which slot spans
171reside. While generally this means "everything between the first
172and last guard partition pages in a super page," the presence of
miktb0cb7522024-07-12 07:33:52173other metadata can bump the starting offset
Kalvin Lee2c238972024-03-11 02:55:01174forward. While this term is entrenched in the code, the team
175considers it suboptimal and is actively looking for a replacement.
176
177### Allocation Fast Path
178
179A path taken during an allocation that is
180considered fast. Usually means that an allocation request can be
181immediately satisfied by grabbing a slot from the freelist of the
182first active slot span in the bucket.
183
184### Allocation Slow Path
185
186Anything which is not fast (see above).
187
188Can involve
189
190* finding another active slot span in the list,
191* provisioning more slots in a slot span,
192* bringing back a free (or decommitted) slot span,
193* allocating a new slot span, or even
194* allocating a new super page.
Kalvin Leedbbd6e42022-08-09 02:35:37195
196*** aside
197By "slow" we may mean something as simple as extra logic (`if`
198statements etc.), or something as costly as system calls.
199***
Kalvin Lee5f8555b2022-05-16 21:30:20200
Kalvin Lee67bcfa52022-10-03 02:58:50201## Legacy Terms
202
203These terms are (mostly) deprecated and should not be used. They are
204surfaced here to provide a ready reference for readers coming from
205older design documents or documentation.
206
Kalvin Lee2c238972024-03-11 02:55:01207### GigaCage
208
209A memory region several gigabytes wide, reserved by
210PartitionAlloc upon initialization, from which nearly all allocations
211are taken. _Pools_ have overtaken GigaCage in conceptual importance,
212and so and so there is less need today to refer to "GigaCage" or the
213"cage." This is especially true given the V8 Sandbox and the
214configurable pool (see above).
Kalvin Lee67bcfa52022-10-03 02:58:50215
Kalvin Lee5f8555b2022-05-16 21:30:20216## PartitionAlloc-Everywhere
217
218Originally, PartitionAlloc was used only in Blink (Chromium's rendering engine).
219It was invoked explicitly, by calling PartitionAlloc APIs directly.
220
221PartitionAlloc-Everywhere is the name of the project that brought PartitionAlloc
222to the entire-ish codebase (exclusions apply). This was done by intercepting
223`malloc()`, `free()`, `realloc()`, aforementioned `posix_memalign()`, etc. and
224routing them into PartitionAlloc. The shim located in
Yuki Shiino550a6e72023-10-24 23:07:29225`base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.h` is
Kalvin Lee5f8555b2022-05-16 21:30:20226responsible for intercepting. For more details, see
227[base/allocator/README.md](../../../base/allocator/README.md).
228
229A special, catch-it-all *Malloc* partition has been created for the intercepted
230`malloc()` et al. This is to isolate from already existing Blink partitions.
231The only exception from that is Blink's *FastMalloc* partition, which was also
232catch-it-all in nature, so it's perfectly fine to merge these together, to
233minimize fragmentation.
234
235As of 2022, PartitionAlloc-Everywhere is supported on
236
Kalvin Lee2c238972024-03-11 02:55:01237* Windows 32- and 64-bit
238* Linux
239* Android 32- and 64-bit
240* macOS
241* Fuchsia
Kalvin Lee5f8555b2022-05-16 21:30:20242
mikt1397a7c2025-05-02 04:35:46243[max-bucket-comment]: https://source.chromium.org/search?q=-file:third_party%2F(angle%7Cdawn)%20file:partition_alloc_constants.h%20symbol:BucketIndexLookup::kMaxBucketSize$&ss=chromium
Kalvin Lee022d0cc2024-03-27 07:17:22244[pa-thread-cache]: https://source.chromium.org/search?q=-file:third_party%2F(angle%7Cdawn)%20file:partition_alloc/thread_cache.h&ss=chromium
Kalvin Lee67bcfa52022-10-03 02:58:50245[v8-sandbox]: https://docs.google.com/document/d/1FM4fQmIhEqPG8uGp5o9A-mnPB5BOeScZYpkHjo0KKA8/preview#
Stephen Roettger6b495de2022-11-07 15:55:18246[v8-cfi]: https://docs.google.com/document/d/1O2jwK4dxI3nRcOJuPYkonhTkNQfbmwdvxQMyXgeaRHo/preview#