diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index c53e771f42b9523edc3920b9a84f53f2f6bb123c..dfd0b680399d8656a3e5a8d164b32ba1d0e1d3e6 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -19,7 +19,7 @@ #include "tlog.h" #include "tname.h" -#define MALLOC_ALIGN_BYTES 32 +#define MALLOC_ALIGN_BYTES 256 int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) { ASSERT(pColumnInfoData != NULL); @@ -1191,7 +1191,6 @@ static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* int32_t oldLen = BitmapLen(existedRows); pColumn->nullbitmap = tmp; memset(&pColumn->nullbitmap[oldLen], 0, BitmapLen(numOfRows) - oldLen); - ASSERT(pColumn->info.bytes); // make sure the allocated memory is MALLOC_ALIGN_BYTES aligned @@ -1207,6 +1206,12 @@ static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* } pColumn->pData = tmp; + + // todo remove it soon +#if defined LINUX + ASSERT((((uint64_t)pColumn->pData) & (MALLOC_ALIGN_BYTES - 1)) == 0x0); +#endif + if (clearPayload) { memset(tmp + pColumn->info.bytes * existedRows, 0, pColumn->info.bytes * (numOfRows - existedRows)); } diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 93c43725867cb41835c98be67e49ed73b4af37aa..2032cb9fce1a533af161a5715cca0e165ce1dda9 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -129,6 +129,7 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, in void* pData = NULL; pGroupResInfo->pRows = taosArrayInit(10, POINTER_BYTES); + // todo avoid repeated malloc memory size_t keyLen = 0; int32_t iter = 0; while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) { diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 2bb38c16789b996a693016a7a692fb4653f4b5bb..e3436c83c1f50739d83295ace1deab49ccfca4c2 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -165,10 +165,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } - colDataDestroy(out.columnData); - taosMemoryFreeClear(out.columnData); - out.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); - + colInfoDataCleanup(out.columnData, out.numOfRows); cell = cell->pNext; } diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 2f30e8977afbfa6d691fed2cc8ab2c5b62752093..230ca5b9683dc26bdcd443235d7e329f489d3d35 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -351,7 +351,8 @@ void* taosMemoryMallocAlign(uint32_t alignment, int64_t size) { ASSERT(0); #else #if defined(LINUX) - return memalign(alignment, size); + void* p = memalign(alignment, size); + return p; #else return taosMemoryMalloc(size); #endif diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 0f4c51060bc1454fdef697255fa3174666c4c53b..37874ae250264dfe69a1669878fbe33ab9683e6d 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -30,6 +30,7 @@ struct SDiskbasedBuf { TdFilePtr pFile; int32_t allocateId; // allocated page id char* path; // file path + char* prefix; // file name prefix int32_t pageSize; // current used page size int32_t inMemPages; // numOfPages that are allocated in memory SList* freePgList; // free page list @@ -48,6 +49,12 @@ struct SDiskbasedBuf { }; static int32_t createDiskFile(SDiskbasedBuf* pBuf) { + if (pBuf->path == NULL) { // prepare the file name when needed it + char path[PATH_MAX] = {0}; + taosGetTmpfilePath(pBuf->prefix, "paged-buf", path); + pBuf->path = taosMemoryStrDup(path); + } + pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL); if (pBuf->pFile == NULL) { @@ -356,10 +363,7 @@ int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMem pPBuf->assistBuf = taosMemoryMalloc(pPBuf->pageSize + 2); // EXTRA BYTES pPBuf->all = taosHashInit(10, fn, true, false); - - char path[PATH_MAX] = {0}; - taosGetTmpfilePath(dir, "paged-buf", path); - pPBuf->path = strdup(path); + pPBuf->prefix = (char*) dir; pPBuf->emptyDummyIdList = taosArrayInit(1, sizeof(int32_t));