-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix](memory) Fix jdk17 and jemalloc hook not compatible on some envs #34578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you for your contribution to Apache Doris. Since 2024-03-18, the Document has been moved to doris-website. |
9d7f140 to
9ead678
Compare
|
run buildall |
|
run buildall |
|
|
clang-tidy review says "All clean, LGTM! 👍" |
|
|
run buildall |
|
clang-tidy review says "All clean, LGTM! 👍" |
|
run buildall |
|
clang-tidy review says "All clean, LGTM! 👍" |
TPC-H: Total hot run time: 40982 ms |
TPC-DS: Total hot run time: 186689 ms |
|
TeamCity be ut coverage result: |
morningman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
…apache#34578) Now in order to support malloc hook, compiling jemalloc will add tow compilation options --with-jemalloc-prefix=je and --disable-cxx, then overwrite malloc/free as follows to allow BE to use jemalloc: void* malloc(size_t size) __THROW ALIAS(doris_malloc); void free(void* p) __THROW ALIAS(doris_free); void* realloc(void* p, size_t size) __THROW ALIAS(doris_realloc); void* calloc(size_t n, size_t size) __THROW ALIAS(doris_calloc); void cfree(void* ptr) __THROW ALIAS(doris_cfree); but after such overwrite like this, Doris BE on jdk17 cannot be started in some environments. there are three solutions: Modify overwrite malloc/free, fixed in Use jemalloc's experimental features to hook jemalloc apache#33897 Modify BE dynamically loads JVM, fixed in [Fix](jdk) Fix jdk17 crash on some envs. apache#32865 Commit of this PR, modify jemalloc compilation options, after remove --with-jemalloc-prefix=je, there is not need to overwrite malloc/free, BE will use Jemalloc by default. So, if need to use memory hook, this PR still cannot solve this problem. Looking forward to modify BE dynamically loads JVM, which will not only solve this problem, also fix other crashes caused by BE use JVM.
…apache#34578) Now in order to support malloc hook, compiling jemalloc will add tow compilation options --with-jemalloc-prefix=je and --disable-cxx, then overwrite malloc/free as follows to allow BE to use jemalloc: #define ALIAS(doris_fn) __attribute__((alias(#doris_fn), used)) void* malloc(size_t size) __THROW ALIAS(doris_malloc); void free(void* p) __THROW ALIAS(doris_free); void* realloc(void* p, size_t size) __THROW ALIAS(doris_realloc); void* calloc(size_t n, size_t size) __THROW ALIAS(doris_calloc); void cfree(void* ptr) __THROW ALIAS(doris_cfree); but after such overwrite like this, Doris BE on jdk17 cannot be started in some environments. there are three solutions: Modify overwrite malloc/free, fixed in Use jemalloc's experimental features to hook jemalloc apache#33897 Modify BE dynamically loads JVM, fixed in [Fix](jdk) Fix jdk17 crash on some envs. apache#32865 Commit of this PR, modify jemalloc compilation options, after remove --with-jemalloc-prefix=je, there is not need to overwrite malloc/free, BE will use Jemalloc by default. So, if need to use memory hook, this PR still cannot solve this problem. Looking forward to modify BE dynamically loads JVM, which will not only solve this problem, also fix other crashes caused by BE use JVM.
## Proposed changes Revert #13660 `-l` and `dlopen` load Dynamic Link Library, will use the Allocator of main program, Doris use Jemalloc by default. but, `dlopen` load libjvm.so and use Jemalloc compiled with prefix, overwriting malloc/free will incompatible with libjvm.so. see #34578 for details. In addition, jemalloc not recommend `dlopen` to load Dynamic Link Library, `dlclose` will memory leak in that case. jemalloc/jemalloc#2404 jemalloc/jemalloc#1321 jemalloc/jemalloc#1890 `export LD_PRELOAD` to force `libjvm.so` use a separate `jemalloc.so` will not solve the problem, but may cause a new crash. ``` received by PID 2368 (TID 2391 OR 0x7f445cafb700) from PID 0; stack trace: *** 0# doris::signal::(anonymous namespace)::FailureSignalHandler(int, siginfo_t*, void*) at /root/selectdb-core/be/src/common/signal_handler.h:421 1# PosixSignals::chained_handler(int, siginfo*, void*) [clone .part.0] in /opt/jdk/lib/server/libjvm.so 2# JVM_handle_linux_signal in /opt/jdk/lib/server/libjvm.so 3# 0x00007F448DB40400 in /lib64/libc.so.6 4# je_arena_dalloc_promoted at /root/selectdb-core/thirdparty/src/jemalloc-5.3.0/doris_build/../src/arena.c:1277 5# je_free_default at /root/selectdb-core/thirdparty/src/jemalloc-5.3.0/doris_build/../src/jemalloc.c:3014 6# __pthread_create_2_1 in /lib64/libpthread.so.0 7# os::create_thread(Thread*, os::ThreadType, unsigned long) in /opt/jdk/lib/server/libjvm.so 8# CompilerThread::CompilerThread(CompileQueue*, CompilerCounters*) in /opt/jdk/lib/server/libjvm.so 9# CompileBroker::make_thread(CompileBroker::ThreadType, _jobject*, CompileQueue*, AbstractCompiler*, JavaThread*) [clone .constprop.0] in /opt/jdk/lib/server/libjvm.so 10# CompileBroker::possibly_add_compiler_threads(JavaThread*) in /opt/jdk/lib/server/libjvm.so 11# CompileBroker::compiler_thread_loop() in /opt/jdk/lib/server/libjvm.so 12# JavaThread::thread_main_inner() in /opt/jdk/lib/server/libjvm.so 13# Thread::call_run() in /opt/jdk/lib/server/libjvm.so 14# thread_native_entry(Thread*) in /opt/jdk/lib/server/libjvm.so 15# start_thread in /lib64/libpthread.so.0 16# clone in /lib64/libc.so.6 ``` <!--Describe your changes.-->
…ome envs (apache#34578)" This reverts commit 673c61a.
## Proposed changes Revert apache#13660 `-l` and `dlopen` load Dynamic Link Library, will use the Allocator of main program, Doris use Jemalloc by default. but, `dlopen` load libjvm.so and use Jemalloc compiled with prefix, overwriting malloc/free will incompatible with libjvm.so. see apache#34578 for details. In addition, jemalloc not recommend `dlopen` to load Dynamic Link Library, `dlclose` will memory leak in that case. jemalloc/jemalloc#2404 jemalloc/jemalloc#1321 jemalloc/jemalloc#1890 `export LD_PRELOAD` to force `libjvm.so` use a separate `jemalloc.so` will not solve the problem, but may cause a new crash. ``` received by PID 2368 (TID 2391 OR 0x7f445cafb700) from PID 0; stack trace: *** 0# doris::signal::(anonymous namespace)::FailureSignalHandler(int, siginfo_t*, void*) at /root/selectdb-core/be/src/common/signal_handler.h:421 1# PosixSignals::chained_handler(int, siginfo*, void*) [clone .part.0] in /opt/jdk/lib/server/libjvm.so 2# JVM_handle_linux_signal in /opt/jdk/lib/server/libjvm.so 3# 0x00007F448DB40400 in /lib64/libc.so.6 4# je_arena_dalloc_promoted at /root/selectdb-core/thirdparty/src/jemalloc-5.3.0/doris_build/../src/arena.c:1277 5# je_free_default at /root/selectdb-core/thirdparty/src/jemalloc-5.3.0/doris_build/../src/jemalloc.c:3014 6# __pthread_create_2_1 in /lib64/libpthread.so.0 7# os::create_thread(Thread*, os::ThreadType, unsigned long) in /opt/jdk/lib/server/libjvm.so 8# CompilerThread::CompilerThread(CompileQueue*, CompilerCounters*) in /opt/jdk/lib/server/libjvm.so 9# CompileBroker::make_thread(CompileBroker::ThreadType, _jobject*, CompileQueue*, AbstractCompiler*, JavaThread*) [clone .constprop.0] in /opt/jdk/lib/server/libjvm.so 10# CompileBroker::possibly_add_compiler_threads(JavaThread*) in /opt/jdk/lib/server/libjvm.so 11# CompileBroker::compiler_thread_loop() in /opt/jdk/lib/server/libjvm.so 12# JavaThread::thread_main_inner() in /opt/jdk/lib/server/libjvm.so 13# Thread::call_run() in /opt/jdk/lib/server/libjvm.so 14# thread_native_entry(Thread*) in /opt/jdk/lib/server/libjvm.so 15# start_thread in /lib64/libpthread.so.0 16# clone in /lib64/libc.so.6 ``` <!--Describe your changes.-->
…ome envs (apache#34578)" This reverts commit 673c61a.
Revert apache#13660 `-l` and `dlopen` load Dynamic Link Library, will use the Allocator of main program, Doris use Jemalloc by default. but, `dlopen` load libjvm.so and use Jemalloc compiled with prefix, overwriting malloc/free will incompatible with libjvm.so. see apache#34578 for details. In addition, jemalloc not recommend `dlopen` to load Dynamic Link Library, `dlclose` will memory leak in that case. jemalloc/jemalloc#2404 jemalloc/jemalloc#1321 jemalloc/jemalloc#1890 `export LD_PRELOAD` to force `libjvm.so` use a separate `jemalloc.so` will not solve the problem, but may cause a new crash. ``` received by PID 2368 (TID 2391 OR 0x7f445cafb700) from PID 0; stack trace: *** 0# doris::signal::(anonymous namespace)::FailureSignalHandler(int, siginfo_t*, void*) at /root/selectdb-core/be/src/common/signal_handler.h:421 1# PosixSignals::chained_handler(int, siginfo*, void*) [clone .part.0] in /opt/jdk/lib/server/libjvm.so 2# JVM_handle_linux_signal in /opt/jdk/lib/server/libjvm.so 3# 0x00007F448DB40400 in /lib64/libc.so.6 4# je_arena_dalloc_promoted at /root/selectdb-core/thirdparty/src/jemalloc-5.3.0/doris_build/../src/arena.c:1277 5# je_free_default at /root/selectdb-core/thirdparty/src/jemalloc-5.3.0/doris_build/../src/jemalloc.c:3014 6# __pthread_create_2_1 in /lib64/libpthread.so.0 7# os::create_thread(Thread*, os::ThreadType, unsigned long) in /opt/jdk/lib/server/libjvm.so 8# CompilerThread::CompilerThread(CompileQueue*, CompilerCounters*) in /opt/jdk/lib/server/libjvm.so 9# CompileBroker::make_thread(CompileBroker::ThreadType, _jobject*, CompileQueue*, AbstractCompiler*, JavaThread*) [clone .constprop.0] in /opt/jdk/lib/server/libjvm.so 10# CompileBroker::possibly_add_compiler_threads(JavaThread*) in /opt/jdk/lib/server/libjvm.so 11# CompileBroker::compiler_thread_loop() in /opt/jdk/lib/server/libjvm.so 12# JavaThread::thread_main_inner() in /opt/jdk/lib/server/libjvm.so 13# Thread::call_run() in /opt/jdk/lib/server/libjvm.so 14# thread_native_entry(Thread*) in /opt/jdk/lib/server/libjvm.so 15# start_thread in /lib64/libpthread.so.0 16# clone in /lib64/libc.so.6 ``` <!--Describe your changes.-->
Proposed changes
Now in order to support malloc hook, compiling jemalloc will add tow compilation options
--with-jemalloc-prefix=jeand--disable-cxx, then overwrite malloc/free as follows to allow BE to use jemalloc:but after such overwrite like this, Doris BE on jdk17 cannot be started in some environments.
there are three solutions:
--with-jemalloc-prefix=je, there is not need to overwrite malloc/free, BE will use Jemalloc by default.So, if need to use memory hook, this PR still cannot solve this problem.
Looking forward to modify BE dynamically loads JVM, which will not only solve this problem, also fix other crashes caused by BE use JVM.
Further comments
If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...