@@ -180,10 +180,9 @@ large number of guard pages created by hardened\_malloc. As an example, in
180180This is unnecessary if you set ` CONFIG_GUARD_SLABS_INTERVAL ` to a very large
181181value in the build configuration.
182182
183- On arm64, make sure your kernel is configured to use 4k pages since we haven't
184- yet added support for 16k and 64k pages. The kernel also has to be configured
185- to use 4 level page tables for the full 48 bit address space instead of only
186- having a 39 bit address space for the default hardened\_ malloc configuration.
183+ On arm64, the kernel also has to be configured to use 4 level page tables for
184+ the full 48 bit address space instead of only having a 39 bit address space
185+ for the default hardened\_ malloc configuration.
187186It's possible to reduce the class region size substantially to make a 39 bit
188187address space workable but the defaults won't work.
189188
@@ -334,6 +333,14 @@ The following integer configuration options are available:
334333 granularity. See the [ section on size classes] ( #size-classes ) below for
335334 details.
336335
336+ * ` CONFIG_PAGE_SIZE ` : ` 4096 ` (default) to set the page size used by the
337+ allocator. Supported values are ` 4096 ` and ` 16384 ` . This must match the page
338+ size of the kernel the library will run on. On arm64, kernels may be
339+ configured for 4k or 16k pages. The allocator verifies at runtime that the
340+ compile-time page size matches the kernel page size and will abort if they
341+ differ. The slab slot counts are tuned per page size to minimize internal
342+ fragmentation for slabs.
343+
337344There will be more control over enabled features in the future along with
338345control over fairly arbitrarily chosen values like the size of empty slab
339346caches (making them smaller improves security and reduces memory usage while
@@ -537,11 +544,11 @@ classes for each doubling in size.
537544
538545The slot counts tied to the size classes are specific to this allocator rather
539546than being taken from jemalloc. Slabs are always a span of pages so the slot
540- count needs to be tuned to minimize waste due to rounding to the page size. For
541- now, this allocator is set up only for 4096 byte pages as a small page size is
542- desirable for finer-grained memory protection and randomization. It could be
543- ported to larger page sizes in the future . The current slot counts are only a
544- preliminary set of values .
547+ count needs to be tuned to minimize waste due to rounding to the page size.
548+ Tuned slot counts are provided for 4096 and 16384 byte page sizes, selectable
549+ via ` CONFIG_PAGE_SIZE ` . A smaller page size is desirable for
550+ finer-grained memory protection and randomization . The tables below show the
551+ default slot counts for 4096 byte pages .
545552
546553| size class | worst case internal fragmentation | slab slots | slab size | internal fragmentation for slabs |
547554| - | - | - | - | - |
@@ -584,7 +591,7 @@ preliminary set of values.
584591
585592The slab allocation size classes end at 16384 since that's the final size for
5865932048 byte spacing and the next spacing class matches the page size of 4096
587- bytes on the target platforms . This is the minimum set of small size classes
594+ bytes when using 4k pages . This is the minimum set of small size classes
588595required to avoid substantial waste from rounding.
589596
590597The ` CONFIG_EXTENDED_SIZE_CLASSES ` option extends the size classes up to
@@ -620,8 +627,8 @@ the same size class scheme providing 4 size classes for every doubling of size.
620627It increases virtual memory consumption but drastically improves performance
621628where realloc is used without proper growth factors, which is fairly common and
622629destroys performance in some commonly used programs. If large size classes are
623- disabled, the granularity is instead the page size, which is currently always
624- 4096 bytes on supported platforms .
630+ disabled, the granularity is instead the page size (4096 or 16384 bytes
631+ depending on ` CONFIG_PAGE_SIZE ` ) .
625632
626633## Scalability
627634
0 commit comments