Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lihongda1002
oceanbase
提交
73ddc419
O
oceanbase
项目概览
lihongda1002
/
oceanbase
与 Fork 源项目一致
Fork自
oceanbase / oceanbase
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oceanbase
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73ddc419
编写于
11月 02, 2022
作者:
N
nroskill
提交者:
wangzelin.wzl
11月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix memory leak in VSliceAlloc
上级
1432398f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
70 addition
and
6 deletion
+70
-6
deps/oblib/src/lib/allocator/ob_slice_alloc.h
deps/oblib/src/lib/allocator/ob_slice_alloc.h
+30
-3
deps/oblib/src/lib/allocator/ob_vslice_alloc.h
deps/oblib/src/lib/allocator/ob_vslice_alloc.h
+24
-2
deps/oblib/src/lib/hash/ob_linear_hash_map.h
deps/oblib/src/lib/hash/ob_linear_hash_map.h
+15
-1
unittest/storage/test_io_manager.cpp
unittest/storage/test_io_manager.cpp
+1
-0
未找到文件。
deps/oblib/src/lib/allocator/ob_slice_alloc.h
浏览文件 @
73ddc419
...
...
@@ -131,9 +131,11 @@ public:
}
public:
uint32_t
total
()
{
return
total_
;
}
int32_t
stock
()
{
return
stock_
;
}
int32_t
remain
()
{
return
stock_
>
K
?
stock_
-
K
:
(
stock_
<
0
?
stock_
+
K
:
stock_
);
}
bool
acquire
()
{
return
dec_if_gt
(
K
,
K
)
>
K
;
}
bool
release
()
{
return
faa
(
-
K
)
>
0
;
}
bool
recyle
()
{
bool
recy
c
le
()
{
int32_t
total
=
total_
;
return
inc_if_lt
(
2
*
K
,
-
K
+
total
)
==
-
K
+
total
;
}
...
...
@@ -271,13 +273,37 @@ public:
LIB_LOG
(
INFO
,
"ObSliceAlloc init finished"
,
K
(
bsize_
),
K
(
isize_
),
K
(
slice_limit_
),
KP
(
tmallocator_
));
}
~
ObSliceAlloc
()
{
tmallocator_
=
NULL
;
destroy
()
;
}
int
init
(
const
int
size
,
const
int
block_size
,
BlockAlloc
&
block_alloc
,
const
ObMemAttr
&
attr
)
{
int
ret
=
common
::
OB_SUCCESS
;
new
(
this
)
ObSliceAlloc
(
size
,
attr
,
block_size
,
block_alloc
,
NULL
);
return
ret
;
}
void
destroy
()
{
for
(
int
i
=
MAX_ARENA_NUM
-
1
;
i
>=
0
;
i
--
)
{
Arena
&
arena
=
arena_
[
i
];
Block
*
old_blk
=
arena
.
clear
();
if
(
NULL
!=
old_blk
)
{
blk_ref_
[
ObBlockSlicer
::
hash
((
uint64_t
)
old_blk
)
%
MAX_REF_NUM
].
sync
();
if
(
old_blk
->
release
())
{
blk_list_
.
add
(
&
old_blk
->
dlink_
);
if
(
old_blk
->
recycle
())
{
destroy_block
(
old_blk
);
}
else
{
_LIB_LOG
(
ERROR
,
"there was memory leak, stock=%d, remain=%d"
,
old_blk
->
stock
(),
old_blk
->
remain
());
}
}
}
}
ObDLink
*
dlink
=
nullptr
;
if
(
OB_NOT_NULL
(
dlink
=
blk_list_
.
top
()))
{
Block
*
blk
=
CONTAINER_OF
(
dlink
,
Block
,
dlink_
);
_LIB_LOG
(
ERROR
,
"there was memory leak, stock=%d, remain=%d"
,
blk
->
stock
(),
blk
->
remain
());
}
tmallocator_
=
NULL
;
bsize_
=
0
;
}
void
set_nway
(
int
nway
)
{
if
(
nway
<=
0
)
{
nway
=
1
;
...
...
@@ -351,6 +377,7 @@ public:
Block
*
blk
=
item
->
host_
;
#ifndef NDEBUG
abort_unless
(
blk
->
get_slice_alloc
()
==
this
);
abort_unless
(
bsize_
!=
0
);
#else
if
(
this
!=
blk
->
get_slice_alloc
())
{
LIB_LOG
(
ERROR
,
"blk is freed or alloced by different slice_alloc"
,
K
(
this
),
K
(
blk
->
get_slice_alloc
()));
...
...
@@ -391,7 +418,7 @@ private:
}
void
add_to_blist
(
Block
*
blk
)
{
blk_list_
.
add
(
&
blk
->
dlink_
);
if
(
blk
->
recyle
())
{
if
(
blk
->
recy
c
le
())
{
destroy_block
(
blk
);
}
}
...
...
deps/oblib/src/lib/allocator/ob_vslice_alloc.h
浏览文件 @
73ddc419
...
...
@@ -25,6 +25,7 @@ namespace common
extern
ObBlockAllocMgr
default_blk_alloc
;
class
ObBlockVSlicer
{
friend
class
ObVSliceAlloc
;
public:
static
const
uint32_t
ITEM_MAGIC_CODE
=
0XCCEEDDF1
;
static
const
uint32_t
ITEM_MAGIC_CODE_MASK
=
0XFFFFFFF0
;
...
...
@@ -72,6 +73,7 @@ private:
class
ObVSliceAlloc
:
public
common
::
ObIAllocator
{
friend
class
ObBlockVSlicer
;
public:
enum
{
MAX_ARENA_NUM
=
32
,
DEFAULT_BLOCK_SIZE
=
OB_MALLOC_NORMAL_BLOCK_SIZE
};
typedef
ObBlockAllocMgr
BlockAlloc
;
...
...
@@ -91,12 +93,31 @@ public:
ObVSliceAlloc
()
:
nway_
(
0
),
bsize_
(
0
),
blk_alloc_
(
default_blk_alloc
)
{}
ObVSliceAlloc
(
const
ObMemAttr
&
attr
,
int
block_size
=
DEFAULT_BLOCK_SIZE
,
BlockAlloc
&
blk_alloc
=
default_blk_alloc
)
:
nway_
(
1
),
bsize_
(
block_size
),
mattr_
(
attr
),
blk_alloc_
(
blk_alloc
)
{}
virtual
~
ObVSliceAlloc
()
override
{}
virtual
~
ObVSliceAlloc
()
override
{
destroy
();
}
int
init
(
int
block_size
,
BlockAlloc
&
block_alloc
,
const
ObMemAttr
&
attr
)
{
int
ret
=
OB_SUCCESS
;
new
(
this
)
ObVSliceAlloc
(
attr
,
block_size
,
block_alloc
);
return
ret
;
}
void
destroy
()
{
for
(
int
i
=
MAX_ARENA_NUM
-
1
;
i
>=
0
;
i
--
)
{
Arena
&
arena
=
arena_
[
i
];
Block
*
old_blk
=
arena
.
clear
();
if
(
NULL
!=
old_blk
)
{
int64_t
old_pos
=
INT64_MAX
;
if
(
old_blk
->
freeze
(
old_pos
))
{
arena
.
sync
();
if
(
old_blk
->
retire
(
old_pos
))
{
destroy_block
(
old_blk
);
}
else
{
// can not monitor all leak !!!
LIB_LOG
(
ERROR
,
"there was memory leak"
,
K
(
old_blk
->
ref_
));
}
}
}
}
bsize_
=
0
;
}
void
set_nway
(
int
nway
)
{
if
(
nway
<=
0
)
{
nway
=
1
;
...
...
@@ -182,12 +203,13 @@ public:
#ifdef OB_USE_ASAN
::
free
(
p
);
#else
if
(
bsize_
>
0
&&
NULL
!=
p
)
{
if
(
NULL
!=
p
)
{
Block
::
Item
*
item
=
(
Block
::
Item
*
)
p
-
1
;
abort_unless
(
Block
::
ITEM_MAGIC_CODE
==
item
->
MAGIC_CODE_
);
Block
*
blk
=
item
->
host_
;
#ifndef NDEBUG
abort_unless
(
blk
->
get_vslice_alloc
()
==
this
);
abort_unless
(
bsize_
!=
0
);
#else
if
(
this
!=
blk
->
get_vslice_alloc
())
{
LIB_LOG
(
ERROR
,
"blk is freed or alloced by different vslice_alloc"
,
K
(
this
),
K
(
blk
->
get_vslice_alloc
()));
...
...
deps/oblib/src/lib/hash/ob_linear_hash_map.h
浏览文件 @
73ddc419
...
...
@@ -182,10 +182,18 @@ struct ShareMemMgrTag { };
/* Don't use this mode unless you know what it means. */
struct
UniqueMemMgrTag
{
};
// avoid allocator destructed before HashMap
template
<
typename
Key
,
typename
Value
,
typename
MemMgrTag
>
struct
ConstructGuard
{
public:
ConstructGuard
();
};
template
<
typename
Key
,
typename
Value
,
typename
MemMgrTag
=
ShareMemMgrTag
>
class
ObLinearHashMap
class
ObLinearHashMap
:
public
ConstructGuard
<
Key
,
Value
,
MemMgrTag
>
{
friend
class
ConstructGuard
<
Key
,
Value
,
MemMgrTag
>
;
private:
/* Entry. */
struct
Node
...
...
@@ -2372,6 +2380,12 @@ bool ObLinearHashMap<Key, Value, MemMgrTag>::DoRemoveIfOnBkt<Function>::operator
return
true
;
}
template
<
typename
Key
,
typename
Value
,
typename
MemMgrTag
>
ConstructGuard
<
Key
,
Value
,
MemMgrTag
>::
ConstructGuard
()
{
auto
&
t
=
ObLinearHashMap
<
Key
,
Value
,
MemMgrTag
>::
HashMapMemMgrCore
::
get_instance
();
}
}
}
...
...
unittest/storage/test_io_manager.cpp
浏览文件 @
73ddc419
...
...
@@ -283,6 +283,7 @@ TEST_F(TestIOStruct, IOAllocator)
TEST_F
(
TestIOStruct
,
IORequest
)
{
ObTenantIOManager
tenant_io_mgr
;
tenant_io_mgr
.
inc_ref
();
ASSERT_SUCC
(
tenant_io_mgr
.
io_allocator_
.
init
(
TEST_TENANT_ID
,
IO_MEMORY_LIMIT
));
ObRefHolder
<
ObTenantIOManager
>
holder
(
&
tenant_io_mgr
);
ObIOFd
fd
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录