Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

utils: periodically memory release of tcmalloc #278

Merged
merged 34 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1f06eca
provide the settings of tcmalloc release rate
andylin-hao Jul 8, 2019
d42a3a5
add periodic memory release
andylin-hao Jul 9, 2019
a9f4442
add periodic memory release
andylin-hao Jul 9, 2019
99cd9f8
minor changes on periodic memory release
andylin-hao Jul 11, 2019
78f5d58
Merge branch 'master' into mem_release
Jul 11, 2019
e08df0a
clang formatting
andylin-hao Jul 12, 2019
e918422
Merge branch 'mem_release' of https://github.com/linlinhaohao888/rdsn…
andylin-hao Jul 12, 2019
f201e46
fix clang-format
andylin-hao Jul 15, 2019
296210a
fix clang-format
andylin-hao Jul 15, 2019
26f4d37
fix clang-format
andylin-hao Jul 15, 2019
63c7931
tcmalloc: add delay time configuration
andylin-hao Jul 15, 2019
f25e26b
fix clang-format
andylin-hao Jul 15, 2019
f699d4c
rdsn: fix MallocExtension does not exist when gperf is disable
andylin-hao Jul 15, 2019
628b7e7
rdsn: fix MallocExtension does not exist when gperf is disabled
andylin-hao Jul 15, 2019
d6c0f3a
fix clang-format
andylin-hao Jul 15, 2019
66580a4
rdsn: add configuration for memory release's related parameters
andylin-hao Jul 15, 2019
1b86ccf
shift the declaration of LPC_MEM_RELEASE
andylin-hao Jul 15, 2019
b07698b
change the memory release's interval time for testing
andylin-hao Jul 16, 2019
b3ef104
Merge branch 'master' into mem_release
qinzuoyan Jul 16, 2019
bb6801d
Merge branch 'master' into mem_release
Jul 22, 2019
6282fbc
fix file privileges
andylin-hao Jul 22, 2019
a372af2
Merge branch 'mem_release' of https://github.com/linlinhaohao888/rdsn…
andylin-hao Jul 22, 2019
c7c54f7
rdsn: change default value of memory release's interval
andylin-hao Jul 22, 2019
3f6bf31
Merge branch 'master' into mem_release
qinzuoyan Jul 22, 2019
4b5f430
rdsn: get logging rid of "\n"
andylin-hao Jul 22, 2019
341fa60
rdsn: remove delay time of memory release
andylin-hao Jul 22, 2019
3f11c0c
rdsn: remove cpu profiler test code
andylin-hao Jul 22, 2019
2ccea50
rdsn: add task cancelling
andylin-hao Jul 22, 2019
345935f
rdsn: remove delay time's declaration
andylin-hao Jul 22, 2019
842a7d0
rdsn: add macro for gperftools' include
andylin-hao Jul 22, 2019
c5fc5dd
fix clang format
andylin-hao Jul 23, 2019
f5e5d84
rdsn: add macro for gperftools' include
andylin-hao Jul 23, 2019
ab3ade5
Merge branch 'master' into mem_release
qinzuoyan Jul 23, 2019
5dcc507
add logging in test
qinzuoyan Jul 24, 2019
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
1 change: 1 addition & 0 deletions include/dsn/dist/replication/replication.codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ MAKE_EVENT_CODE_AIO(LPC_WRITE_REPLICATION_LOG_COMMON, TASK_PRIORITY_HIGH)
MAKE_EVENT_CODE_AIO(LPC_WRITE_REPLICATION_LOG_PRIVATE, TASK_PRIORITY_HIGH)
MAKE_EVENT_CODE_AIO(LPC_WRITE_REPLICATION_LOG_SHARED, TASK_PRIORITY_HIGH)
MAKE_EVENT_CODE(LPC_QUERY_CONFIGURATION_ALL, TASK_PRIORITY_HIGH)
MAKE_EVENT_CODE(LPC_MEM_RELEASE, TASK_PRIORITY_COMMON)
#undef CURRENT_THREAD_POOL

// THREAD_POOL_META_SERVER
Expand Down
13 changes: 13 additions & 0 deletions src/core/core/service_api_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include <dsn/utility/process_utils.h>
#include <dsn/tool-api/command_manager.h>
#include <fstream>
#ifdef DSN_ENABLE_GPERF
#include <gperftools/malloc_extension.h>
#endif

#include "service_engine.h"
#include "rpc_engine.h"
Expand Down Expand Up @@ -381,6 +384,16 @@ bool run(const char *config_file,
"thread local transient memory buffer size (KB), default is 1024");
::dsn::tls_trans_mem_init(tls_trans_memory_KB * 1024);

#ifdef DSN_ENABLE_GPERF
double_t tcmalloc_release_rate =
(double_t)dsn_config_get_value_double("core",
"tcmalloc_release_rate",
1., // [0, 10]
"the memory releasing rate of tcmalloc, default is "
"1.0 in gperftools, value range is 0.0~10.0");
::MallocExtension::instance()->SetMemoryReleaseRate(tcmalloc_release_rate);
#endif

// prepare minimum necessary
::dsn::service_engine::instance().init_before_toollets(spec);

Expand Down
2 changes: 2 additions & 0 deletions src/dist/http/pprof_http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <dsn/utility/timer.h>
#include <dsn/utility/string_splitter.h>
#include <gperftools/malloc_extension.h>
#include <gperftools/profiler.h>

namespace dsn {

Expand Down Expand Up @@ -334,6 +335,7 @@ static bool get_heap_profile(std::string &result)
void pprof_http_service::heap_handler(const http_request &req, http_response &resp)
{
resp.status_code = http_status_code::ok;

get_heap_profile(resp.body);
}

Expand Down
14 changes: 14 additions & 0 deletions src/dist/replication/common/replication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ replication_options::replication_options()
config_sync_disabled = false;
config_sync_interval_ms = 30000;

mem_release_enabled = true;
mem_release_interval_ms = 86400000;

lb_interval_ms = 10000;

learn_app_max_concurrent_count = 5;
Expand Down Expand Up @@ -471,6 +474,17 @@ void replication_options::initialize()
config_sync_interval_ms,
"every this period(ms) the replica syncs replica configuration with the meta server");

mem_release_enabled = dsn_config_get_value_bool("replication",
"mem_release_enabled",
mem_release_enabled,
"whether to enable periodic memory release");

mem_release_interval_ms = (int)dsn_config_get_value_uint64(
"replication",
"mem_release_interval_ms",
mem_release_interval_ms,
"the replica releases its idle memory to the system every this period of time(ms)");

lb_interval_ms = (int)dsn_config_get_value_uint64(
"replication",
"lb_interval_ms",
Expand Down
3 changes: 3 additions & 0 deletions src/dist/replication/common/replication_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class replication_options
bool config_sync_disabled;
int32_t config_sync_interval_ms;

bool mem_release_enabled;
int32_t mem_release_interval_ms;

int32_t lb_interval_ms;

int32_t learn_app_max_concurrent_count;
Expand Down
28 changes: 26 additions & 2 deletions src/dist/replication/lib/replica_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#include <dsn/dist/replication/replication_app_base.h>
#include <vector>
#include <deque>
#ifdef DSN_ENABLE_GPERF
#include <gperftools/malloc_extension.h>
#endif

namespace dsn {
namespace replication {
Expand Down Expand Up @@ -632,6 +635,22 @@ void replica_stub::initialize_start()
std::chrono::milliseconds(_options.config_sync_interval_ms));
}

#ifdef DSN_ENABLE_GPERF
if (_options.mem_release_enabled) {
_mem_release_timer_task =
tasking::enqueue_timer(LPC_MEM_RELEASE,
&_tracker,
[]() {
ddebug("Memory release has started...");
::MallocExtension::instance()->ReleaseFreeMemory();
ddebug("Memory release has ended...");
},
std::chrono::milliseconds(_options.mem_release_interval_ms),
0,
std::chrono::milliseconds(_options.mem_release_interval_ms));
}
#endif

// init liveness monitor
dassert(NS_Disconnected == _state, "");
if (_options.fd_disabled == false) {
Expand Down Expand Up @@ -2185,6 +2204,11 @@ void replica_stub::close()
_gc_timer_task = nullptr;
}

if (_mem_release_timer_task != nullptr) {
_mem_release_timer_task->cancel(true);
_mem_release_timer_task = nullptr;
}

{
zauto_write_lock l(_replicas_lock);
while (!_closing_replicas.empty()) {
Expand Down Expand Up @@ -2254,5 +2278,5 @@ std::string replica_stub::get_replica_dir(const char *app_type, gpid id, bool cr
}
return ret_dir;
}
}
} // namespace
} // namespace replication
} // namespace dsn
1 change: 1 addition & 0 deletions src/dist/replication/lib/replica_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class replica_stub : public serverlet<replica_stub>, public ref_counter
::dsn::task_ptr _config_sync_timer_task;
::dsn::task_ptr _gc_timer_task;
::dsn::task_ptr _disk_stat_timer_task;
::dsn::task_ptr _mem_release_timer_task;

// command_handlers
dsn_handle_t _kill_partition_command;
Expand Down
1 change: 1 addition & 0 deletions src/tests/dsn/failure_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ void clear(test_worker *worker, std::vector<test_master *> masters)

void finish(test_worker *worker, test_master *master, int master_index)
{
dwarn("start to finish");
std::atomic_int wait_count;
wait_count.store(2);
worker->fd()->when_disconnected(
Expand Down