From c751974ae0dc8a077af6b6f6860a45d669c9dd97 Mon Sep 17 00:00:00 2001 From: Kozlowski Mateusz Date: Fri, 12 Mar 2021 15:28:57 +0100 Subject: [PATCH] Allocator structures cacheline alignment Align atomic fields to a different cacheline, so no false sharing between CPUs occur. Signed-off-by: Kozlowski Mateusz --- modules/cas_cache/ocf_env.c | 12 ++++++------ modules/cas_cache/utils/utils_rpool.c | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/cas_cache/ocf_env.c b/modules/cas_cache/ocf_env.c index e4c55b1..f627873 100644 --- a/modules/cas_cache/ocf_env.c +++ b/modules/cas_cache/ocf_env.c @@ -14,16 +14,16 @@ struct _env_allocator { /*!< Memory pool ID unique name */ char *name; - /*!< Size of specific item of memory pool */ - uint32_t item_size; - /*!< OS handle to memory pool */ struct kmem_cache *kmem_cache; - /*!< Number of currently allocated items in pool */ - atomic_t count; - struct cas_reserve_pool *rpool; + + /*!< Size of specific item of memory pool */ + uint32_t item_size; + + /*!< Number of currently allocated items in pool */ + atomic_t count __attribute__((aligned(64))); }; static inline size_t env_allocator_align(size_t size) diff --git a/modules/cas_cache/utils/utils_rpool.c b/modules/cas_cache/utils/utils_rpool.c index 7da026d..085b21c 100644 --- a/modules/cas_cache/utils/utils_rpool.c +++ b/modules/cas_cache/utils/utils_rpool.c @@ -25,11 +25,17 @@ #define CAS_DEBUG_PARAM(format, ...) #endif +/* This is currently 24B padded/force aligned to 32B. + * With a 64B cacheline this means two structs on different cores may + * invalidate each other. This shouldn't happen between different physical + * CPUs and cause false sharing though, since with an even number of cores + * per CPU same cacheline shouldn't be polluted from the other physical CPU. + * */ struct _cas_reserve_pool_per_cpu { spinlock_t lock; struct list_head list; atomic_t count; -}; +} __attribute__((__aligned__(32))); struct cas_reserve_pool { uint32_t limit;