fix(meta/malloc): use new aligned buffer pool malloc
This commit is contained in:
parent
053f48e33a
commit
e302cb320f
|
@ -91,6 +91,7 @@ typedef struct SCommitInfo SCommitInfo;
|
||||||
|
|
||||||
// vnd.h
|
// vnd.h
|
||||||
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
|
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
|
||||||
|
void* vnodeBufPoolMallocAligned(SVBufPool* pPool, int size);
|
||||||
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
|
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
|
||||||
void vnodeBufPoolRef(SVBufPool* pPool);
|
void vnodeBufPoolRef(SVBufPool* pPool);
|
||||||
void vnodeBufPoolUnRef(SVBufPool* pPool);
|
void vnodeBufPoolUnRef(SVBufPool* pPool);
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
|
|
||||||
static FORCE_INLINE void *metaMalloc(void *pPool, size_t size) { return vnodeBufPoolMalloc((SVBufPool *)pPool, size); }
|
static FORCE_INLINE void *metaMalloc(void *pPool, size_t size) {
|
||||||
|
return vnodeBufPoolMallocAligned((SVBufPool *)pPool, size);
|
||||||
|
}
|
||||||
static FORCE_INLINE void metaFree(void *pPool, void *p) { vnodeBufPoolFree((SVBufPool *)pPool, p); }
|
static FORCE_INLINE void metaFree(void *pPool, void *p) { vnodeBufPoolFree((SVBufPool *)pPool, p); }
|
||||||
|
|
||||||
// begin a meta txn
|
// begin a meta txn
|
||||||
|
|
|
@ -123,6 +123,46 @@ void vnodeBufPoolReset(SVBufPool *pPool) {
|
||||||
pPool->ptr = pPool->node.data;
|
pPool->ptr = pPool->node.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *vnodeBufPoolMallocAligned(SVBufPool *pPool, int size) {
|
||||||
|
SVBufPoolNode *pNode;
|
||||||
|
void *p = NULL;
|
||||||
|
uint8_t *ptr = NULL;
|
||||||
|
int paddingLen = 0;
|
||||||
|
ASSERT(pPool != NULL);
|
||||||
|
|
||||||
|
if (pPool->lock) taosThreadSpinLock(pPool->lock);
|
||||||
|
|
||||||
|
ptr = pPool->ptr;
|
||||||
|
paddingLen = (((long)ptr + 7) & ~7) - (long)ptr;
|
||||||
|
|
||||||
|
if (pPool->node.size >= pPool->ptr - pPool->node.data + size + paddingLen) {
|
||||||
|
// allocate from the anchor node
|
||||||
|
p = pPool->ptr + paddingLen;
|
||||||
|
size += paddingLen;
|
||||||
|
pPool->ptr = pPool->ptr + size;
|
||||||
|
pPool->size += size;
|
||||||
|
} else {
|
||||||
|
// allocate a new node
|
||||||
|
pNode = taosMemoryMalloc(sizeof(*pNode) + size);
|
||||||
|
if (pNode == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
if (pPool->lock) taosThreadSpinUnlock(pPool->lock);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = pNode->data;
|
||||||
|
pNode->size = size;
|
||||||
|
pNode->prev = pPool->pTail;
|
||||||
|
pNode->pnext = &pPool->pTail;
|
||||||
|
pPool->pTail->pnext = &pNode->prev;
|
||||||
|
pPool->pTail = pNode;
|
||||||
|
|
||||||
|
pPool->size = pPool->size + sizeof(*pNode) + size;
|
||||||
|
}
|
||||||
|
if (pPool->lock) taosThreadSpinUnlock(pPool->lock);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
||||||
SVBufPoolNode *pNode;
|
SVBufPoolNode *pNode;
|
||||||
void *p = NULL;
|
void *p = NULL;
|
||||||
|
|
Loading…
Reference in New Issue