Skip to content

Commit 968a7e6

Browse files
authored
Merge pull request swiftlang#40915 from mikeash/slab-allocation-size-fix
[Concurrency] Adjust the task allocator slab size to 984 bytes.
2 parents 45aeca8 + 17ac269 commit 968a7e6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,11 @@ class alignas(sizeof(void*) * 2) ActiveTaskStatus {
284284
}
285285
};
286286

287-
/// The size of an allocator slab.
288-
static constexpr size_t SlabCapacity = 1000;
287+
/// The size of an allocator slab. We want the full allocation to fit into a
288+
/// 1024-byte malloc quantum. We subtract off the slab header size, plus a
289+
/// little extra to stay within our limits even when there's overhead from
290+
/// malloc stack logging.
291+
static constexpr size_t SlabCapacity = 1024 - StackAllocator<0, nullptr>::slabHeaderSize() - 8;
289292
extern Metadata TaskAllocatorSlabMetadata;
290293

291294
using TaskAllocator = StackAllocator<SlabCapacity, &TaskAllocatorSlabMetadata>;

stdlib/public/runtime/StackAllocator.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class StackAllocator {
109109
}
110110

111111
/// The size of the slab header.
112-
static size_t headerSize() {
113-
return llvm::alignTo(sizeof(Slab), llvm::Align(alignment));
112+
static constexpr size_t headerSize() {
113+
return (sizeof(Slab) + alignment - 1) & ~(alignment - 1);
114114
}
115115

116116
/// Return \p size with the added overhead of the slab header.
@@ -276,6 +276,10 @@ class StackAllocator {
276276
assert(getNumAllocatedSlabs() == 0);
277277
}
278278

279+
static constexpr size_t slabHeaderSize() {
280+
return Slab::headerSize();
281+
}
282+
279283
/// Allocate a memory buffer of \p size.
280284
void *alloc(size_t size) {
281285
if (guardAllocations)

0 commit comments

Comments
 (0)