提交 611ab8b3 编写于 作者: H Haojun Liao

refactor: make sure the memory is aligned to 32 bytes.

上级 b70a616a
......@@ -37,6 +37,7 @@ void taosMemoryFree(void *ptr);
int64_t taosMemorySize(void *ptr);
void taosPrintBackTrace();
void taosMemoryTrim(int32_t size);
void *taosMemoryMallocAlign(uint32_t alignment, int64_t size);
#define taosMemoryFreeClear(ptr) \
do { \
......
......@@ -19,6 +19,8 @@
#include "tlog.h"
#include "tname.h"
#define MALLOC_ALIGN_BYTES 32
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) {
ASSERT(pColumnInfoData != NULL);
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
......@@ -1163,6 +1165,7 @@ static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo*
pColumn->varmeta.offset = (int32_t*)tmp;
memset(&pColumn->varmeta.offset[existedRows], 0, sizeof(int32_t) * (numOfRows - existedRows));
} else {
// prepare for the null bitmap
char* tmp = taosMemoryRealloc(pColumn->nullbitmap, BitmapLen(numOfRows));
if (tmp == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
......@@ -1173,11 +1176,19 @@ static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo*
memset(&pColumn->nullbitmap[oldLen], 0, BitmapLen(numOfRows) - oldLen);
ASSERT(pColumn->info.bytes);
tmp = taosMemoryRealloc(pColumn->pData, numOfRows * pColumn->info.bytes);
// make sure the allocated memory is MALLOC_ALIGN_BYTES aligned
tmp = taosMemoryMallocAlign(MALLOC_ALIGN_BYTES, numOfRows * pColumn->info.bytes);
if (tmp == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
// copy back the existed data
if (pColumn->pData != NULL) {
memcpy(tmp, pColumn->pData, existedRows * pColumn->info.bytes);
taosMemoryFreeClear(pColumn->pData);
}
pColumn->pData = tmp;
if (clearPayload) {
memset(tmp + pColumn->info.bytes * existedRows, 0, pColumn->info.bytes * (numOfRows - existedRows));
......
......@@ -271,67 +271,6 @@ static int16_t i16VectorCmpAVX2(const int16_t* pData, int32_t numOfRows, bool is
return v;
}
//static int64_t i64VectorCmpAVX2(const int64_t* pData, int32_t numOfRows, bool isMinFunc) {
// int64_t v = 0;
// const int32_t bitWidth = 256;
// const int64_t* p = pData;
//
// int32_t width = (bitWidth>>3u) / sizeof(int64_t);
// int32_t remain = numOfRows % width;
// int32_t rounds = numOfRows / width;
//
//#if __AVX2__
// __m256i next;
// __m256i initialVal = _mm256_loadu_si256((__m256i*)p);
// p += width;
//
// if (!isMinFunc) { // max function
// for (int32_t i = 0; i < rounds; ++i) {
// next = _mm256_lddqu_si256((__m256i*)p);
// initialVal = _mm256_max_epi64(initialVal, next);
// p += width;
// }
//
// // let sum up the final results
// const int64_t* q = (const int64_t*)&initialVal;
// v = TMAX(q[0], q[1]);
// for(int32_t k = 1; k < width; ++k) {
// v = TMAX(v, q[k]);
// }
//
// // calculate the front and the reminder items in array list
// int32_t start = rounds * width;
// for (int32_t j = 0; j < remain; ++j) {
// if (v < p[j + start]) {
// v = p[j + start];
// }
// }
// } else { // min function
// for (int32_t i = 0; i < rounds; ++i) {
// next = _mm256_lddqu_si256((__m256i*)p);
// initialVal = _mm256_min_epi64(initialVal, next);
// p += width;
// }
//
// // let sum up the final results
// const int64_t* q = (const int64_t*)&initialVal;
// v = TMIN(q[0], q[1]);
// for(int32_t k = 1; k < width; ++k) {
// v = TMIN(v, q[k]);
// }
//
// // calculate the front and the remainder items in array list
// int32_t start = rounds * width;
// for (int32_t j = 0; j < remain; ++j) {
// if (v > p[j + start]) {
// v = p[j + start];
// }
// }
// }
//#endif
//
// return v;
//}
static int32_t handleInt32Col(SColumnInfoData* pCol, int32_t start, int32_t numOfRows, SqlFunctionCtx* pCtx,
SMinmaxResInfo* pBuf, bool isMinFunc) {
......
......@@ -345,3 +345,11 @@ void taosMemoryTrim(int32_t size) {
malloc_trim(size);
#endif
}
void* taosMemoryMallocAlign(uint32_t alignment, int64_t size) {
#ifdef USE_TD_MEMORY
ASSERT(0);
#else
return memalign(alignment, size);
#endif
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册