From e501bbe21656915fde8e4914abf22db0ff5609dd Mon Sep 17 00:00:00 2001 From: nroskill Date: Tue, 4 Apr 2023 15:14:33 +0000 Subject: [PATCH] fix stack overflow when page_size is not 4k --- deps/oblib/src/common/ob_smart_call.h | 4 ++-- deps/oblib/src/lib/thread/protected_stack_allocator.cpp | 5 ----- deps/oblib/src/lib/thread/protected_stack_allocator.h | 1 - deps/oblib/src/lib/thread/threads.cpp | 2 +- deps/oblib/unittest/common/test_smart_call.cpp | 2 +- src/observer/ob_server.cpp | 2 +- 6 files changed, 5 insertions(+), 11 deletions(-) diff --git a/deps/oblib/src/common/ob_smart_call.h b/deps/oblib/src/common/ob_smart_call.h index 943fabbf5..2a45116ae 100644 --- a/deps/oblib/src/common/ob_smart_call.h +++ b/deps/oblib/src/common/ob_smart_call.h @@ -22,7 +22,7 @@ namespace oceanbase namespace common { static constexpr int64_t ALL_STACK_LIMIT = 10L << 20; -static constexpr int64_t STACK_PER_EXTEND = 2L << 20; +static constexpr int64_t STACK_PER_EXTEND = (2L << 20) - ACHUNK_PRESERVE_SIZE; static constexpr int64_t STACK_RESERVED_SIZE = 128L << 10; RLOCAL_EXTERN(int64_t, all_stack_size); @@ -36,7 +36,7 @@ inline int call_with_new_stack(void * arg_, int(*func_) (void*)) size_t ori_stack_size = 0; void *stack_addr = nullptr; uint64_t tenant_id = GET_TENANT_ID() == 0 ? 500 : GET_TENANT_ID(); - const int64_t stack_size = lib::ProtectedStackAllocator::adjust_size(STACK_PER_EXTEND); + const int64_t stack_size = STACK_PER_EXTEND; if (OB_FAIL(get_stackattr(ori_stack_addr, ori_stack_size))) { } else if (FALSE_IT(all_stack_size = 0 == all_stack_size ? ori_stack_size : all_stack_size)) { diff --git a/deps/oblib/src/lib/thread/protected_stack_allocator.cpp b/deps/oblib/src/lib/thread/protected_stack_allocator.cpp index 24309bdac..1253a1ce9 100644 --- a/deps/oblib/src/lib/thread/protected_stack_allocator.cpp +++ b/deps/oblib/src/lib/thread/protected_stack_allocator.cpp @@ -29,11 +29,6 @@ namespace lib ProtectedStackAllocator g_stack_allocer; StackMgr g_stack_mgr; -ssize_t ProtectedStackAllocator::adjust_size(const ssize_t size) -{ - return size - page_size() * 2 - ACHUNK_PRESERVE_SIZE; -} - ssize_t ProtectedStackAllocator::page_size() { return get_page_size(); diff --git a/deps/oblib/src/lib/thread/protected_stack_allocator.h b/deps/oblib/src/lib/thread/protected_stack_allocator.h index c0c334cb5..5b51baf0c 100644 --- a/deps/oblib/src/lib/thread/protected_stack_allocator.h +++ b/deps/oblib/src/lib/thread/protected_stack_allocator.h @@ -41,7 +41,6 @@ class ProtectedStackAllocator public: void *alloc(const uint64_t tenant_id, const ssize_t size); void dealloc(void *ptr); - static ssize_t adjust_size(const ssize_t size); static ObStackHeader *stack_header(void *ptr); static ssize_t page_size(); private: diff --git a/deps/oblib/src/lib/thread/threads.cpp b/deps/oblib/src/lib/thread/threads.cpp index 1f8b0c65d..b29dc4e41 100644 --- a/deps/oblib/src/lib/thread/threads.cpp +++ b/deps/oblib/src/lib/thread/threads.cpp @@ -23,7 +23,7 @@ using namespace oceanbase::lib; using namespace oceanbase::common; -int64_t global_thread_stack_size = ProtectedStackAllocator::adjust_size(1L << 19) - SIG_STACK_SIZE; +int64_t global_thread_stack_size = (1L << 19) - SIG_STACK_SIZE - ACHUNK_PRESERVE_SIZE; thread_local uint64_t ThreadPool::thread_idx_ = 0; // 获取线程局部的租户上下文,为线程池启动时检查使用 diff --git a/deps/oblib/unittest/common/test_smart_call.cpp b/deps/oblib/unittest/common/test_smart_call.cpp index 55872ca6e..9b9d7e902 100644 --- a/deps/oblib/unittest/common/test_smart_call.cpp +++ b/deps/oblib/unittest/common/test_smart_call.cpp @@ -110,7 +110,7 @@ TEST(sc, usability) void *cur_stack_addr = nullptr; size_t cur_stack_size = 0; int stack_change_cnt = 0; -#define STACK_PER_EXTEND_SIZE lib::ProtectedStackAllocator::adjust_size(STACK_PER_EXTEND) +#define STACK_PER_EXTEND_SIZE STACK_PER_EXTEND const int64_t s_size = STACK_PER_EXTEND_SIZE; int test(int &i, int once_invoke_hold) { diff --git a/src/observer/ob_server.cpp b/src/observer/ob_server.cpp index b530bc987..ceea332d0 100644 --- a/src/observer/ob_server.cpp +++ b/src/observer/ob_server.cpp @@ -1645,7 +1645,7 @@ int ObServer::init_pre_setting() if (OB_SUCC(ret)) { const int64_t stack_size = std::max(1L << 19, static_cast(GCONF.stack_size)); LOG_INFO("set stack_size", K(stack_size)); - global_thread_stack_size = lib::ProtectedStackAllocator::adjust_size(stack_size) - SIG_STACK_SIZE; + global_thread_stack_size = stack_size - SIG_STACK_SIZE - ACHUNK_PRESERVE_SIZE; } return ret; }