diff --git a/flex/CMakeLists.txt b/flex/CMakeLists.txt index 94ff4e5ed9b3..6cd561409883 100644 --- a/flex/CMakeLists.txt +++ b/flex/CMakeLists.txt @@ -15,7 +15,6 @@ option(BUILD_TEST "Whether to build test" ON) option(BUILD_DOC "Whether to build doc" ON) option(BUILD_ODPS_FRAGMENT_LOADER "Whether to build odps fragment loader" ON) option(MONITOR_SESSIONS "Whether monitor sessions" OFF) -option(ENABLE_HUGEPAGE "Whether to use hugepages when open mmap array in memory" OFF) #print options message(STATUS "Build HighQPS Engine: ${BUILD_HQPS}") @@ -49,12 +48,6 @@ if (MONITOR_SESSIONS) add_definitions(-DMONITOR_SESSIONS) endif () - -if (ENABLE_HUGEPAGE) - message("Hugepage is enabled") - add_definitions(-DHUGEPAGE) -endif () - execute_process(COMMAND uname -r OUTPUT_VARIABLE LINUX_KERNEL_VERSION) string(STRIP ${LINUX_KERNEL_VERSION} LINUX_KERNEL_VERSION) message(${LINUX_KERNEL_VERSION}) diff --git a/flex/bin/rt_server.cc b/flex/bin/rt_server.cc index e30a6238f1c3..11b23aab3ffd 100644 --- a/flex/bin/rt_server.cc +++ b/flex/bin/rt_server.cc @@ -38,8 +38,8 @@ int main(int argc, char** argv) { "graph schema config file")( "data-path,d", bpo::value(), "data directory path")( "warmup,w", bpo::value()->default_value(false), - "warmup graph data")("memory-only,m", - bpo::value()->default_value(true)); + "warmup graph data")("memory-level,m", + bpo::value()->default_value(1)); google::InitGoogleLogging(argv[0]); FLAGS_logtostderr = true; @@ -58,7 +58,7 @@ int main(int argc, char** argv) { bool enable_dpdk = false; bool warmup = vm["warmup"].as(); - bool memory_only = vm["memory-only"].as(); + int memory_level = vm["memory-level"].as(); uint32_t shard_num = vm["shard-num"].as(); uint16_t http_port = vm["http-port"].as(); @@ -84,17 +84,7 @@ int main(int argc, char** argv) { auto schema = gs::Schema::LoadFromYaml(graph_schema_path); gs::GraphDBConfig config(schema, data_path, shard_num); -#ifdef HUGEPAGE - config.allocator_strategy = gs::MemoryStrategy::kHugepagePrefered; - config.vertex_map_strategy = gs::MemoryStrategy::kHugepagePrefered; - config.vertex_table_strategy = gs::MemoryStrategy::kHugepagePrefered; - config.topology_strategy = gs::MemoryStrategy::kHugepagePrefered; -#else - config.allocator_strategy = gs::MemoryStrategy::kMemoryOnly; - config.vertex_map_strategy = gs::MemoryStrategy::kMemoryOnly; - config.vertex_table_strategy = gs::MemoryStrategy::kMemoryOnly; - config.topology_strategy = gs::MemoryStrategy::kMemoryOnly; -#endif + config.memory_level = memory_level; config.enable_auto_compaction = true; config.service_port = http_port; db.Open(config); diff --git a/flex/engines/graph_db/database/graph_db.cc b/flex/engines/graph_db/database/graph_db.cc index 3136562e0020..42a455202e3c 100644 --- a/flex/engines/graph_db/database/graph_db.cc +++ b/flex/engines/graph_db/database/graph_db.cc @@ -66,15 +66,9 @@ Result GraphDB::Open(const Schema& schema, const std::string& data_dir, GraphDBConfig config(schema, data_dir, thread_num); config.warmup = warmup; if (memory_only) { - config.allocator_strategy = MemoryStrategy::kMemoryOnly; - config.topology_strategy = MemoryStrategy::kMemoryOnly; - config.vertex_map_strategy = MemoryStrategy::kMemoryOnly; - config.vertex_table_strategy = MemoryStrategy::kMemoryOnly; + config.memory_level = 1; } else { - config.allocator_strategy = MemoryStrategy::kSyncToFile; - config.topology_strategy = MemoryStrategy::kSyncToFile; - config.vertex_map_strategy = MemoryStrategy::kSyncToFile; - config.vertex_table_strategy = MemoryStrategy::kSyncToFile; + config.memory_level = 0; } config.enable_auto_compaction = enable_auto_compaction; config.service_port = port; @@ -97,8 +91,7 @@ Result GraphDB::Open(const GraphDBConfig& config) { work_dir_ = data_dir; thread_num_ = config.thread_num; try { - graph_.Open(data_dir, config.vertex_map_strategy, - config.vertex_table_strategy, config.topology_strategy); + graph_.Open(data_dir, config.memory_level); } catch (std::exception& e) { LOG(ERROR) << "Exception: " << e.what(); return Result(StatusCode::InternalError, @@ -129,7 +122,14 @@ Result GraphDB::Open(const GraphDBConfig& config) { mutable_schema.EmplacePlugins(plugin_paths); last_compaction_ts_ = 0; - openWalAndCreateContexts(data_dir, config.allocator_strategy); + MemoryStrategy allocator_strategy = MemoryStrategy::kMemoryOnly; + if (config.memory_level == 0) { + allocator_strategy = MemoryStrategy::kSyncToFile; + } else if (config.memory_level >= 2) { + allocator_strategy = MemoryStrategy::kHugepagePrefered; + } + + openWalAndCreateContexts(data_dir, allocator_strategy); if ((!create_empty_graph) && config.warmup) { graph_.Warmup(thread_num_); diff --git a/flex/engines/graph_db/database/graph_db.h b/flex/engines/graph_db/database/graph_db.h index c91d224e4ba0..b7e3415b6210 100644 --- a/flex/engines/graph_db/database/graph_db.h +++ b/flex/engines/graph_db/database/graph_db.h @@ -49,10 +49,7 @@ struct GraphDBConfig { warmup(false), enable_auto_compaction(false), service_port(-1), - vertex_map_strategy(MemoryStrategy::kMemoryOnly), - vertex_table_strategy(MemoryStrategy::kMemoryOnly), - topology_strategy(MemoryStrategy::kMemoryOnly), - allocator_strategy(MemoryStrategy::kMemoryOnly) {} + memory_level(1) {} Schema schema; std::string data_dir; @@ -60,10 +57,14 @@ struct GraphDBConfig { bool warmup; bool enable_auto_compaction; int service_port; - MemoryStrategy vertex_map_strategy; - MemoryStrategy vertex_table_strategy; - MemoryStrategy topology_strategy; - MemoryStrategy allocator_strategy; + + /* + 0 - sync with disk; + 1 - mmap virtual memory; + 2 - prefering hugepages; + 3 - force hugepages; + */ + int memory_level; }; class GraphDB { diff --git a/flex/storages/rt_mutable_graph/dual_csr.h b/flex/storages/rt_mutable_graph/dual_csr.h index 6ccd18f965e4..a2eea20ab9d6 100644 --- a/flex/storages/rt_mutable_graph/dual_csr.h +++ b/flex/storages/rt_mutable_graph/dual_csr.h @@ -42,14 +42,12 @@ class DualCsrBase { const std::string& edata_name, const std::string& snapshot_dir, size_t src_vertex_cap, size_t dst_vertex_cap) = 0; -#ifdef HUGEPAGE virtual void OpenWithHugepages(const std::string& oe_name, const std::string& ie_name, const std::string& edata_name, const std::string& snapshot_dir, size_t src_vertex_cap, size_t dst_vertex_cap) = 0; -#endif virtual void Dump(const std::string& oe_name, const std::string& ie_name, const std::string& edata_name, const std::string& new_snapshot_dir) = 0; @@ -120,7 +118,6 @@ class DualCsr : public DualCsrBase { out_csr_->open_in_memory(snapshot_dir + "/" + oe_name, src_vertex_cap); } -#ifdef HUGEPAGE void OpenWithHugepages(const std::string& oe_name, const std::string& ie_name, const std::string& edata_name, const std::string& snapshot_dir, size_t src_vertex_cap, @@ -128,7 +125,6 @@ class DualCsr : public DualCsrBase { in_csr_->open_with_hugepages(snapshot_dir + "/" + ie_name, dst_vertex_cap); out_csr_->open_with_hugepages(snapshot_dir + "/" + oe_name, src_vertex_cap); } -#endif void Dump(const std::string& oe_name, const std::string& ie_name, const std::string& edata_name, @@ -261,14 +257,12 @@ class DualCsr : public DualCsrBase { column_.resize(std::max(column_.size() + (column_.size() + 4) / 5, 4096ul)); } -#ifdef HUGEPAGE void OpenWithHugepages(const std::string& oe_name, const std::string& ie_name, const std::string& edata_name, const std::string& snapshot_dir, size_t src_vertex_cap, size_t dst_vertex_cap) override { LOG(FATAL) << "not supported..."; } -#endif void Dump(const std::string& oe_name, const std::string& ie_name, const std::string& edata_name, diff --git a/flex/storages/rt_mutable_graph/mutable_csr.h b/flex/storages/rt_mutable_graph/mutable_csr.h index 6999fe903651..ef5271deb965 100644 --- a/flex/storages/rt_mutable_graph/mutable_csr.h +++ b/flex/storages/rt_mutable_graph/mutable_csr.h @@ -501,12 +501,10 @@ class MutableCsrBase { const std::string& work_dir) = 0; virtual void open_in_memory(const std::string& prefix, size_t v_cap = 0) = 0; -#ifdef HUGEPAGE virtual void open_with_hugepages(const std::string& prefix, size_t v_cap = 0) { LOG(FATAL) << "not supported..."; } -#endif virtual void dump(const std::string& name, const std::string& new_spanshot_dir) = 0; @@ -768,7 +766,6 @@ class MutableCsr : public TypedMutableCsrBase { } } -#ifdef HUGEPAGE void open_with_hugepages(const std::string& prefix, size_t v_cap) override { mmap_array degree_list; degree_list.open(prefix + ".deg", false); @@ -802,7 +799,6 @@ class MutableCsr : public TypedMutableCsrBase { delete cap_list; } } -#endif void warmup(int thread_num) const override { size_t vnum = adj_lists_.size(); @@ -1282,7 +1278,6 @@ class SingleMutableCsr : public TypedMutableCsrBase { } } -#ifdef HUGEPAGE void open_with_hugepages(const std::string& prefix, size_t v_cap) override { nbr_list_.open_with_hugepages(prefix + ".snbr", v_cap); size_t old_size = nbr_list_.size(); @@ -1293,7 +1288,6 @@ class SingleMutableCsr : public TypedMutableCsrBase { } } } -#endif void dump(const std::string& name, const std::string& new_snapshot_dir) override { @@ -1640,9 +1634,7 @@ class EmptyCsr : public TypedMutableCsrBase { void open_in_memory(const std::string& prefix, size_t v_cap) override {} -#ifdef HUGEPAGE void open_with_hugepages(const std::string& prefix, size_t v_cap) override {} -#endif void dump(const std::string& name, const std::string& new_spanshot_dir) override {} diff --git a/flex/storages/rt_mutable_graph/mutable_property_fragment.cc b/flex/storages/rt_mutable_graph/mutable_property_fragment.cc index 7c9df49eca39..3c0b0b4a3737 100644 --- a/flex/storages/rt_mutable_graph/mutable_property_fragment.cc +++ b/flex/storages/rt_mutable_graph/mutable_property_fragment.cc @@ -112,15 +112,7 @@ inline DualCsrBase* create_csr(EdgeStrategy oes, EdgeStrategy ies, } void MutablePropertyFragment::Open(const std::string& work_dir, - bool memory_only) { - Open(work_dir, MemoryStrategy::kMemoryOnly, MemoryStrategy::kMemoryOnly, - MemoryStrategy::kMemoryOnly); -} - -void MutablePropertyFragment::Open(const std::string& work_dir, - MemoryStrategy vertex_map_strategy, - MemoryStrategy vertex_table_strategy, - MemoryStrategy topology_strategy) { + int memory_level) { std::string schema_file = schema_path(work_dir); std::string snapshot_dir{}; bool build_empty_graph = false; @@ -153,46 +145,44 @@ void MutablePropertyFragment::Open(const std::string& work_dir, for (size_t i = 0; i < vertex_label_num_; ++i) { std::string v_label_name = schema_.get_vertex_label_name(i); - if (vertex_map_strategy == MemoryStrategy::kMemoryOnly) { - lf_indexers_[i].open_in_memory(snapshot_dir + "/" + - vertex_map_prefix(v_label_name)); -#ifdef HUGEPAGE - } else if (vertex_map_strategy == MemoryStrategy::kHugepagePrefered) { - lf_indexers_[i].open_with_hugepages(snapshot_dir + "/" + - vertex_map_prefix(v_label_name)); -#endif - } else { - assert(vertex_map_strategy == MemoryStrategy::kSyncToFile); + if (memory_level == 0) { lf_indexers_[i].open(vertex_map_prefix(v_label_name), snapshot_dir, tmp_dir_path); - } - - if (vertex_table_strategy == MemoryStrategy::kMemoryOnly) { + vertex_data_[i].open(vertex_table_prefix(v_label_name), snapshot_dir, + tmp_dir_path, schema_.get_vertex_property_names(i), + schema_.get_vertex_properties(i), + schema_.get_vertex_storage_strategies(v_label_name)); + if (!build_empty_graph) { + vertex_data_[i].copy_to_tmp(vertex_table_prefix(v_label_name), + snapshot_dir, tmp_dir_path); + } + } else if (memory_level == 1) { + lf_indexers_[i].open_in_memory(snapshot_dir + "/" + + vertex_map_prefix(v_label_name)); vertex_data_[i].open_in_memory( vertex_table_prefix(v_label_name), snapshot_dir, schema_.get_vertex_property_names(i), schema_.get_vertex_properties(i), schema_.get_vertex_storage_strategies(v_label_name)); -#ifdef HUGEPAGE - } else if (vertex_table_strategy == MemoryStrategy::kHugepagePrefered) { + } else if (memory_level == 2) { + lf_indexers_[i].open_with_hugepages( + snapshot_dir + "/" + vertex_map_prefix(v_label_name), false); vertex_data_[i].open_with_hugepages( vertex_table_prefix(v_label_name), snapshot_dir, schema_.get_vertex_property_names(i), schema_.get_vertex_properties(i), - schema_.get_vertex_storage_strategies(v_label_name)); -#endif + schema_.get_vertex_storage_strategies(v_label_name), false); } else { - assert(vertex_table_strategy == MemoryStrategy::kSyncToFile); - vertex_data_[i].open(vertex_table_prefix(v_label_name), snapshot_dir, - tmp_dir_path, schema_.get_vertex_property_names(i), - schema_.get_vertex_properties(i), - schema_.get_vertex_storage_strategies(v_label_name)); - } - if (!build_empty_graph && - (vertex_table_strategy == MemoryStrategy::kSyncToFile)) { - vertex_data_[i].copy_to_tmp(vertex_table_prefix(v_label_name), - snapshot_dir, tmp_dir_path); + assert(memory_level == 3); + lf_indexers_[i].open_with_hugepages( + snapshot_dir + "/" + vertex_map_prefix(v_label_name), true); + vertex_data_[i].open_with_hugepages( + vertex_table_prefix(v_label_name), snapshot_dir, + schema_.get_vertex_property_names(i), + schema_.get_vertex_properties(i), + schema_.get_vertex_storage_strategies(v_label_name), true); } + size_t vertex_capacity = schema_.get_max_vnum(v_label_name); // lf_indexers_[i].capacity(); if (build_empty_graph) { @@ -236,27 +226,24 @@ void MutablePropertyFragment::Open(const std::string& work_dir, create_csr(oe_strategy, ie_strategy, properties); ie_[index] = dual_csr_list_[index]->GetInCsr(); oe_[index] = dual_csr_list_[index]->GetOutCsr(); - if (topology_strategy == MemoryStrategy::kMemoryOnly) { - dual_csr_list_[index]->OpenInMemory( + if (memory_level == 0) { + dual_csr_list_[index]->Open( oe_prefix(src_label, dst_label, edge_label), ie_prefix(src_label, dst_label, edge_label), edata_prefix(src_label, dst_label, edge_label), snapshot_dir, - vertex_capacities[src_label_i], vertex_capacities[dst_label_i]); -#ifdef HUGEPAGE - } else if (topology_strategy == MemoryStrategy::kHugepagePrefered) { + tmp_dir_path); + } else if (memory_level >= 2) { dual_csr_list_[index]->OpenWithHugepages( oe_prefix(src_label, dst_label, edge_label), ie_prefix(src_label, dst_label, edge_label), edata_prefix(src_label, dst_label, edge_label), snapshot_dir, vertex_capacities[src_label_i], vertex_capacities[dst_label_i]); -#endif } else { - assert(topology_strategy == MemoryStrategy::kSyncToFile); - dual_csr_list_[index]->Open( + dual_csr_list_[index]->OpenInMemory( oe_prefix(src_label, dst_label, edge_label), ie_prefix(src_label, dst_label, edge_label), edata_prefix(src_label, dst_label, edge_label), snapshot_dir, - tmp_dir_path); + vertex_capacities[src_label_i], vertex_capacities[dst_label_i]); } ie_[index]->resize(vertex_capacities[dst_label_i]); oe_[index]->resize(vertex_capacities[src_label_i]); diff --git a/flex/storages/rt_mutable_graph/mutable_property_fragment.h b/flex/storages/rt_mutable_graph/mutable_property_fragment.h index 86d139c63841..f15b0864f49b 100644 --- a/flex/storages/rt_mutable_graph/mutable_property_fragment.h +++ b/flex/storages/rt_mutable_graph/mutable_property_fragment.h @@ -48,11 +48,7 @@ class MutablePropertyFragment { vid_t dst_lid, label_t edge_label, timestamp_t ts, const Any& arc, Allocator& alloc); - void Open(const std::string& work_dir, bool memory_only); - - void Open(const std::string& work_dir, MemoryStrategy vertex_map_strategy, - MemoryStrategy vertex_table_strategy, - MemoryStrategy topology_strategy); + void Open(const std::string& work_dir, int memory_level); void Compact(uint32_t version); diff --git a/flex/utils/allocators.h b/flex/utils/allocators.h index b55d5d756587..00a436c4dfe4 100644 --- a/flex/utils/allocators.h +++ b/flex/utils/allocators.h @@ -27,18 +27,16 @@ namespace gs { class ArenaAllocator { - static constexpr size_t batch_size = 128 * 1024 * 1024; + static constexpr size_t batch_size = 16 * 1024 * 1024; public: ArenaAllocator(MemoryStrategy strategy, const std::string& prefix) : strategy_(strategy), prefix_(prefix), cur_loc_(0), - cur_size_(0) -#ifdef MONITOR_SESSIONS - , - allocated_memory_(0) -#endif + cur_size_(0), + allocated_memory_(0), + allocated_batches_(0) { if (strategy_ != MemoryStrategy::kSyncToFile) { prefix_.clear(); @@ -61,9 +59,7 @@ class ArenaAllocator { } void* allocate(size_t size) { -#ifdef MONITOR_SESSIONS allocated_memory_ += size; -#endif if (cur_size_ - cur_loc_ >= size) { void* ret = (char*) cur_buffer_ + cur_loc_; cur_loc_ += size; @@ -79,23 +75,18 @@ class ArenaAllocator { } } -#ifdef MONITOR_SESSIONS size_t allocated_memory() const { return allocated_memory_; } -#endif private: void* allocate_batch(size_t size) { + allocated_batches_ += size; if (prefix_.empty()) { mmap_array* buf = new mmap_array(); -#ifdef HUGEPAGE if (strategy_ == MemoryStrategy::kHugepagePrefered) { buf->open_with_hugepages("", size); } else { buf->open("", false); } -#else - buf->open("", false); -#endif buf->resize(size); mmap_buffers_.push_back(buf); return static_cast(buf->data()); @@ -116,9 +107,8 @@ class ArenaAllocator { size_t cur_loc_; size_t cur_size_; -#ifdef MONITOR_SESSIONS size_t allocated_memory_; -#endif + size_t allocated_batches_; }; using Allocator = ArenaAllocator; diff --git a/flex/utils/id_indexer.h b/flex/utils/id_indexer.h index 16e35ddd0c99..8d6a3dd22879 100644 --- a/flex/utils/id_indexer.h +++ b/flex/utils/id_indexer.h @@ -384,20 +384,22 @@ class LFIndexer { keys_->resize(num_elements + (num_elements >> 2)); } -#ifdef HUGEPAGE - void open_with_hugepages(const std::string& name) { + void open_with_hugepages(const std::string& name, bool hugepage_table) { if (std::filesystem::exists(name + ".meta")) { load_meta(name + ".meta"); } else { num_elements_.store(0); } - keys_->open_with_hugepages(name + ".keys"); - indices_.open_with_hugepages(name + ".indices"); + keys_->open_with_hugepages(name + ".keys", true); + if (hugepage_table) { + indices_.open_with_hugepages(name + ".indices"); + } else { + indices_.open(name + ".indices", false); + } indices_size_ = indices_.size(); size_t num_elements = num_elements_.load(); keys_->resize(num_elements + (num_elements >> 2)); } -#endif void dump(const std::string& name, const std::string& snapshot_dir) { keys_->resize(num_elements_.load()); diff --git a/flex/utils/mmap_array.h b/flex/utils/mmap_array.h index 26729c266fb9..6742f993e718 100644 --- a/flex/utils/mmap_array.h +++ b/flex/utils/mmap_array.h @@ -27,8 +27,6 @@ #include "glog/logging.h" #include "grape/util.h" -#ifdef HUGEPAGE - #ifdef __ia64__ #define ADDR (void*) (0x8000000000000000UL) #define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_FIXED) @@ -55,16 +53,12 @@ inline size_t hugepage_round_up(size_t size) { return ROUND_UP(size); } #undef HUGEPAGE_MASK #undef ROUND_UP -#endif - namespace gs { enum class MemoryStrategy { kSyncToFile, kMemoryOnly, -#ifdef HUGEPAGE kHugepagePrefered, -#endif }; template @@ -76,11 +70,8 @@ class mmap_array { data_(NULL), size_(0), mmap_size_(0), - sync_to_file_(false) -#ifdef HUGEPAGE - , + sync_to_file_(false), hugepage_prefered_(false) -#endif { } mmap_array(mmap_array&& rhs) : mmap_array() { swap(rhs); } @@ -101,19 +92,15 @@ class mmap_array { sync_to_file_ = false; } -#ifdef HUGEPAGE void set_hugepage_prefered(bool val) { hugepage_prefered_ = (val && !sync_to_file_); } -#endif void open(const std::string& filename, bool sync_to_file = false) { reset(); filename_ = filename; sync_to_file_ = sync_to_file; -#ifdef HUGEPAGE hugepage_prefered_ = false; -#endif if (sync_to_file_) { bool creat = !std::filesystem::exists(filename_); fd_ = ::open(filename_.c_str(), O_RDWR | O_CREAT, 0777); @@ -169,7 +156,6 @@ class mmap_array { } } -#ifdef HUGEPAGE void open_with_hugepages(const std::string& filename, size_t capacity = 0) { reset(); hugepage_prefered_ = true; @@ -183,6 +169,7 @@ class mmap_array { if (data_ != MAP_FAILED) { FILE* fin = fopen(filename.c_str(), "rb"); CHECK_EQ(fread(data_, sizeof(T), size_, fin), size_); + fclose(fin); } else { LOG(ERROR) << "allocating hugepage failed, " << strerror(errno) << ", try with normal pages"; @@ -193,7 +180,6 @@ class mmap_array { } } } -#endif void dump(const std::string& filename) { if (sync_to_file_) { @@ -252,7 +238,6 @@ class mmap_array { } else { T* new_data = NULL; size_t new_mmap_size = size * sizeof(T); -#ifdef HUGEPAGE if (hugepage_prefered_) { new_data = reinterpret_cast(allocate_hugepages(new_mmap_size)); if (new_data == MAP_FAILED) { @@ -263,7 +248,6 @@ class mmap_array { new_mmap_size = hugepage_round_up(new_mmap_size); } } -#endif if (new_data == NULL) { new_data = reinterpret_cast( mmap(NULL, new_mmap_size, PROT_READ | PROT_WRITE, @@ -311,9 +295,7 @@ class mmap_array { std::swap(data_, rhs.data_); std::swap(size_, rhs.size_); std::swap(mmap_size_, rhs.mmap_size_); -#ifdef HUGEPAGE std::swap(hugepage_prefered_, rhs.hugepage_prefered_); -#endif } const std::string& filename() const { return filename_; } @@ -327,9 +309,7 @@ class mmap_array { size_t mmap_size_; bool sync_to_file_; -#ifdef HUGEPAGE bool hugepage_prefered_; -#endif }; struct string_item { @@ -349,24 +329,20 @@ class mmap_array { data_.reset(); } -#ifdef HUGEPAGE void set_hugepage_prefered(bool val) { items_.set_hugepage_prefered(val); data_.set_hugepage_prefered(val); } -#endif void open(const std::string& filename, bool sync_to_file) { items_.open(filename + ".items", sync_to_file); data_.open(filename + ".data", sync_to_file); } -#ifdef HUGEPAGE void open_with_hugepages(const std::string& filename) { items_.open_with_hugepages(filename + ".items"); data_.open_with_hugepages(filename + ".data"); } -#endif void touch(const std::string& filename) { items_.touch(filename + ".items"); diff --git a/flex/utils/property/column.cc b/flex/utils/property/column.cc index 8a40ef32dec5..b746255e01d0 100644 --- a/flex/utils/property/column.cc +++ b/flex/utils/property/column.cc @@ -30,9 +30,7 @@ class TypedEmptyColumn : public ColumnBase { void open(const std::string& name, const std::string& snapshot_dir, const std::string& work_dir) override {} void open_in_memory(const std::string& name) override {} -#ifdef HUGEPAGE - void open_with_hugepages(const std::string& name) override {} -#endif + void open_with_hugepages(const std::string& name, bool force) override {} void touch(const std::string& filename) override {} void dump(const std::string& filename) override {} void copy_to_tmp(const std::string& cur_path, @@ -71,9 +69,7 @@ class TypedEmptyColumn : public ColumnBase { void open(const std::string& name, const std::string& snapshot_dir, const std::string& work_dir) override {} void open_in_memory(const std::string& name) override {} -#ifdef HUGEPAGE - void open_with_hugepages(const std::string& name) override {} -#endif + void open_with_hugepages(const std::string& name, bool force) override {} void touch(const std::string& filename) override {} void dump(const std::string& filename) override {} void copy_to_tmp(const std::string& cur_path, diff --git a/flex/utils/property/column.h b/flex/utils/property/column.h index 7fda849a8db4..8977e04b1158 100644 --- a/flex/utils/property/column.h +++ b/flex/utils/property/column.h @@ -34,9 +34,7 @@ class ColumnBase { virtual void open_in_memory(const std::string& name) = 0; -#ifdef HUGEPAGE - virtual void open_with_hugepages(const std::string& name) = 0; -#endif + virtual void open_with_hugepages(const std::string& name, bool force) = 0; virtual void close() = 0; @@ -96,9 +94,8 @@ class TypedColumn : public ColumnBase { extra_size_ = 0; } -#ifdef HUGEPAGE - void open_with_hugepages(const std::string& name) override { - if (strategy_ == StorageStrategy::kMem) { + void open_with_hugepages(const std::string& name, bool force) override { + if (strategy_ == StorageStrategy::kMem || force) { if (!name.empty() && std::filesystem::exists(name)) { basic_buffer_.open_with_hugepages(name); basic_size_ = basic_buffer_.size(); @@ -111,10 +108,10 @@ class TypedColumn : public ColumnBase { extra_buffer_.set_hugepage_prefered(true); extra_size_ = 0; } else if (strategy_ == StorageStrategy::kDisk) { + LOG(INFO) << "Open " << name << " with normal mmap pages"; open_in_memory(name); } } -#endif void touch(const std::string& filename) override { mmap_array tmp; @@ -270,9 +267,8 @@ class TypedColumn : public ColumnBase { pos_.store(0); } -#ifdef HUGEPAGE - void open_with_hugepages(const std::string& prefix) override { - if (strategy_ == StorageStrategy::kMem) { + void open_with_hugepages(const std::string& prefix, bool force) override { + if (strategy_ == StorageStrategy::kMem || force) { basic_buffer_.open_with_hugepages(prefix); basic_size_ = basic_buffer_.size(); @@ -281,10 +277,10 @@ class TypedColumn : public ColumnBase { extra_size_ = 0; pos_.store(0); } else if (strategy_ == StorageStrategy::kDisk) { + LOG(INFO) << "Open " << prefix << " with normal mmap pages"; open_in_memory(prefix); } } -#endif void touch(const std::string& filename) override { mmap_array tmp; @@ -370,7 +366,6 @@ class TypedColumn : public ColumnBase { } else { basic_size_ = basic_buffer_.size(); extra_size_ = size - basic_size_; -#ifdef HUGEPAGE if (basic_buffer_.size() != 0) { size_t basic_avg_width = (basic_buffer_.data_size() + basic_buffer_.size() - 1) / @@ -379,9 +374,6 @@ class TypedColumn : public ColumnBase { } else { extra_buffer_.resize(extra_size_, extra_size_ * width_); } -#else - extra_buffer_.resize(extra_size_, extra_size_ * width_); -#endif } } @@ -465,9 +457,7 @@ class StringMapColumn : public ColumnBase { void open(const std::string& name, const std::string& snapshot_dir, const std::string& work_dir) override; void open_in_memory(const std::string& name) override; -#ifdef HUGEPAGE - void open_with_hugepages(const std::string& name) override; -#endif + void open_with_hugepages(const std::string& name, bool force) override; void dump(const std::string& filename) override; void touch(const std::string& filename) override { @@ -532,14 +522,13 @@ void StringMapColumn::open_in_memory(const std::string& name) { meta_map_->reserve(std::numeric_limits::max()); } -#ifdef HUGEPAGE template -void StringMapColumn::open_with_hugepages(const std::string& name) { - index_col_.open_with_hugepages(name); - meta_map_->open_with_hugepages(name + ".map_meta"); +void StringMapColumn::open_with_hugepages(const std::string& name, + bool force) { + index_col_.open_with_hugepages(name, force); + meta_map_->open_with_hugepages(name + ".map_meta", true); meta_map_->reserve(std::numeric_limits::max()); } -#endif template void StringMapColumn::dump(const std::string& filename) { diff --git a/flex/utils/property/table.cc b/flex/utils/property/table.cc index 228392534455..bcdb4c660b2d 100644 --- a/flex/utils/property/table.cc +++ b/flex/utils/property/table.cc @@ -77,21 +77,19 @@ void Table::open_in_memory(const std::string& name, buildColumnPtrs(); } -#ifdef HUGEPAGE void Table::open_with_hugepages( const std::string& name, const std::string& snapshot_dir, const std::vector& col_name, const std::vector& property_types, - const std::vector& strategies_) { + const std::vector& strategies_, bool force) { initColumns(col_name, property_types, strategies_); for (size_t i = 0; i < columns_.size(); ++i) { columns_[i]->open_with_hugepages(snapshot_dir + "/" + name + ".col_" + - std::to_string(i)); + std::to_string(i), force); } touched_ = true; buildColumnPtrs(); } -#endif void Table::touch(const std::string& name, const std::string& work_dir) { if (touched_) { diff --git a/flex/utils/property/table.h b/flex/utils/property/table.h index db9fa33ecae6..99a6e6ccb752 100644 --- a/flex/utils/property/table.h +++ b/flex/utils/property/table.h @@ -48,13 +48,11 @@ class Table { const std::vector& property_types, const std::vector& strategies_); -#ifdef HUGEPAGE void open_with_hugepages(const std::string& name, const std::string& snapshot_dir, const std::vector& col_name, const std::vector& property_types, - const std::vector& strategies_); -#endif + const std::vector& strategies_, bool force); void touch(const std::string& name, const std::string& work_dir);