未验证 提交 23942087 编写于 作者: O openharmony_ci 提交者: Gitee

!964 添加jemalloc垃圾回收信号

Merge pull request !964 from 李策/master
...@@ -36,6 +36,7 @@ declare_args() { ...@@ -36,6 +36,7 @@ declare_args() {
user_custom_libc = true user_custom_libc = true
use_jemalloc = false use_jemalloc = false
use_jemalloc_dfx_intf = false use_jemalloc_dfx_intf = false
use_jemalloc_recycle_func = false
use_pthread_cancel = false use_pthread_cancel = false
musl_ported_dir = "intermidiates/${musl_target_os}/musl_src_ported" musl_ported_dir = "intermidiates/${musl_target_os}/musl_src_ported"
musl_inc_out_dir = "usr/include/${musl_target_triple}" musl_inc_out_dir = "usr/include/${musl_target_triple}"
......
...@@ -584,6 +584,9 @@ template("musl_libs") { ...@@ -584,6 +584,9 @@ template("musl_libs") {
if (use_jemalloc_dfx_intf) { if (use_jemalloc_dfx_intf) {
defines += [ "USE_JEMALLOC_DFX_INTF" ] defines += [ "USE_JEMALLOC_DFX_INTF" ]
} }
if (use_jemalloc_recycle_func) {
defines += [ "USE_JEMALLOC_RECYCLE_FUNC" ]
}
include_dirs = [ "//third_party/jemalloc/include/jemalloc" ] include_dirs = [ "//third_party/jemalloc/include/jemalloc" ]
} }
...@@ -797,6 +800,9 @@ template("musl_libs") { ...@@ -797,6 +800,9 @@ template("musl_libs") {
if (use_jemalloc_dfx_intf) { if (use_jemalloc_dfx_intf) {
defines += [ "USE_JEMALLOC_DFX_INTF" ] defines += [ "USE_JEMALLOC_DFX_INTF" ]
} }
if (use_jemalloc_recycle_func) {
defines += [ "USE_JEMALLOC_RECYCLE_FUNC" ]
}
include_dirs = [ "//third_party/jemalloc/include/jemalloc" ] include_dirs = [ "//third_party/jemalloc/include/jemalloc" ]
} }
......
...@@ -217,6 +217,9 @@ int __libc_current_sigrtmax(void); ...@@ -217,6 +217,9 @@ int __libc_current_sigrtmax(void);
#define MUSL_SIGNAL_NATIVE_LOCAL (SIGRTMIN + 3) #define MUSL_SIGNAL_NATIVE_LOCAL (SIGRTMIN + 3)
#define MUSL_SIGNAL_JSHEAP (SIGRTMIN + 4) #define MUSL_SIGNAL_JSHEAP (SIGRTMIN + 4)
#define MUSL_SIGNAL_JSHEAP_PRIV (SIGRTMIN + 5) #define MUSL_SIGNAL_JSHEAP_PRIV (SIGRTMIN + 5)
#ifdef USE_JEMALLOC_RECYCLE_FUNC
#define MUSL_SIGNAL_RECYCLE_JEMALLOC(SIGRTMIN + 8)
#endif
#define MUSL_SIGNAL_MEMCHECK (SIGRTMIN + 9) #define MUSL_SIGNAL_MEMCHECK (SIGRTMIN + 9)
int kill(pid_t, int); int kill(pid_t, int);
......
...@@ -271,6 +271,28 @@ static bool init_prctl_function(void* malloc_shared_library_handler, MallocPrctl ...@@ -271,6 +271,28 @@ static bool init_prctl_function(void* malloc_shared_library_handler, MallocPrctl
return true; return true;
} }
#ifdef USE_JEMALLOC_RECYCLE_FUNC
extern int je_reclaim_cache();
static void handle_recycle_cache()
{
int ret;
ret = je_reclaim_cache();
MUSL_LOGD("je_reclaim_cache result=%{public}d", ret);
}
static void init_jemalloc_recycle_handler()
{
struct sigaction action = {};
action.sa_handler = NULL;
action.sa_sigaction = handle_recycle_cache;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, MUSL_SIGNAL_RECYCLE_JEMALLOC);
action.sa_flags = SA_SIGINFO | SA_RESTART;
action.sa_restorer = NULL;
sigaction(MUSL_SIGNAL_RECYCLE_JEMALLOC, &action, NULL);
}
#endif
static bool init_hook_functions(void* shared_library_handler, struct MallocDispatchType* table, const char* prefix) static bool init_hook_functions(void* shared_library_handler, struct MallocDispatchType* table, const char* prefix)
{ {
...@@ -626,6 +648,9 @@ static void __install_malloc_hook_signal_handler() ...@@ -626,6 +648,9 @@ static void __install_malloc_hook_signal_handler()
static void __initialize_malloc() static void __initialize_malloc()
{ {
__install_malloc_hook_signal_handler(); __install_malloc_hook_signal_handler();
#ifdef USE_JEMALLOC_RECYCLE_FUNC
init_jemalloc_recycle_handler();
#endif
} }
__attribute__((constructor(1))) static void __musl_initialize() __attribute__((constructor(1))) static void __musl_initialize()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册