Skip to content

Commit 51f86f7

Browse files
committed
Increase the size of the bitmaps for 16k
The for loop can be unrolled/make use of intrinsics later.
1 parent d903746 commit 51f86f7

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

calculate-waste

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ for size, slots, fragmentation in zip(size_classes, size_class_slots, fragmentat
9797
end=" |\n",
9898
)
9999

100-
max_bits = 256
100+
max_bits = 512
101101
max_page_span = 16
102102

103103
print()
104104

105105
print("maximum bitmap size is {}-bit".format(max_bits))
106-
print( "maximum page span size is {} ({})".format(max_page_span, max_page_span * page_size))
106+
print("maximum page span size is {} ({})".format(max_page_span, max_page_span * page_size))
107107

108108
for size_class in size_classes:
109109
choices = []

h_malloc.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ static bool memory_map_fixed_tagged(void *ptr, size_t size) {
115115
#define SLAB_METADATA_COUNT
116116

117117
struct slab_metadata {
118+
#if CONFIG_PAGE_SIZE == 16384
119+
u64 bitmap[8];
120+
#else
118121
u64 bitmap[4];
122+
#endif
119123
struct slab_metadata *next;
120124
struct slab_metadata *prev;
121125
#if SLAB_CANARY
@@ -125,8 +129,12 @@ struct slab_metadata {
125129
u16 count;
126130
#endif
127131
#if SLAB_QUARANTINE
132+
#if CONFIG_PAGE_SIZE == 16384
133+
u64 quarantine_bitmap[8];
134+
#else
128135
u64 quarantine_bitmap[4];
129-
#endif
136+
#endif /* CONFIG_PAGE_SIZE */
137+
#endif
130138
#ifdef HAS_ARM_MTE
131139
// arm_mte_tags is used as a u4 array (MTE tags are 4-bit wide)
132140
//
@@ -467,20 +475,14 @@ static bool has_free_slots(size_t slots, const struct slab_metadata *metadata) {
467475
#ifdef SLAB_METADATA_COUNT
468476
return metadata->count < slots;
469477
#else
470-
if (slots <= U64_WIDTH) {
471-
u64 masked = metadata->bitmap[0] | get_mask(slots);
472-
return masked != ~0UL;
473-
}
474-
if (slots <= U64_WIDTH * 2) {
475-
u64 masked = metadata->bitmap[1] | get_mask(slots - U64_WIDTH);
476-
return metadata->bitmap[0] != ~0UL || masked != ~0UL;
477-
}
478-
if (slots <= U64_WIDTH * 3) {
479-
u64 masked = metadata->bitmap[2] | get_mask(slots - U64_WIDTH * 2);
480-
return metadata->bitmap[0] != ~0UL || metadata->bitmap[1] != ~0UL || masked != ~0UL;
478+
size_t last = (slots - 1) / U64_WIDTH;
479+
for (size_t i = 0; i < last; i++) {
480+
if (metadata->bitmap[i] != ~0UL) {
481+
return true;
482+
}
481483
}
482-
u64 masked = metadata->bitmap[3] | get_mask(slots - U64_WIDTH * 3);
483-
return metadata->bitmap[0] != ~0UL || metadata->bitmap[1] != ~0UL || metadata->bitmap[2] != ~0UL || masked != ~0UL;
484+
u64 masked = metadata->bitmap[last] | get_mask(slots - last * U64_WIDTH);
485+
return masked != ~0UL;
484486
#endif
485487
}
486488

@@ -489,7 +491,12 @@ static bool is_free_slab(const struct slab_metadata *metadata) {
489491
return !metadata->count;
490492
#else
491493
return !metadata->bitmap[0] && !metadata->bitmap[1] && !metadata->bitmap[2] &&
492-
!metadata->bitmap[3];
494+
!metadata->bitmap[3]
495+
#if CONFIG_PAGE_SIZE == 16384
496+
&& !metadata->bitmap[4] && !metadata->bitmap[5] && !metadata->bitmap[6]
497+
&& !metadata->bitmap[7]
498+
#endif
499+
;
493500
#endif
494501
}
495502

0 commit comments

Comments
 (0)