Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions include/metall/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

// --------------------
Expand Down
12 changes: 11 additions & 1 deletion include/metall/kernel/object_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down