Skip to content

Commit

Permalink
Disable memory pools when running on Mac (#2067)
Browse files Browse the repository at this point in the history
* Turn off use_memory_pools when using TSAN with mac

* Add TSAN check to nano_wallet

* Turn off using memory pools on Mac entirely
  • Loading branch information
wezrule authored and Russel Waters committed Jun 11, 2019
1 parent d2e2eaf commit b892b69
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
6 changes: 6 additions & 0 deletions nano/core_test/memory_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::open_block> ();
nano::make_shared<nano::receive_block> ();
nano::make_shared<nano::send_block> ();
Expand Down
23 changes: 22 additions & 1 deletion nano/lib/memory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
#include <nano/lib/memory.hpp>

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<std::function<void()>> const & cleanup_funcs_a) :
cleanup_funcs (cleanup_funcs_a)
Expand Down
5 changes: 3 additions & 2 deletions nano/lib/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,7 +47,7 @@ class cleanup_guard final
template <typename T, typename... Args>
std::shared_ptr<T> make_shared (Args &&... args)
{
if (nano::use_memory_pools)
if (nano::get_use_memory_pools ())
{
return std::allocate_shared<T> (boost::fast_pool_allocator<T> (), std::forward<Args> (args)...);
}
Expand Down
3 changes: 1 addition & 2 deletions nano/nano_node/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano::
std::unique_ptr<nano::thread_runner> 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);
Expand Down
1 change: 1 addition & 0 deletions nano/nano_wallet/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion nano/rpc_test/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down

0 comments on commit b892b69

Please sign in to comment.