fix stack overflow when page_size is not 4k

This commit is contained in:
nroskill 2023-04-04 15:14:33 +00:00 committed by ob-robot
parent 17c7709c25
commit e501bbe216
6 changed files with 5 additions and 11 deletions

View File

@ -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)) {

View File

@ -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();

View File

@ -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:

View File

@ -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;
// 获取线程局部的租户上下文,为线程池启动时检查使用

View File

@ -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)
{

View File

@ -1645,7 +1645,7 @@ int ObServer::init_pre_setting()
if (OB_SUCC(ret)) {
const int64_t stack_size = std::max(1L << 19, static_cast<int64_t>(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;
}