Skip to content

Commit 1083429

Browse files
committed
Increase the size of the bitmaps
The for loop can be unrolled/make use of intrinsics later.
1 parent 1e53bc1 commit 1083429

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

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: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static bool memory_map_fixed_tagged(void *ptr, size_t size) {
115115
#define SLAB_METADATA_COUNT
116116

117117
struct slab_metadata {
118-
u64 bitmap[4];
118+
u64 bitmap[8];
119119
struct slab_metadata *next;
120120
struct slab_metadata *prev;
121121
#if SLAB_CANARY
@@ -125,19 +125,19 @@ struct slab_metadata {
125125
u16 count;
126126
#endif
127127
#if SLAB_QUARANTINE
128-
u64 quarantine_bitmap[4];
128+
u64 quarantine_bitmap[8];
129129
#endif
130130
#ifdef HAS_ARM_MTE
131131
// arm_mte_tags is used as a u4 array (MTE tags are 4-bit wide)
132132
//
133133
// Its size is calculated by the following formula:
134134
// (MAX_SLAB_SLOT_COUNT + 2) / 2
135-
// MAX_SLAB_SLOT_COUNT is currently 256, 2 extra slots are needed for branchless handling of
135+
// MAX_SLAB_SLOT_COUNT is currently 512, 2 extra slots are needed for branchless handling of
136136
// edge slots in tag_and_clear_slab_slot()
137137
//
138138
// It's intentionally placed at the end of struct to improve locality: for most size classes,
139139
// slot count is far lower than MAX_SLAB_SLOT_COUNT.
140-
u8 arm_mte_tags[129];
140+
u8 arm_mte_tags[257];
141141
#endif
142142
};
143143

@@ -460,20 +460,14 @@ static bool has_free_slots(size_t slots, const struct slab_metadata *metadata) {
460460
#ifdef SLAB_METADATA_COUNT
461461
return metadata->count < slots;
462462
#else
463-
if (slots <= U64_WIDTH) {
464-
u64 masked = metadata->bitmap[0] | get_mask(slots);
465-
return masked != ~0UL;
466-
}
467-
if (slots <= U64_WIDTH * 2) {
468-
u64 masked = metadata->bitmap[1] | get_mask(slots - U64_WIDTH);
469-
return metadata->bitmap[0] != ~0UL || masked != ~0UL;
470-
}
471-
if (slots <= U64_WIDTH * 3) {
472-
u64 masked = metadata->bitmap[2] | get_mask(slots - U64_WIDTH * 2);
473-
return metadata->bitmap[0] != ~0UL || metadata->bitmap[1] != ~0UL || masked != ~0UL;
463+
size_t last = (slots - 1) / U64_WIDTH;
464+
for (size_t i = 0; i < last; i++) {
465+
if (metadata->bitmap[i] != ~0UL) {
466+
return true;
467+
}
474468
}
475-
u64 masked = metadata->bitmap[3] | get_mask(slots - U64_WIDTH * 3);
476-
return metadata->bitmap[0] != ~0UL || metadata->bitmap[1] != ~0UL || metadata->bitmap[2] != ~0UL || masked != ~0UL;
469+
u64 masked = metadata->bitmap[last] | get_mask(slots - last * U64_WIDTH);
470+
return masked != ~0UL;
477471
#endif
478472
}
479473

@@ -482,7 +476,8 @@ static bool is_free_slab(const struct slab_metadata *metadata) {
482476
return !metadata->count;
483477
#else
484478
return !metadata->bitmap[0] && !metadata->bitmap[1] && !metadata->bitmap[2] &&
485-
!metadata->bitmap[3];
479+
!metadata->bitmap[3] && !metadata->bitmap[4] && !metadata->bitmap[5] &&
480+
!metadata->bitmap[6] && !metadata->bitmap[7];
486481
#endif
487482
}
488483

0 commit comments

Comments
 (0)