Skip to content

Add support for 16k pages#290

Open
jvoisin wants to merge 2 commits intoGrapheneOS:mainfrom
jvoisin:16k
Open

Add support for 16k pages#290
jvoisin wants to merge 2 commits intoGrapheneOS:mainfrom
jvoisin:16k

Conversation

@jvoisin
Copy link
Copy Markdown
Contributor

@jvoisin jvoisin commented Mar 16, 2026

With 16384 pages:

size class worst case internal fragmentation slab slots slab size internal fragmentation for slabs
16 93.75% 256 16384 75.0%
32 46.88% 256 16384 50.0%
48 31.25% 256 16384 25.0%
64 23.44% 256 16384 0.0%
80 18.75% 204 16384 0.390625%
96 15.62% 170 16384 0.390625%
112 13.39% 146 16384 0.1953125%
128 11.72% 256 32768 0.0%
160 19.38% 204 32768 0.390625%
192 16.15% 256 49152 0.0%
224 13.84% 219 49152 0.1953125%
256 12.11% 256 65536 0.0%
320 19.69% 256 81920 0.0%
384 16.41% 256 98304 0.0%
448 14.06% 256 114688 0.0%
512 12.3% 256 131072 0.0%
640 19.84% 256 163840 0.0%
768 16.54% 256 196608 0.0%
896 14.17% 256 229376 0.0%
1024 12.4% 256 262144 0.0%
1280 19.92% 192 245760 0.0%
1536 16.6% 160 245760 0.0%
1792 14.23% 128 229376 0.0%
2048 12.45% 128 262144 0.0%
2560 19.96% 96 245760 0.0%
3072 16.63% 80 245760 0.0%
3584 14.26% 64 229376 0.0%
4096 12.48% 64 262144 0.0%
5120 19.98% 48 245760 0.0%
6144 16.65% 40 245760 0.0%
7168 14.27% 32 229376 0.0%
8192 12.49% 32 262144 0.0%
10240 19.99% 24 245760 0.0%
12288 16.66% 20 245760 0.0%
14336 14.28% 16 229376 0.0%
16384 12.49% 16 262144 0.0%
20480 20.0% 12 245760 0.0%
24576 16.66% 10 245760 0.0%
28672 14.28% 8 229376 0.0%
32768 12.5% 8 262144 0.0%
40960 20.0% 6 245760 0.0%
49152 16.66% 5 245760 0.0%
57344 14.28% 4 229376 0.0%
65536 12.5% 4 262144 0.0%
81920 20.0% 3 245760 0.0%
98304 16.67% 2 196608 0.0%
114688 14.28% 2 229376 0.0%
131072 12.5% 2 262144 0.0%

maximum bitmap size is 256-bit
maximum page span size is 16 (262144)

with 4k to compare:

size class worst case internal fragmentation slab slots slab size internal fragmentation for slabs
16 93.75% 256 4096 0.0%
32 46.88% 128 4096 0.0%
48 31.25% 85 4096 0.390625%
64 23.44% 64 4096 0.0%
80 18.75% 51 4096 0.390625%
96 15.62% 42 4096 1.5625%
112 13.39% 36 4096 1.5625%
128 11.72% 64 8192 0.0%
160 19.38% 51 8192 0.390625%
192 16.15% 64 12288 0.0%
224 13.84% 54 12288 1.5625%
256 12.11% 64 16384 0.0%
320 19.69% 64 20480 0.0%
384 16.41% 64 24576 0.0%
448 14.06% 64 28672 0.0%
512 12.3% 64 32768 0.0%
640 19.84% 64 40960 0.0%
768 16.54% 64 49152 0.0%
896 14.17% 64 57344 0.0%
1024 12.4% 64 65536 0.0%
1280 19.92% 16 20480 0.0%
1536 16.6% 16 24576 0.0%
1792 14.23% 16 28672 0.0%
2048 12.45% 16 32768 0.0%
2560 19.96% 8 20480 0.0%
3072 16.63% 8 24576 0.0%
3584 14.26% 8 28672 0.0%
4096 12.48% 8 32768 0.0%
5120 19.98% 8 40960 0.0%
6144 16.65% 8 49152 0.0%
7168 14.27% 8 57344 0.0%
8192 12.49% 8 65536 0.0%
10240 19.99% 6 61440 0.0%
12288 16.66% 5 61440 0.0%
14336 14.28% 4 57344 0.0%
16384 12.49% 4 65536 0.0%
20480 20.0% 2 40960 0.0%
24576 16.66% 2 49152 0.0%
28672 14.28% 2 57344 0.0%
32768 12.5% 2 65536 0.0%
40960 20.0% 1 40960 0.0%
49152 16.66% 1 49152 0.0%
57344 14.28% 1 57344 0.0%
65536 12.5% 1 65536 0.0%
81920 20.0% 1 81920 0.0%
98304 16.67% 1 98304 0.0%
114688 14.28% 1 114688 0.0%
131072 12.5% 1 131072 0.0%

maximum bitmap size is 256-bit
maximum page span size is 16 (65536)

This implements #213

@jvoisin
Copy link
Copy Markdown
Contributor Author

jvoisin commented Mar 16, 2026

This makes the testsuite pass on my local arm64 16k-pages test machine with make CONFIG_PAGE_SIZE=16384 clean test

@thestinger
Copy link
Copy Markdown
Member

This is okay as an initial implementation but it really needs to be improved by having a larger or multi-level bitmap for handling the smallest sizes.

@jvoisin
Copy link
Copy Markdown
Contributor Author

jvoisin commented Mar 16, 2026

Yup, that's clearly a first step in the right direction, but nowhere near a complete proper implementation. I simply wanted to have the tests to work on my main machine :P

@jvoisin jvoisin marked this pull request as ready for review March 16, 2026 19:33
@jvoisin
Copy link
Copy Markdown
Contributor Author

jvoisin commented Mar 20, 2026

I don't think I'm comfortable enough with the codebase to implement multi-level bitmap in a nice way :/

@thestinger
Copy link
Copy Markdown
Member

@jvoisin It could also just be a long bitmap with SIMD or something.

jvoisin added 2 commits March 25, 2026 16:40
With 16384 pages:

| size class | worst case internal fragmentation | slab slots | slab size | internal fragmentation for slabs |
| - | - | - | - | - |
| 16 | 93.75% | 256 | 16384 | 75.0% |
| 32 | 46.88% | 256 | 16384 | 50.0% |
| 48 | 31.25% | 256 | 16384 | 25.0% |
| 64 | 23.44% | 256 | 16384 | 0.0% |
| 80 | 18.75% | 204 | 16384 | 0.390625% |
| 96 | 15.62% | 170 | 16384 | 0.390625% |
| 112 | 13.39% | 146 | 16384 | 0.1953125% |
| 128 | 11.72% | 256 | 32768 | 0.0% |
| 160 | 19.38% | 204 | 32768 | 0.390625% |
| 192 | 16.15% | 256 | 49152 | 0.0% |
| 224 | 13.84% | 219 | 49152 | 0.1953125% |
| 256 | 12.11% | 256 | 65536 | 0.0% |
| 320 | 19.69% | 256 | 81920 | 0.0% |
| 384 | 16.41% | 256 | 98304 | 0.0% |
| 448 | 14.06% | 256 | 114688 | 0.0% |
| 512 | 12.3% | 256 | 131072 | 0.0% |
| 640 | 19.84% | 256 | 163840 | 0.0% |
| 768 | 16.54% | 256 | 196608 | 0.0% |
| 896 | 14.17% | 256 | 229376 | 0.0% |
| 1024 | 12.4% | 256 | 262144 | 0.0% |
| 1280 | 19.92% | 192 | 245760 | 0.0% |
| 1536 | 16.6% | 160 | 245760 | 0.0% |
| 1792 | 14.23% | 128 | 229376 | 0.0% |
| 2048 | 12.45% | 128 | 262144 | 0.0% |
| 2560 | 19.96% | 96 | 245760 | 0.0% |
| 3072 | 16.63% | 80 | 245760 | 0.0% |
| 3584 | 14.26% | 64 | 229376 | 0.0% |
| 4096 | 12.48% | 64 | 262144 | 0.0% |
| 5120 | 19.98% | 48 | 245760 | 0.0% |
| 6144 | 16.65% | 40 | 245760 | 0.0% |
| 7168 | 14.27% | 32 | 229376 | 0.0% |
| 8192 | 12.49% | 32 | 262144 | 0.0% |
| 10240 | 19.99% | 24 | 245760 | 0.0% |
| 12288 | 16.66% | 20 | 245760 | 0.0% |
| 14336 | 14.28% | 16 | 229376 | 0.0% |
| 16384 | 12.49% | 16 | 262144 | 0.0% |
| 20480 | 20.0% | 12 | 245760 | 0.0% |
| 24576 | 16.66% | 10 | 245760 | 0.0% |
| 28672 | 14.28% | 8 | 229376 | 0.0% |
| 32768 | 12.5% | 8 | 262144 | 0.0% |
| 40960 | 20.0% | 6 | 245760 | 0.0% |
| 49152 | 16.66% | 5 | 245760 | 0.0% |
| 57344 | 14.28% | 4 | 229376 | 0.0% |
| 65536 | 12.5% | 4 | 262144 | 0.0% |
| 81920 | 20.0% | 3 | 245760 | 0.0% |
| 98304 | 16.67% | 2 | 196608 | 0.0% |
| 114688 | 14.28% | 2 | 229376 | 0.0% |
| 131072 | 12.5% | 2 | 262144 | 0.0% |

maximum bitmap size is 256-bit
maximum page span size is 16 (262144)

with 4k to compare:

| size class | worst case internal fragmentation | slab slots | slab size | internal fragmentation for slabs |
| - | - | - | - | - |
| 16 | 93.75% | 256 | 4096 | 0.0% |
| 32 | 46.88% | 128 | 4096 | 0.0% |
| 48 | 31.25% | 85 | 4096 | 0.390625% |
| 64 | 23.44% | 64 | 4096 | 0.0% |
| 80 | 18.75% | 51 | 4096 | 0.390625% |
| 96 | 15.62% | 42 | 4096 | 1.5625% |
| 112 | 13.39% | 36 | 4096 | 1.5625% |
| 128 | 11.72% | 64 | 8192 | 0.0% |
| 160 | 19.38% | 51 | 8192 | 0.390625% |
| 192 | 16.15% | 64 | 12288 | 0.0% |
| 224 | 13.84% | 54 | 12288 | 1.5625% |
| 256 | 12.11% | 64 | 16384 | 0.0% |
| 320 | 19.69% | 64 | 20480 | 0.0% |
| 384 | 16.41% | 64 | 24576 | 0.0% |
| 448 | 14.06% | 64 | 28672 | 0.0% |
| 512 | 12.3% | 64 | 32768 | 0.0% |
| 640 | 19.84% | 64 | 40960 | 0.0% |
| 768 | 16.54% | 64 | 49152 | 0.0% |
| 896 | 14.17% | 64 | 57344 | 0.0% |
| 1024 | 12.4% | 64 | 65536 | 0.0% |
| 1280 | 19.92% | 16 | 20480 | 0.0% |
| 1536 | 16.6% | 16 | 24576 | 0.0% |
| 1792 | 14.23% | 16 | 28672 | 0.0% |
| 2048 | 12.45% | 16 | 32768 | 0.0% |
| 2560 | 19.96% | 8 | 20480 | 0.0% |
| 3072 | 16.63% | 8 | 24576 | 0.0% |
| 3584 | 14.26% | 8 | 28672 | 0.0% |
| 4096 | 12.48% | 8 | 32768 | 0.0% |
| 5120 | 19.98% | 8 | 40960 | 0.0% |
| 6144 | 16.65% | 8 | 49152 | 0.0% |
| 7168 | 14.27% | 8 | 57344 | 0.0% |
| 8192 | 12.49% | 8 | 65536 | 0.0% |
| 10240 | 19.99% | 6 | 61440 | 0.0% |
| 12288 | 16.66% | 5 | 61440 | 0.0% |
| 14336 | 14.28% | 4 | 57344 | 0.0% |
| 16384 | 12.49% | 4 | 65536 | 0.0% |
| 20480 | 20.0% | 2 | 40960 | 0.0% |
| 24576 | 16.66% | 2 | 49152 | 0.0% |
| 28672 | 14.28% | 2 | 57344 | 0.0% |
| 32768 | 12.5% | 2 | 65536 | 0.0% |
| 40960 | 20.0% | 1 | 40960 | 0.0% |
| 49152 | 16.66% | 1 | 49152 | 0.0% |
| 57344 | 14.28% | 1 | 57344 | 0.0% |
| 65536 | 12.5% | 1 | 65536 | 0.0% |
| 81920 | 20.0% | 1 | 81920 | 0.0% |
| 98304 | 16.67% | 1 | 98304 | 0.0% |
| 114688 | 14.28% | 1 | 114688 | 0.0% |
| 131072 | 12.5% | 1 | 131072 | 0.0% |

maximum bitmap size is 256-bit
maximum page span size is 16 (65536)
The for loop can be unrolled/make use of intrinsics later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants