From fd408637a7a172d260f38c73667323148439a09e Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 28 Oct 2021 14:23:15 +0100 Subject: [PATCH] Move some structures to cache lines Prevent some bad sharing of cache lines by aligning some concurrently accessed strucutures. --- src/ds/mpmcstack.h | 2 +- src/mem/chunkallocator.h | 12 ++++++------ src/mem/pool.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ds/mpmcstack.h b/src/ds/mpmcstack.h index d7a4f92..b701c05 100644 --- a/src/ds/mpmcstack.h +++ b/src/ds/mpmcstack.h @@ -11,7 +11,7 @@ namespace snmalloc using ABAT = ABA; private: - ABAT stack; + alignas(CACHELINE_SIZE) ABAT stack; public: constexpr MPMCStack() = default; diff --git a/src/mem/chunkallocator.h b/src/mem/chunkallocator.h index 0a8e41e..286d7d0 100644 --- a/src/mem/chunkallocator.h +++ b/src/mem/chunkallocator.h @@ -79,6 +79,12 @@ namespace snmalloc ModArray> decommitted_chunk_stack; + /** + * Which is the current epoch to place dealloced chunks, and the + * first place we look for allocating chunks. + */ + alignas(CACHELINE_SIZE) std::atomic epoch{0}; + /** * All memory issued by this address space manager */ @@ -88,12 +94,6 @@ namespace snmalloc std::atomic all_local{nullptr}; - /** - * Which is the current epoch to place dealloced chunks, and the - * first place we look for allocating chunks. - */ - std::atomic epoch{0}; - // Flag to ensure one-shot registration with the PAL for notifications. std::atomic_flag register_decay{}; diff --git a/src/mem/pool.h b/src/mem/pool.h index 0c470c7..c773e89 100644 --- a/src/mem/pool.h +++ b/src/mem/pool.h @@ -28,8 +28,8 @@ namespace snmalloc friend class Pool; private: - std::atomic_flag lock = ATOMIC_FLAG_INIT; MPMCStack stack; + std::atomic_flag lock = ATOMIC_FLAG_INIT; T* list{nullptr}; public: