Bucket Distribution in PartitionAlloc

In PartitionAlloc, a slab-based memory allocator, a “bucket” serves to categorize different memory allocation sizes. When memory is requested, PartitionAlloc rounds the requested size up to the nearest predefined size class (referred to as slot size). Allocations that map to the same bucket are then grouped together and allocated from a size-segregated slot span.

A bucket, therefore, defines a specific size category. This bucketing strategy is key to how PartitionAlloc manages and organizes memory efficiently, offering several benefits:

  • Increased cache locality for same-size allocations
  • Smaller metadata
  • Easy mapping of address to size
  • Decreased fragmentation over time

This document describes PartitionAlloc's methodology for mapping requested allocation sizes to their corresponding buckets. See //partition_alloc/bucket_lookup.h for implementation details.

Bucket Distribution Types

PartitionAlloc provides two different distributions; Neutral and Denser. As the name tells, Denser offers a more granular set of buckets, roughly doubling the number compared to the Neutral distribution.

  1. Neutral Bucket Distribution (kNeutral)
  • Pro: Results in fewer partially-filled slot spans, potentially reducing fragmentation caused by unused slots in these spans.
  • Con: Allocations are often rounded up to a significantly larger slot size than requested. This increases fragmentation within each allocation due to the larger difference between the requested size and the allocated slot size.
  1. Denser Bucket Distribution (kDenser):
  • Pro: Allocations can more closely match the requested memory size. This reduces fragmentation within each allocation, as the chosen slot size is nearer to the actual need.
  • Con: May lead to more partially-filled slot spans. If these slot spans are not fully utilized, it can increase fragmentation due to more unused slots across these spans.

The Neutral distribution is implemented as a variation of the Denser one, making it straightforward to understand if one understands the Denser layout.

Denser Bucket Distribution: A Closer Look

The Denser distribution itself operates as a hybrid system. For smaller allocation sizes, bucket sizes increase in a simple, linear fashion. Conversely, for larger allocation sizes, the bucket sizes increase exponentially.

Linear Sizing (for Smaller Allocations)

When an allocation request is for a relatively small amount of memory, the system employs a linear scale. This means each subsequent bucket size is larger than the previous one by a fixed increment. This increment is determined by the system's fundamental memory alignment requirement, which might be, for instance, 16 bytes. As an example, if this fixed increment is 16 bytes, the sequence of buckets might represent sizes such as 16 bytes, 32 bytes, 48 bytes, and so on.

Exponential Sizing (for Larger Allocations)

For larger memory requests, the bucket sizes adhere to an exponential pattern. The system divides broad power-of-two ranges, termed “orders,” into a fixed number of smaller bucket steps. For instance, the range of sizes from 128 bytes up to, but not including, 256 bytes constitutes an “order,” and it would contain a specific number of distinct bucket sizes. The subsequent order, such as 256 to 511 bytes, would be similarly divided.

A fixed number of buckets, for example eight, are used to subdivide each power-of-two range, creating what is known as “Buckets per Order.” This configuration results in a logarithmic scale where bucket sizes grow proportionally rather than by a fixed additive amount. To illustrate with an example using 8 buckets per order, sizes just above 128 bytes might be 128 bytes, then approximately 1.125x128 bytes, 1.25x128 bytes, and continue in this manner up to nearly 256 bytes. This pattern then repeats for sizes above 256 bytes, then 512 bytes, and so forth.

Order-Index 0Order-Index 1Order-Index 2Order-Index 3Order-Index 4Order-Index 5Order-Index 6Order-Index 7
Order 8 (2⁷)121-128129-144145-160161-176177-192193-208209-224225-240
Order 9 (2⁸)241-256257-288289-320321-352353-384385-416417-448449-480
Order 10 (2⁹)481-512513-576577-640641-704705-768769-832833-896897-960

Neutral Bucket Distribution

The Neutral Bucket Distribution offers a sparser alternative, derived from the Denser one. In the range where the Denser distribution uses linear sizing, or for the smallest exponential sizes where alignment naturally limits bucket density, the Neutral and Denser distributions are identical. However, for larger sizes within the exponential sizing range, the Neutral distribution typically uses fewer buckets per “order” compared to the Denser one. It selects every other bucket that the Denser distribution would define, leading to fewer, more widely spaced buckets.

Consider an illustrative conceptual difference: if the Denser distribution has buckets for sizes like ..., 384, 416, 448, 480, 512, ..., the Neutral distribution, in the same range, might only have buckets for ..., 384, then skip 416 to use 448, then skip 480 to use 512, and so on.

Example Distribution

8 Bytes Alignment (Typically 32-bit Systems)

IndexSizeBucket DistributionOriginating Formula
08kNeutral and kDenserlinear [8 x 1]
116kNeutral and kDenserlinear [8 x 2]
224kNeutral and kDenserlinear [8 x 3]
332kNeutral and kDenserlinear [8 x 4]
440kNeutral and kDenserlinear [8 x 5]
548kNeutral and kDenserlinear [8 x 6]
656kNeutral and kDenserlinear [8 x 7]
764kNeutral and kDenserlinear [8 x 8] yet exponential [2⁶ x (1 + 0)]
872kNeutral and kDenserlinear [8 x 9] yet exponential [2⁶ x (1 + ⅛)]
980kNeutral and kDenserlinear [8 x 10] yet exponential [2⁶ x (1 + ¼)]
1088kNeutral and kDenserlinear [8 x 11] yet exponential [2⁶ x (1 + ⅜)]
1196kNeutral and kDenserlinear [8 x 12] yet exponential [2⁶ x (1 + ½)]
12104kNeutral and kDenserlinear [8 x 13] yet exponential [2⁶ x (1 + ⅝)]
13112kNeutral and kDenserlinear [8 x 14] yet exponential [2⁶ x (1 + ¾)]
14120kNeutral and kDenserlinear [8 x 15] yet exponential [2⁶ x (1 + ⅞)]
15128kNeutral and kDenserlinear [8 x 16] yet exponential [2⁷ x (1 + 0)]
16144kDenser onlyexponential [2⁷ x (1 + ⅛)]
17160kNeutral and kDenserexponential [2⁷ x (1 + ¼)]
18176kDenser onlyexponential [2⁷ x (1 + ⅜)]
19192kNeutral and kDenserexponential [2⁷ x (1 + ½)]
20208kDenser onlyexponential [2⁷ x (1 + ⅝)]
21224kNeutral and kDenserexponential [2⁷ x (1 + ¾)]
22240kDenser onlyexponential [2⁷ x (1 + ⅞)]
23256kNeutral and kDenserexponential [2⁸ x (1 + 0)]
24288kDenser onlyexponential [2⁸ x (1 + ⅛)]
25320kNeutral and kDenserexponential [2⁸ x (1 + ¼)]
26352kDenser onlyexponential [2⁸ x (1 + ⅜)]
27384kNeutral and kDenserexponential [2⁸ x (1 + ½)]
28416kDenser onlyexponential [2⁸ x (1 + ⅝)]
29448kNeutral and kDenserexponential [2⁸ x (1 + ¾)]
30480kDenser onlyexponential [2⁸ x (1 + ⅞)]
31512kNeutral and kDenserexponential [2⁹ x (1 + 0)]
32576kDenser onlyexponential [2⁹ x (1 + ⅛)]
33640kNeutral and kDenserexponential [2⁹ x (1 + ¼)]
34704kDenser onlyexponential [2⁹ x (1 + ⅜)]
35768kNeutral and kDenserexponential [2⁹ x (1 + ½)]
36832kDenser onlyexponential [2⁹ x (1 + ⅝)]
37896kNeutral and kDenserexponential [2⁹ x (1 + ¾)]
38960kDenser onlyexponential [2⁹ x (1 + ⅞)]
391024kNeutral and kDenserexponential [2¹⁰ x (1 + 0)]
401152kDenser onlyexponential [2¹⁰ x (1 + ⅛)]
411280kNeutral and kDenserexponential [2¹⁰ x (1 + ¼)]
421408kDenser onlyexponential [2¹⁰ x (1 + ⅜)]
431536kNeutral and kDenserexponential [2¹⁰ x (1 + ½)]
441664kDenser onlyexponential [2¹⁰ x (1 + ⅝)]
451792kNeutral and kDenserexponential [2¹⁰ x (1 + ¾)]
461920kDenser onlyexponential [2¹⁰ x (1 + ⅞)]
472048kNeutral and kDenserexponential [2¹¹ x (1 + 0)]
482304kDenser onlyexponential [2¹¹ x (1 + ⅛)]
492560kNeutral and kDenserexponential [2¹¹ x (1 + ¼)]
502816kDenser onlyexponential [2¹¹ x (1 + ⅜)]
513072kNeutral and kDenserexponential [2¹¹ x (1 + ½)]
523328kDenser onlyexponential [2¹¹ x (1 + ⅝)]
533584kNeutral and kDenserexponential [2¹¹ x (1 + ¾)]
543840kDenser onlyexponential [2¹¹ x (1 + ⅞)]
554096kNeutral and kDenserexponential [2¹² x (1 + 0)]
564608kDenser onlyexponential [2¹² x (1 + ⅛)]
575120kNeutral and kDenserexponential [2¹² x (1 + ¼)]
585632kDenser onlyexponential [2¹² x (1 + ⅜)]
596144kNeutral and kDenserexponential [2¹² x (1 + ½)]
606656kDenser onlyexponential [2¹² x (1 + ⅝)]
617168kNeutral and kDenserexponential [2¹² x (1 + ¾)]
627680kDenser onlyexponential [2¹² x (1 + ⅞)]
638192kNeutral and kDenserexponential [2¹³ x (1 + 0)]
649216kDenser onlyexponential [2¹³ x (1 + ⅛)]
6510240kNeutral and kDenserexponential [2¹³ x (1 + ¼)]
6611264kDenser onlyexponential [2¹³ x (1 + ⅜)]
6712288kNeutral and kDenserexponential [2¹³ x (1 + ½)]
6813312kDenser onlyexponential [2¹³ x (1 + ⅝)]
6914336kNeutral and kDenserexponential [2¹³ x (1 + ¾)]
7015360kDenser onlyexponential [2¹³ x (1 + ⅞)]
7116384kNeutral and kDenserexponential [2¹⁴ x (1 + 0)]
7218432kDenser onlyexponential [2¹⁴ x (1 + ⅛)]
7320480kNeutral and kDenserexponential [2¹⁴ x (1 + ¼)]
7422528kDenser onlyexponential [2¹⁴ x (1 + ⅜)]
7524576kNeutral and kDenserexponential [2¹⁴ x (1 + ½)]
7626624kDenser onlyexponential [2¹⁴ x (1 + ⅝)]
7728672kNeutral and kDenserexponential [2¹⁴ x (1 + ¾)]
7830720kDenser onlyexponential [2¹⁴ x (1 + ⅞)]
7932768kNeutral and kDenserexponential [2¹⁵ x (1 + 0)]
8036864kDenser onlyexponential [2¹⁵ x (1 + ⅛)]
8140960kNeutral and kDenserexponential [2¹⁵ x (1 + ¼)]
8245056kDenser onlyexponential [2¹⁵ x (1 + ⅜)]
8349152kNeutral and kDenserexponential [2¹⁵ x (1 + ½)]
8453248kDenser onlyexponential [2¹⁵ x (1 + ⅝)]
8557344kNeutral and kDenserexponential [2¹⁵ x (1 + ¾)]
8661440kDenser onlyexponential [2¹⁵ x (1 + ⅞)]
8765536kNeutral and kDenserexponential [2¹⁶ x (1 + 0)]
8873728kDenser onlyexponential [2¹⁶ x (1 + ⅛)]
8981920kNeutral and kDenserexponential [2¹⁶ x (1 + ¼)]
9090112kDenser onlyexponential [2¹⁶ x (1 + ⅜)]
9198304kNeutral and kDenserexponential [2¹⁶ x (1 + ½)]
92106496kDenser onlyexponential [2¹⁶ x (1 + ⅝)]
93114688kNeutral and kDenserexponential [2¹⁶ x (1 + ¾)]
94122880kDenser onlyexponential [2¹⁶ x (1 + ⅞)]
95131072kNeutral and kDenserexponential [2¹⁷ x (1 + 0)]
96147456kDenser onlyexponential [2¹⁷ x (1 + ⅛)]
97163840kNeutral and kDenserexponential [2¹⁷ x (1 + ¼)]
98180224kDenser onlyexponential [2¹⁷ x (1 + ⅜)]
99196608kNeutral and kDenserexponential [2¹⁷ x (1 + ½)]
100212992kDenser onlyexponential [2¹⁷ x (1 + ⅝)]
101229376kNeutral and kDenserexponential [2¹⁷ x (1 + ¾)]
102245760kDenser onlyexponential [2¹⁷ x (1 + ⅞)]
103262144kNeutral and kDenserexponential [2¹⁸ x (1 + 0)]
104294912kDenser onlyexponential [2¹⁸ x (1 + ⅛)]
105327680kNeutral and kDenserexponential [2¹⁸ x (1 + ¼)]
106360448kDenser onlyexponential [2¹⁸ x (1 + ⅜)]
107393216kNeutral and kDenserexponential [2¹⁸ x (1 + ½)]
108425984kDenser onlyexponential [2¹⁸ x (1 + ⅝)]
109458752kNeutral and kDenserexponential [2¹⁸ x (1 + ¾)]
110491520kDenser onlyexponential [2¹⁸ x (1 + ⅞)]
111524288kNeutral and kDenserexponential [2¹⁹ x (1 + 0)]
112589824kDenser onlyexponential [2¹⁹ x (1 + ⅛)]
113655360kNeutral and kDenserexponential [2¹⁹ x (1 + ¼)]
114720896kDenser onlyexponential [2¹⁹ x (1 + ⅜)]
115786432kNeutral and kDenserexponential [2¹⁹ x (1 + ½)]
116851968kDenser onlyexponential [2¹⁹ x (1 + ⅝)]
117917504kNeutral and kDenserexponential [2¹⁹ x (1 + ¾)]
118983040kNeutral and kDenserexponential [2¹⁹ x (1 + ⅞)]

16 Bytes Alignment (Typically 64-bit Systems)

IndexSizeBucket DistributionOriginating Formula
016kNeutral and kDenserlinear [16 x 1]
132kNeutral and kDenserlinear [16 x 2]
248kNeutral and kDenserlinear [16 x 3]
364kNeutral and kDenserlinear [16 x 4]
480kNeutral and kDenserlinear [16 x 5]
596kNeutral and kDenserlinear [16 x 6]
6112kNeutral and kDenserlinear [16 x 7]
7128kNeutral and kDenserlinear [16 x 8] yet exponential [2⁷ x (1 + 0)]
8144kNeutral and kDenserlinear [16 x 9] yet exponential [2⁷ x (1 + ⅛)]
9160kNeutral and kDenserlinear [16 x 10] yet exponential [2⁷ x (1 + ¼)]
10176kNeutral and kDenserlinear [16 x 11] yet exponential [2⁷ x (1 + ⅜)]
11192kNeutral and kDenserlinear [16 x 12] yet exponential [2⁷ x (1 + ½)]
12208kNeutral and kDenserlinear [16 x 13] yet exponential [2⁷ x (1 + ⅝)]
13224kNeutral and kDenserlinear [16 x 14] yet exponential [2⁷ x (1 + ¾)]
14240kNeutral and kDenserlinear [16 x 15] yet exponential [2⁷ x (1 + ⅞)]
15256kNeutral and kDenserlinear [16 x 16] yet exponential [2⁸ x (1 + 0)]
16288kDenser onlyexponential [2⁸ x (1 + ⅛)]
17320kNeutral and kDenserexponential [2⁸ x (1 + ¼)]
18352kDenser onlyexponential [2⁸ x (1 + ⅜)]
19384kNeutral and kDenserexponential [2⁸ x (1 + ½)]
20416kDenser onlyexponential [2⁸ x (1 + ⅝)]
21448kNeutral and kDenserexponential [2⁸ x (1 + ¾)]
22480kDenser onlyexponential [2⁸ x (1 + ⅞)]
23512kNeutral and kDenserexponential [2⁹ x (1 + 0)]
24576kDenser onlyexponential [2⁹ x (1 + ⅛)]
25640kNeutral and kDenserexponential [2⁹ x (1 + ¼)]
26704kDenser onlyexponential [2⁹ x (1 + ⅜)]
27768kNeutral and kDenserexponential [2⁹ x (1 + ½)]
28832kDenser onlyexponential [2⁹ x (1 + ⅝)]
29896kNeutral and kDenserexponential [2⁹ x (1 + ¾)]
30960kDenser onlyexponential [2⁹ x (1 + ⅞)]
311024kNeutral and kDenserexponential [2¹⁰ x (1 + 0)]
321152kDenser onlyexponential [2¹⁰ x (1 + ⅛)]
331280kNeutral and kDenserexponential [2¹⁰ x (1 + ¼)]
341408kDenser onlyexponential [2¹⁰ x (1 + ⅜)]
351536kNeutral and kDenserexponential [2¹⁰ x (1 + ½)]
361664kDenser onlyexponential [2¹⁰ x (1 + ⅝)]
371792kNeutral and kDenserexponential [2¹⁰ x (1 + ¾)]
381920kDenser onlyexponential [2¹⁰ x (1 + ⅞)]
392048kNeutral and kDenserexponential [2¹¹ x (1 + 0)]
402304kDenser onlyexponential [2¹¹ x (1 + ⅛)]
412560kNeutral and kDenserexponential [2¹¹ x (1 + ¼)]
422816kDenser onlyexponential [2¹¹ x (1 + ⅜)]
433072kNeutral and kDenserexponential [2¹¹ x (1 + ½)]
443328kDenser onlyexponential [2¹¹ x (1 + ⅝)]
453584kNeutral and kDenserexponential [2¹¹ x (1 + ¾)]
463840kDenser onlyexponential [2¹¹ x (1 + ⅞)]
474096kNeutral and kDenserexponential [2¹² x (1 + 0)]
484608kDenser onlyexponential [2¹² x (1 + ⅛)]
495120kNeutral and kDenserexponential [2¹² x (1 + ¼)]
505632kDenser onlyexponential [2¹² x (1 + ⅜)]
516144kNeutral and kDenserexponential [2¹² x (1 + ½)]
526656kDenser onlyexponential [2¹² x (1 + ⅝)]
537168kNeutral and kDenserexponential [2¹² x (1 + ¾)]
547680kDenser onlyexponential [2¹² x (1 + ⅞)]
558192kNeutral and kDenserexponential [2¹³ x (1 + 0)]
569216kDenser onlyexponential [2¹³ x (1 + ⅛)]
5710240kNeutral and kDenserexponential [2¹³ x (1 + ¼)]
5811264kDenser onlyexponential [2¹³ x (1 + ⅜)]
5912288kNeutral and kDenserexponential [2¹³ x (1 + ½)]
6013312kDenser onlyexponential [2¹³ x (1 + ⅝)]
6114336kNeutral and kDenserexponential [2¹³ x (1 + ¾)]
6215360kDenser onlyexponential [2¹³ x (1 + ⅞)]
6316384kNeutral and kDenserexponential [2¹⁴ x (1 + 0)]
6418432kDenser onlyexponential [2¹⁴ x (1 + ⅛)]
6520480kNeutral and kDenserexponential [2¹⁴ x (1 + ¼)]
6622528kDenser onlyexponential [2¹⁴ x (1 + ⅜)]
6724576kNeutral and kDenserexponential [2¹⁴ x (1 + ½)]
6826624kDenser onlyexponential [2¹⁴ x (1 + ⅝)]
6928672kNeutral and kDenserexponential [2¹⁴ x (1 + ¾)]
7030720kDenser onlyexponential [2¹⁴ x (1 + ⅞)]
7132768kNeutral and kDenserexponential [2¹⁵ x (1 + 0)]
7236864kDenser onlyexponential [2¹⁵ x (1 + ⅛)]
7340960kNeutral and kDenserexponential [2¹⁵ x (1 + ¼)]
7445056kDenser onlyexponential [2¹⁵ x (1 + ⅜)]
7549152kNeutral and kDenserexponential [2¹⁵ x (1 + ½)]
7653248kDenser onlyexponential [2¹⁵ x (1 + ⅝)]
7757344kNeutral and kDenserexponential [2¹⁵ x (1 + ¾)]
7861440kDenser onlyexponential [2¹⁵ x (1 + ⅞)]
7965536kNeutral and kDenserexponential [2¹⁶ x (1 + 0)]
8073728kDenser onlyexponential [2¹⁶ x (1 + ⅛)]
8181920kNeutral and kDenserexponential [2¹⁶ x (1 + ¼)]
8290112kDenser onlyexponential [2¹⁶ x (1 + ⅜)]
8398304kNeutral and kDenserexponential [2¹⁶ x (1 + ½)]
84106496kDenser onlyexponential [2¹⁶ x (1 + ⅝)]
85114688kNeutral and kDenserexponential [2¹⁶ x (1 + ¾)]
86122880kDenser onlyexponential [2¹⁶ x (1 + ⅞)]
87131072kNeutral and kDenserexponential [2¹⁷ x (1 + 0)]
88147456kDenser onlyexponential [2¹⁷ x (1 + ⅛)]
89163840kNeutral and kDenserexponential [2¹⁷ x (1 + ¼)]
90180224kDenser onlyexponential [2¹⁷ x (1 + ⅜)]
91196608kNeutral and kDenserexponential [2¹⁷ x (1 + ½)]
92212992kDenser onlyexponential [2¹⁷ x (1 + ⅝)]
93229376kNeutral and kDenserexponential [2¹⁷ x (1 + ¾)]
94245760kDenser onlyexponential [2¹⁷ x (1 + ⅞)]
95262144kNeutral and kDenserexponential [2¹⁸ x (1 + 0)]
96294912kDenser onlyexponential [2¹⁸ x (1 + ⅛)]
97327680kNeutral and kDenserexponential [2¹⁸ x (1 + ¼)]
98360448kDenser onlyexponential [2¹⁸ x (1 + ⅜)]
99393216kNeutral and kDenserexponential [2¹⁸ x (1 + ½)]
100425984kDenser onlyexponential [2¹⁸ x (1 + ⅝)]
101458752kNeutral and kDenserexponential [2¹⁸ x (1 + ¾)]
102491520kDenser onlyexponential [2¹⁸ x (1 + ⅞)]
103524288kNeutral and kDenserexponential [2¹⁹ x (1 + 0)]
104589824kDenser onlyexponential [2¹⁹ x (1 + ⅛)]
105655360kNeutral and kDenserexponential [2¹⁹ x (1 + ¼)]
106720896kDenser onlyexponential [2¹⁹ x (1 + ⅜)]
107786432kNeutral and kDenserexponential [2¹⁹ x (1 + ½)]
108851968kDenser onlyexponential [2¹⁹ x (1 + ⅝)]
109917504kNeutral and kDenserexponential [2¹⁹ x (1 + ¾)]
110983040kNeutral and kDenserexponential [2¹⁹ x (1 + ⅞)]