Skip to content

Commit

Permalink
Merge pull request #295 from LLNL/feature/optimize_cache
Browse files Browse the repository at this point in the history
Feature/optimize cache
  • Loading branch information
KIwabuchi authored Nov 1, 2023
2 parents 5efc9b6 + e65f6b8 commit a2225e5
Show file tree
Hide file tree
Showing 9 changed files with 956 additions and 419 deletions.
3 changes: 2 additions & 1 deletion bench/adjacency_list/test/test_large.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ a=0.57
b=0.19
c=0.19
seed=123
e=$((2**$((${v}+4)))) # The number of edges to generate

# The default path to store data.
# This value is overwritten if '-d' option is specified
Expand Down Expand Up @@ -78,6 +77,8 @@ main() {
ref_edge_dump_file1="${out_dir_path}/ref_edge_list1"
ref_edge_dump_file2="${out_dir_path}/ref_edge_list2"

local e=$((2**$((${v}+4)))) # The number of edges to generate

./run_adj_list_bench_metall -o ${data_store_path} -d ${adj_list_dump_file} -s ${seed} -v ${v} -e ${e} -a ${a} -b ${b} -c ${c} -r 1 -u 1 -D ${ref_edge_dump_file1}
check_program_exit_status
echo ""
Expand Down
36 changes: 2 additions & 34 deletions docs/readthedocs/basics/compile_time_options.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,4 @@
# Compile-Time Options

There are some compile-time options (C/C++ macro) as follows to configure the behavior of Metall:

- METALL_DEFAULT_CAPACITY=*bytes*
- The default capacity of a segment/datastore.
- This value is used when a user does not specify the capacity of a datastore when creating it.

- METALL_VERBOSE_SYSTEM_SUPPORT_WARNING
- If defined, Metall shows warning messages at compile time if the system does not support important features.

- METALL_DISABLE_CONCURRENCY
- Disable concurrency support in Metall. This option is useful when Metall is used in a single-threaded application.
- If this macro is defined, applications must not call Metall concurrently from multiple threads.
- Even if this option is enabled, Metall still uses multiple threads for background tasks, such as synchronizing segment files.

- METALL_USE_SORTED_BIN
- If defined, Metall stores addresses in sorted order in the bin directory.
- This option enables Metall to use memory space more efficiently, but it increases the cost of the bin directory operations.

- METALL_FREE_SMALL_OBJECT_SIZE_HINT=*bytes*
- If defined, Metall tries to free space when an object equal to or larger than the specified bytes is deallocated.
- Will be rounded up to a multiple of the page size internally.


**Macros for the segment storage manager:**

- METALL_SEGMENT_BLOCK_SIZE=*bytes*
- The segment block size.
- Metall allocates a backing file with this size.

- METALL_DISABLE_FREE_FILE_SPACE
- If defined, Metall does not free file space.

- METALL_USE_ANONYMOUS_NEW_MAP
- If defined, Metall uses anonymous memory mapping instead of file mapping when creating a new map region.
There are some compile-time options (C/C++ macro) to configure the behavior of Metall.
Those macros are defined in `metall/include/metall/defs.hpp`.
72 changes: 59 additions & 13 deletions include/metall/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
/// \def METALL_MAX_CAPACITY
/// The max capacity, i.e., the maximum total memory size a single Metall
/// datastore can allocate. This value is a theoretical limit, and the actual
/// limit is smaller than this value.
/// limit is smaller than this value. This value is used to determine the types
/// of some internal variables.
#ifndef METALL_MAX_CAPACITY
#define METALL_MAX_CAPACITY (1ULL << 48ULL)
#endif

#ifdef METALL_MAX_SEGMENT_SIZE
#warning \
"METALL_MAX_SEGMENT_SIZE is deprecated. Use METALL_MAX_CAPACITY instead."
#define METALL_MAX_CAPACITY (1ULL << 47ULL)
#endif

/// \def METALL_DEFAULT_CAPACITY
Expand All @@ -36,20 +32,52 @@
#endif
#endif

#ifdef METALL_DEFAULT_VM_RESERVE_SIZE
#warning \
"METALL_DEFAULT_VM_RESERVE_SIZE is deprecated. Use METALL_DEFAULT_CAPACITY instead."
#ifdef DOXYGEN_SKIP
/// \brief If defined, Metall shows warning messages at compile time if the
/// system does not support important features.
#define METALL_VERBOSE_SYSTEM_SUPPORT_WARNING

/// \brief If defined, Metall stores addresses in sorted order in the bin
/// directory. This option enables Metall to use memory space more efficiently,
/// but it increases the cost of the bin directory operations.
#define METALL_USE_SORTED_BIN

/// \brief If defined, Metall tries to free space when an object equal to or
/// larger than the specified bytes is deallocated. Will be rounded up to a
/// multiple of the page size internally.
#define METALL_FREE_SMALL_OBJECT_SIZE_HINT
#endif

// --------------------
// Macros for the default segment storage manager
// --------------------

/// \def METALL_SEGMENT_BLOCK_SIZE
/// The segment block size the default segment storage use.
#ifndef METALL_SEGMENT_BLOCK_SIZE
#define METALL_SEGMENT_BLOCK_SIZE (1ULL << 28ULL)
#endif

#ifdef METALL_INITIAL_SEGMENT_SIZE
#warning \
"METALL_INITIAL_SEGMENT_SIZE is deprecated. Use METALL_SEGMENT_BLOCK_SIZE instead."
#ifdef DOXYGEN_SKIP
/// \brief If defined, the default segment storage does not free file space even
/// thought the corresponding segment becomes free.
#define METALL_DISABLE_FREE_FILE_SPACE
#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)
#endif

/// \def METALL_NUM_CACHES_PER_CPU
/// The number of caches per CPU (logical CPU core).
#ifndef METALL_NUM_CACHES_PER_CPU
#define METALL_NUM_CACHES_PER_CPU 2
#endif

#ifdef DOXYGEN_SKIP
Expand All @@ -63,4 +91,22 @@
#define METALL_DISABLE_CONCURRENCY
#endif

// --------------------
// Deprecated macros

#ifdef METALL_MAX_SEGMENT_SIZE
#warning \
"METALL_MAX_SEGMENT_SIZE is deprecated. Use METALL_MAX_CAPACITY instead."
#endif

#ifdef METALL_DEFAULT_VM_RESERVE_SIZE
#warning \
"METALL_DEFAULT_VM_RESERVE_SIZE is deprecated. Use METALL_DEFAULT_CAPACITY instead."
#endif

#ifdef METALL_INITIAL_SEGMENT_SIZE
#warning \
"METALL_INITIAL_SEGMENT_SIZE is deprecated. Use METALL_SEGMENT_BLOCK_SIZE instead."
#endif

#endif // METALL_DEFS_HPP
29 changes: 21 additions & 8 deletions include/metall/detail/proc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@

#include <sched.h>

namespace metall::mtlldetail {
#ifdef _GNU_SOURCE
#define SUPPORT_GET_CPU_CORE_NO true
#include <sys/sysinfo.h>
#define SUPPORT_GET_CPU_NO true
#else
#define SUPPORT_GET_CPU_CORE_NO false
#define SUPPORT_GET_CPU_NO false
#endif

/// \brief Returns the number of the CPU core on which the calling thread is
/// currently executing \return Returns a non-negative CPU core number
inline int get_cpu_core_no() {
#if SUPPORT_GET_CPU_CORE_NO
#include <thread>

namespace metall::mtlldetail {

/// \brief Returns the number of the logical CPU core on which the calling
/// thread is currently executing.
inline unsigned int get_cpu_no() {
#if SUPPORT_GET_CPU_NO

const int cpu = ::sched_getcpu();
if (cpu == -1) {
Expand All @@ -29,12 +33,21 @@ inline int get_cpu_core_no() {
#else

#ifdef METALL_VERBOSE_SYSTEM_SUPPORT_WARNING
#warning "CPU core number is always 0"
#warning "CPU number is always 0"
#endif
return 0;

#endif
}

/// \brief Returns the number of the logical CPU cores on the system.
inline unsigned int get_num_cpus() {
#if SUPPORT_GET_CPU_NO
return ::get_nprocs_conf();
#else
return std::thread::hardware_concurrency();
#endif
}

} // namespace metall::mtlldetail
#endif // METALL_DETAIL_UTILITY_PROC_HPP
Loading

0 comments on commit a2225e5

Please sign in to comment.