From 5517e5275f404722ed9999f4c7f761c21d2a5fb4 Mon Sep 17 00:00:00 2001 From: Wesley Shillingford Date: Tue, 11 Jun 2019 09:23:56 +0100 Subject: [PATCH] Disable memory pools when running on Mac (#2067) * Turn off use_memory_pools when using TSAN with mac * Add TSAN check to nano_wallet * Turn off using memory pools on Mac entirely --- nano/core_test/memory_pool.cpp | 6 ++++++ nano/lib/memory.cpp | 23 ++++++++++++++++++++++- nano/lib/memory.hpp | 5 +++-- nano/nano_node/daemon.cpp | 3 +-- nano/nano_wallet/entry.cpp | 1 + nano/rpc_test/entry.cpp | 2 +- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/nano/core_test/memory_pool.cpp b/nano/core_test/memory_pool.cpp index dff49da17..b956bc26d 100644 --- a/nano/core_test/memory_pool.cpp +++ b/nano/core_test/memory_pool.cpp @@ -54,6 +54,12 @@ size_t get_allocated_size () TEST (memory_pool, validate_cleanup) { + // This might be turned off, e.g on Mac for instance, so don't do this test + if (!nano::get_use_memory_pools ()) + { + return; + } + nano::make_shared (); nano::make_shared (); nano::make_shared (); diff --git a/nano/lib/memory.cpp b/nano/lib/memory.cpp index 012566edc..7f0210032 100644 --- a/nano/lib/memory.cpp +++ b/nano/lib/memory.cpp @@ -1,6 +1,27 @@ #include -bool nano::use_memory_pools{ true }; +namespace +{ +#ifdef __APPLE__ +/** TSAN on mac is generating some warnings. They need further investigating before using memory pools can be used, so disable them for now */ +bool use_memory_pools{ false }; +#else +bool use_memory_pools{ true }; +#endif +} + +bool nano::get_use_memory_pools () +{ + return use_memory_pools; +} + +/** This has no effect on Mac */ +void nano::set_use_memory_pools (bool use_memory_pools_a) +{ +#ifndef __APPLE__ + use_memory_pools = use_memory_pools_a; +#endif +} nano::cleanup_guard::cleanup_guard (std::vector> const & cleanup_funcs_a) : cleanup_funcs (cleanup_funcs_a) diff --git a/nano/lib/memory.hpp b/nano/lib/memory.hpp index 7ecda8564..9e11e0884 100644 --- a/nano/lib/memory.hpp +++ b/nano/lib/memory.hpp @@ -8,7 +8,8 @@ namespace nano { -extern bool use_memory_pools; +bool get_use_memory_pools (); +void set_use_memory_pools (bool use_memory_pools); /** This makes some heuristic assumptions about the implementation defined shared_ptr internals. Should only be used in the memory pool purge functions at exit, which doesn't matter much if @@ -46,7 +47,7 @@ private: template std::shared_ptr make_shared (Args &&... args) { - if (nano::use_memory_pools) + if (nano::get_use_memory_pools ()) { return std::allocate_shared (boost::fast_pool_allocator (), std::forward (args)...); } diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index 664d59a74..6ed774914 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -91,8 +91,7 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano:: std::unique_ptr runner; nano::daemon_config config (data_path); auto error = nano::read_and_update_daemon_config (data_path, config); - nano::use_memory_pools = config.node.use_memory_pools; - + nano::set_use_memory_pools (config.node.use_memory_pools); if (!error) { config.node.logging.init (data_path); diff --git a/nano/nano_wallet/entry.cpp b/nano/nano_wallet/entry.cpp index f03cb3bde..cfd6e8d77 100644 --- a/nano/nano_wallet/entry.cpp +++ b/nano/nano_wallet/entry.cpp @@ -237,6 +237,7 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost int result (0); nano::jsonconfig json; auto error (json.read_and_update (config, config_path)); + nano::set_use_memory_pools (config.node.use_memory_pools); nano::set_secure_perm_file (config_path, error_chmod); if (!error) { diff --git a/nano/rpc_test/entry.cpp b/nano/rpc_test/entry.cpp index 2fd0e3362..7eb458259 100644 --- a/nano/rpc_test/entry.cpp +++ b/nano/rpc_test/entry.cpp @@ -11,7 +11,7 @@ void force_nano_test_network (); int main (int argc, char ** argv) { nano::force_nano_test_network (); - nano::use_memory_pools = false; + nano::set_use_memory_pools (false); nano::node_singleton_memory_pool_purge_guard cleanup_guard; testing::InitGoogleTest (&argc, argv); auto res = RUN_ALL_TESTS ();