Skip to content

Commit fd40863

Browse files
committed
Move some structures to cache lines
Prevent some bad sharing of cache lines by aligning some concurrently accessed strucutures.
1 parent 3407347 commit fd40863

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/ds/mpmcstack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace snmalloc
1111
using ABAT = ABA<T, c>;
1212

1313
private:
14-
ABAT stack;
14+
alignas(CACHELINE_SIZE) ABAT stack;
1515

1616
public:
1717
constexpr MPMCStack() = default;

src/mem/chunkallocator.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ namespace snmalloc
7979
ModArray<NUM_SLAB_SIZES, MPMCStack<ChunkRecord, RequiresInit>>
8080
decommitted_chunk_stack;
8181

82+
/**
83+
* Which is the current epoch to place dealloced chunks, and the
84+
* first place we look for allocating chunks.
85+
*/
86+
alignas(CACHELINE_SIZE) std::atomic<size_t> epoch{0};
87+
8288
/**
8389
* All memory issued by this address space manager
8490
*/
@@ -88,12 +94,6 @@ namespace snmalloc
8894

8995
std::atomic<ChunkAllocatorLocalState*> all_local{nullptr};
9096

91-
/**
92-
* Which is the current epoch to place dealloced chunks, and the
93-
* first place we look for allocating chunks.
94-
*/
95-
std::atomic<size_t> epoch{0};
96-
9797
// Flag to ensure one-shot registration with the PAL for notifications.
9898
std::atomic_flag register_decay{};
9999

src/mem/pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ namespace snmalloc
2828
friend class Pool;
2929

3030
private:
31-
std::atomic_flag lock = ATOMIC_FLAG_INIT;
3231
MPMCStack<T, PreZeroed> stack;
32+
std::atomic_flag lock = ATOMIC_FLAG_INIT;
3333
T* list{nullptr};
3434

3535
public:

0 commit comments

Comments
 (0)