Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a7e15c32
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1191
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a7e15c32
编写于
10月 09, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
finish vma
上级
f762d037
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
139 addition
and
2 deletion
+139
-2
source/server/vnode/inc/vnodeMemAllocator.h
source/server/vnode/inc/vnodeMemAllocator.h
+28
-1
source/server/vnode/src/vnodeMemAllocator.c
source/server/vnode/src/vnodeMemAllocator.c
+111
-1
未找到文件。
source/server/vnode/inc/vnodeMemAllocator.h
浏览文件 @
a7e15c32
...
...
@@ -16,12 +16,39 @@
#ifndef _TD_VNODE_MEM_ALLOCATOR_H_
#define _TD_VNODE_MEM_ALLOCATOR_H_
#include "
amalloc
.h"
#include "
os
.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
SVMANode
SVMANode
;
typedef
struct
SVnodeMemAllocator
SVnodeMemAllocator
;
SVnodeMemAllocator
*
VMACreate
(
size_t
size
/* base size */
,
size_t
ssize
/* step size */
,
size_t
threshold
/* threshold size when full*/
);
void
VMADestroy
(
SVnodeMemAllocator
*
pvma
);
void
VMAReset
(
SVnodeMemAllocator
*
pvma
);
void
*
VMAMalloc
(
SVnodeMemAllocator
*
pvma
,
size_t
size
);
void
VMAFree
(
SVnodeMemAllocator
*
pvma
,
void
*
ptr
);
bool
VMAIsFull
(
SVnodeMemAllocator
*
pvma
);
// ------------------ FOR TEST ONLY ------------------
struct
SVMANode
{
struct
SVMANode
*
prev
;
size_t
tsize
;
size_t
used
;
char
data
[];
};
struct
SVnodeMemAllocator
{
bool
full
;
// if allocator is full
size_t
threshold
;
// threshold;
size_t
ssize
;
// step size to allocate
SVMANode
*
inuse
;
// inuse node to allocate
SVMANode
node
;
// basic node to use
};
#ifdef __cplusplus
}
#endif
...
...
source/server/vnode/src/vnodeMemAllocator.c
浏览文件 @
a7e15c32
...
...
@@ -11,4 +11,114 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
\ No newline at end of file
*/
#include "vnodeMemAllocator.h"
#define VMA_IS_FULL(pvma) \
(((pvma)->inuse != &((pvma)->node)) || ((pvma)->inuse->tsize - (pvma)->inuse->used < (pvma)->threshold))
static
SVMANode
*
VMANodeNew
(
size_t
size
);
static
void
VMANodeFree
(
SVMANode
*
node
);
SVnodeMemAllocator
*
VMACreate
(
size_t
size
,
size_t
ssize
,
size_t
threshold
)
{
SVnodeMemAllocator
*
pvma
=
NULL
;
if
(
size
<
threshold
)
{
return
NULL
;
}
pvma
=
(
SVnodeMemAllocator
*
)
malloc
(
sizeof
(
*
pvma
)
+
size
);
if
(
pvma
)
{
pvma
->
full
=
false
;
pvma
->
threshold
=
threshold
;
pvma
->
ssize
=
ssize
;
pvma
->
inuse
=
&
(
pvma
->
node
);
pvma
->
inuse
->
prev
=
NULL
;
pvma
->
inuse
->
tsize
=
size
;
pvma
->
inuse
->
used
=
0
;
}
return
pvma
;
}
void
VMADestroy
(
SVnodeMemAllocator
*
pvma
)
{
if
(
pvma
)
{
VMAReset
(
pvma
);
free
(
pvma
);
}
}
void
VMAReset
(
SVnodeMemAllocator
*
pvma
)
{
while
(
pvma
->
inuse
!=
&
(
pvma
->
node
))
{
SVMANode
*
node
=
pvma
->
inuse
;
pvma
->
inuse
=
node
->
prev
;
VMANodeFree
(
node
);
}
pvma
->
inuse
->
used
=
0
;
pvma
->
full
=
false
;
}
void
*
VMAMalloc
(
SVnodeMemAllocator
*
pvma
,
size_t
size
)
{
void
*
ptr
=
NULL
;
size_t
tsize
=
size
+
sizeof
(
size_t
);
if
(
pvma
->
inuse
->
tsize
-
pvma
->
inuse
->
used
<
tsize
)
{
SVMANode
*
pNode
=
VMANodeNew
(
MAX
(
pvma
->
ssize
,
tsize
));
if
(
pNode
==
NULL
)
{
return
NULL
;
}
pNode
->
prev
=
pvma
->
inuse
;
pvma
->
inuse
=
pNode
;
}
ptr
=
pvma
->
inuse
->
data
+
pvma
->
inuse
->
used
;
pvma
->
inuse
->
used
+=
tsize
;
*
(
size_t
*
)
ptr
=
size
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
size_t
));
pvma
->
full
=
VMA_IS_FULL
(
pvma
);
return
ptr
;
}
void
VMAFree
(
SVnodeMemAllocator
*
pvma
,
void
*
ptr
)
{
if
(
ptr
)
{
size_t
size
=
*
(
size_t
*
)
POINTER_SHIFT
(
ptr
,
-
sizeof
(
size_t
));
if
(
POINTER_SHIFT
(
ptr
,
size
)
==
pvma
->
inuse
->
data
+
pvma
->
inuse
->
used
)
{
pvma
->
inuse
->
used
-=
(
size
+
sizeof
(
size_t
));
if
((
pvma
->
inuse
->
used
==
0
)
&&
(
pvma
->
inuse
!=
&
(
pvma
->
node
)))
{
SVMANode
*
node
=
pvma
->
inuse
;
pvma
->
inuse
=
node
->
prev
;
VMANodeFree
(
node
);
}
pvma
->
full
=
VMA_IS_FULL
(
pvma
);
}
}
}
bool
VMAIsFull
(
SVnodeMemAllocator
*
pvma
)
{
return
pvma
->
full
;
}
static
SVMANode
*
VMANodeNew
(
size_t
size
)
{
SVMANode
*
node
=
NULL
;
node
=
(
SVMANode
*
)
malloc
(
sizeof
(
*
node
)
+
size
);
if
(
node
)
{
node
->
prev
=
NULL
;
node
->
tsize
=
size
;
node
->
used
=
0
;
}
return
node
;
}
static
void
VMANodeFree
(
SVMANode
*
node
)
{
if
(
node
)
{
free
(
node
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录