Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d1e0a9a7
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
d1e0a9a7
编写于
12月 16, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make test run
上级
835c3030
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
45 addition
and
176 deletion
+45
-176
source/dnode/vnode/impl/src/vnodeBufferPool.c
source/dnode/vnode/impl/src/vnodeBufferPool.c
+45
-176
未找到文件。
source/dnode/vnode/impl/src/vnodeBufferPool.c
浏览文件 @
d1e0a9a7
...
...
@@ -28,6 +28,9 @@ struct SVBufPool {
SMemAllocatorFactory
*
pMAF
;
};
static
SMemAllocator
*
vBufPoolCreateMA
(
SMemAllocatorFactory
*
pMAF
);
static
void
vBufPoolDestroyMA
(
SMemAllocatorFactory
*
pMAF
,
SMemAllocator
*
pMA
);
int
vnodeOpenBufPool
(
SVnode
*
pVnode
)
{
uint64_t
capacity
;
...
...
@@ -54,6 +57,15 @@ int vnodeOpenBufPool(SVnode *pVnode) {
tDListAppend
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
}
pVnode
->
pBufPool
->
pMAF
=
(
SMemAllocatorFactory
*
)
malloc
(
sizeof
(
SMemAllocatorFactory
));
if
(
pVnode
->
pBufPool
->
pMAF
==
NULL
)
{
// TODO: handle error
return
-
1
;
}
pVnode
->
pBufPool
->
pMAF
->
impl
=
pVnode
;
pVnode
->
pBufPool
->
pMAF
->
create
=
vBufPoolCreateMA
;
pVnode
->
pBufPool
->
pMAF
->
destroy
=
vBufPoolDestroyMA
;
return
0
;
}
...
...
@@ -127,195 +139,52 @@ bool vnodeBufPoolIsFull(SVnode *pVnode) {
SMemAllocatorFactory
*
vBufPoolGetMAF
(
SVnode
*
pVnode
)
{
return
pVnode
->
pBufPool
->
pMAF
;
}
#if 0
typedef enum {
// Heap allocator
E_V_HEAP_ALLOCATOR = 0,
// Arena allocator
E_V_ARENA_ALLOCATOR
} EVMemAllocatorT;
typedef struct {
/* TODO */
} SVHeapAllocator;
typedef struct SVArenaNode {
struct SVArenaNode *prev;
uint64_t size;
void * ptr;
char data[];
} SVArenaNode;
typedef struct {
uint64_t ssize; // step size
uint64_t lsize; // limit size
SVArenaNode *inuse;
SVArenaNode node;
} SVArenaAllocator;
/* ------------------------ STATIC METHODS ------------------------ */
typedef
struct
{
SVnode * pVnode;
S
ListNode *pNode
;
SVnode
*
pVnode
;
S
VMemAllocator
*
pVMA
;
}
SVMAWrapper
;
static
FORCE_INLINE
void
*
vmaMaloocCb
(
SMemAllocator
*
pMA
,
uint64_t
size
)
{
SVMAWrapper
*
pWrapper
=
(
SVMAWrapper
*
)(
pMA
->
impl
);
static SListNode * vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type);
static void vBufPoolFreeNode(SListNode *pNode);
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf);
static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma);
static void * vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size);
/* ------------------------ STATIC METHODS ------------------------ */
static SListNode *vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type) {
SListNode * pNode;
SVMemAllocator *pvma;
uint64_t msize;
uint64_t ssize = 4096; // TODO
uint64_t lsize = 1024; // TODO
msize = sizeof(SListNode) + sizeof(SVMemAllocator);
if (type == E_V_ARENA_ALLOCATOR) {
msize += capacity;
}
pNode = (SListNode *)calloc(1, msize);
if (pNode == NULL) {
// TODO: handle error
return NULL;
}
pvma = (SVMemAllocator *)(pNode->data);
pvma->capacity = capacity;
pvma->type = type;
switch (type) {
case E_V_ARENA_ALLOCATOR:
vArenaAllocatorInit(&(pvma->vaa), capacity, ssize, lsize);
break;
case E_V_HEAP_ALLOCATOR:
// vHeapAllocatorInit(&(pvma->vha));
break;
default:
ASSERT(0);
}
return pNode;
return
vmaMalloc
(
pWrapper
->
pVMA
,
size
);
}
static void vBufPoolFreeNode(SListNode *pNode) {
SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data);
switch (pvma->type) {
case E_V_ARENA_ALLOCATOR:
vArenaAllocatorClear(&(pvma->vaa));
break;
case E_V_HEAP_ALLOCATOR:
// vHeapAllocatorClear(&(pvma->vha));
break;
default:
break;
}
// TODO: Add atomic operations here
static
SMemAllocator
*
vBufPoolCreateMA
(
SMemAllocatorFactory
*
pMAF
)
{
SMemAllocator
*
pMA
;
SVnode
*
pVnode
=
(
SVnode
*
)(
pMAF
->
impl
);
SVMAWrapper
*
pWrapper
;
free(pNode);
}
static void *vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size) {
void *ptr = NULL;
if (pvma->type == E_V_ARENA_ALLOCATOR) {
SVArenaAllocator *pvaa = &(pvma->vaa);
if (POINTER_DISTANCE(pvaa->inuse->ptr, pvaa->inuse->data) + size > pvaa->inuse->size) {
SVArenaNode *pNode = (SVArenaNode *)malloc(sizeof(*pNode) + MAX(size, pvaa->ssize));
if (pNode == NULL) {
// TODO: handle error
return NULL;
}
pNode->prev = pvaa->inuse;
pNode->size = MAX(size, pvaa->ssize);
pNode->ptr = pNode->data;
pvaa->inuse = pNode;
}
ptr = pvaa->inuse->ptr;
pvaa->inuse->ptr = POINTER_SHIFT(ptr, size);
} else if (pvma->type == E_V_HEAP_ALLOCATOR) {
/* TODO */
}
return ptr;
}
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf) {
SVnode * pVnode;
SMemAllocator * pma;
SVMemAllocator *pvma;
SVMAWrapper * pvmaw;
pVnode = (SVnode *)(pmaf->impl);
pma = (SMemAllocator *)calloc(1, sizeof(*pma) + sizeof(SVMAWrapper));
if (pma == NULL) {
// TODO: handle error
pMA
=
(
SMemAllocator
*
)
calloc
(
1
,
sizeof
(
*
pMA
)
+
sizeof
(
SVMAWrapper
));
if
(
pMA
==
NULL
)
{
return
NULL
;
}
pvmaw = (SVMAWrapper *)POINTER_SHIFT(pma, sizeof(*pma));
// No allocator used currently
if (pVnode->pBufPool->inuse == NULL) {
while (listNEles(&(pVnode->pBufPool->free)) == 0) {
// TODO: wait until all released ro kill query
// tsem_wait();
ASSERT(0);
}
pVnode->pBufPool->inuse = tdListPopHead(&(pVnode->pBufPool->free));
pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
T_REF_INIT_VAL(pvma, 1);
} else {
pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
}
T_REF_INC(pvma);
pVnode
->
pBufPool
->
inuse
->
_ref
.
val
++
;
pWrapper
=
POINTER_SHIFT
(
pMA
,
sizeof
(
*
pMA
));
pWrapper
->
pVnode
=
pVnode
;
pWrapper
->
pVMA
=
pVnode
->
pBufPool
->
inuse
;
pvmaw->pVnode = pVnode;
pvmaw->pNode = pVnode->pBufPool->inuse;
pMA
->
impl
=
pWrapper
;
pMA
->
malloc
=
vmaMaloocCb
;
pMA
->
calloc
=
NULL
;
pMA
->
realloc
=
NULL
;
pMA
->
free
=
NULL
;
pMA
->
usage
=
NULL
;
pma->impl = pvmaw;
pma->malloc = NULL;
pma->calloc = NULL; /* TODO */
pma->realloc = NULL; /* TODO */
pma->free = NULL; /* TODO */
pma->usage = NULL; /* TODO */
return pma;
return
pMA
;
}
static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma) { /* TODO */
SVnode * pVnode = (SVnode *)(pmaf->impl);
SListNode * pNode = ((SVMAWrapper *)(pma->impl))->pNode;
SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data);
if (T_REF_DEC(pvma) == 0) {
if (pvma->type == E_V_ARENA_ALLOCATOR) {
SVArenaAllocator *pvaa = &(pvma->vaa);
while (pvaa->inuse != &(pvaa->node)) {
SVArenaNode *pNode = pvaa->inuse;
pvaa->inuse = pNode->prev;
/* code */
}
pvaa->inuse->ptr = pvaa->inuse->data;
} else if (pvma->type == E_V_HEAP_ALLOCATOR) {
} else {
ASSERT(0);
}
static
void
vBufPoolDestroyMA
(
SMemAllocatorFactory
*
pMAF
,
SMemAllocator
*
pMA
)
{
SVMAWrapper
*
pWrapper
=
(
SVMAWrapper
*
)(
pMA
->
impl
);
SVnode
*
pVnode
=
pWrapper
->
pVnode
;
SVMemAllocator
*
pVMA
=
pWrapper
->
pVMA
;
// Move node from incycle to free
tdListAppendNode(&(pVnode->pBufPool->free), tdListPopNode(&(pVnode->pBufPool->incycle), pNode));
// tsem_post(); todo: sem_post
free
(
pMA
);
if
(
--
pVMA
->
_ref
.
val
==
0
)
{
tDListPop
(
&
(
pVnode
->
pBufPool
->
incycle
),
pVMA
);
tDListAppend
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
}
}
#endif
\ No newline at end of file
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录