diff --git a/include/metall/defs.hpp b/include/metall/defs.hpp index f8385e72..3def4969 100644 --- a/include/metall/defs.hpp +++ b/include/metall/defs.hpp @@ -64,31 +64,60 @@ #define METALL_DISABLE_FREE_FILE_SPACE #endif +// -------------------- +// Macros for the segment allocator +// -------------------- + +#ifdef DOXYGEN_SKIP +/// \brief If defined, disable concurrency support. +/// \details +/// If this macro is defined, Metall disables concurrency support and optimizes +/// the internal behavior for single-thread usage. Applications must not call +/// any Metall functions concurrently if this macro is defined. On the other +/// hand, Metall still may use multi-threading for internal operations, such +/// as synchronizing data with files. +#define METALL_DISABLE_CONCURRENCY +#endif + // -------------------- // Macros for the object cache // -------------------- -/// \def METALL_MAX_PER_CPU_CACHE_SIZE -/// The maximum size of the per CPU (logical CPU core) cache in bytes. -#ifndef METALL_MAX_PER_CPU_CACHE_SIZE -#define METALL_MAX_PER_CPU_CACHE_SIZE (1ULL << 20ULL) +#ifdef DOXYGEN_SKIP +/// \brief If defined, Metall disables the object cache feature. +#define METALL_DISABLE_OBJECT_CACHE +#endif + +/// \def METALL_NUM_OBJECT_CACHES +/// The total number of object caches. If this macro is defined, +/// its value must be greater than 0. +#ifdef DOXYGEN_SKIP +#define METALL_NUM_OBJECT_CACHES 2 +#endif + +#if defined(METALL_NUM_OBJECT_CACHES) && METALL_NUM_OBJECT_CACHES <= 0 +#warning "METALL_NUM_OBJECT_CACHES must be > 0. This value is ignored." +#undef METALL_NUM_OBJECT_CACHES #endif /// \def METALL_NUM_CACHES_PER_CPU /// The number of caches per CPU (logical CPU core). +/// This value must be greater than 0. +/// This macro is ignored if METALL_NUM_OBJECT_CACHES is defined. #ifndef METALL_NUM_CACHES_PER_CPU #define METALL_NUM_CACHES_PER_CPU 2 #endif -#ifdef DOXYGEN_SKIP -/// \brief A macro to disable concurrency support. -/// \details -/// If this macro is defined, Metall disables concurrency support and optimizes -/// the internal behavior for single-thread usage. Applications must not call -/// any Metall functions concurrently if this macro is defined. On the other -/// hand, Metall still may use multi-threading for internal operations, such -/// as synchronizing data with files. -#define METALL_DISABLE_CONCURRENCY +#if METALL_NUM_CACHES_PER_CPU <= 0 +#warning "METALL_NUM_CACHES_PER_CPU must be > 0." +#undef METALL_NUM_CACHES_PER_CPU +#define METALL_NUM_CACHES_PER_CPU 2 +#endif + +/// \def METALL_MAX_PER_CPU_CACHE_SIZE +/// The maximum size of the per CPU (logical CPU core) cache in bytes. +#ifndef METALL_MAX_PER_CPU_CACHE_SIZE +#define METALL_MAX_PER_CPU_CACHE_SIZE (1ULL << 20ULL) #endif // -------------------- diff --git a/include/metall/kernel/object_cache.hpp b/include/metall/kernel/object_cache.hpp index 6547e548..f53f1e6e 100644 --- a/include/metall/kernel/object_cache.hpp +++ b/include/metall/kernel/object_cache.hpp @@ -446,7 +446,7 @@ class object_cache { } explicit object_cache() - : m_num_caches(priv_get_num_cpus() * k_num_caches_per_cpu) + : m_num_caches(priv_get_num_cahes()) #ifdef METALL_ENABLE_MUTEX_IN_OBJECT_CACHE , m_mutex(m_num_caches) @@ -544,6 +544,16 @@ class object_cache { return mdtl::get_num_cpus(); } + /// Calculate the number of caches to be used. + inline static unsigned int priv_get_num_cahes() { +#ifdef METALL_NUM_OBJECT_CACHES + if (METALL_NUM_OBJECT_CACHES > 0) { + return METALL_NUM_OBJECT_CACHES; + } +#endif + return priv_get_num_cpus() * k_num_caches_per_cpu; + } + inline size_type priv_cache_no() const { #ifdef METALL_DISABLE_CONCURRENCY return 0;