[CP] DecoderCtx optimizing memory fragmentation.

This commit is contained in:
obdev
2023-04-20 04:41:31 +00:00
committed by ob-robot
parent d3f25346dd
commit 9f8e92e0ec

View File

@ -70,17 +70,18 @@ class ObDecoderCtxArray
{ {
public: public:
typedef ObColumnDecoderCtx ObDecoderCtx; typedef ObColumnDecoderCtx ObDecoderCtx;
ObDecoderCtxArray() {}; explicit ObDecoderCtxArray(ObIAllocator &allocator): ctxs_(), allocator_(&allocator) {};
virtual ~ObDecoderCtxArray() virtual ~ObDecoderCtxArray()
{ {
FOREACH(it, ctxs_) { FOREACH(it, ctxs_) {
ObDecoderCtx *c = *it; ObDecoderCtx *c = *it;
OB_DELETE(ObDecoderCtx, ObModIds::OB_SSTABLE_READER, c); c->~ObDecoderCtx();
allocator_->free(c);
} }
ctxs_.reset(); ctxs_.reset();
} }
TO_STRING_KV(K_(ctxs)); TO_STRING_KV(K_(ctxs), KP_(allocator));
ObDecoderCtx **get_ctx_array(int64_t size) ObDecoderCtx **get_ctx_array(int64_t size)
{ {
@ -92,13 +93,14 @@ public:
} else { } else {
if (ctxs_.size() < size) { if (ctxs_.size() < size) {
for (int64_t i = ctxs_.size(); OB_SUCC(ret) && i < size; ++i) { for (int64_t i = ctxs_.size(); OB_SUCC(ret) && i < size; ++i) {
ObDecoderCtx *ctx = OB_NEW(ObDecoderCtx, ObModIds::OB_SSTABLE_READER); ObDecoderCtx *ctx = nullptr;
if (NULL == ctx) { if (OB_ISNULL(ctx = OB_NEWx(ObDecoderCtx, allocator_))) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("alloc memory failed", K(ret)); LOG_WARN("alloc memory failed", K(ret));
} else if (OB_FAIL(ctxs_.push_back(ctx))) { } else if (OB_FAIL(ctxs_.push_back(ctx))) {
LOG_WARN("array push back failed", K(ret)); LOG_WARN("array push back failed", K(ret));
OB_DELETE(ObDecoderCtx, ObModIds::OB_SSTABLE_READER, ctx); ctx->~ObDecoderCtx();
allocator_->free(ctx);
} }
} }
if (OB_SUCC(ret)) { if (OB_SUCC(ret)) {
@ -113,6 +115,7 @@ public:
private: private:
ObArray<ObDecoderCtx *> ctxs_; ObArray<ObDecoderCtx *> ctxs_;
ObIAllocator *allocator_;
DISALLOW_COPY_AND_ASSIGN(ObDecoderCtxArray); DISALLOW_COPY_AND_ASSIGN(ObDecoderCtxArray);
}; };
@ -123,14 +126,12 @@ ObColumnDecoderCtx ObMicroBlockDecoder::none_exist_column_decoder_ctx_;
class ObTLDecoderCtxArray class ObTLDecoderCtxArray
{ {
public: public:
ObTLDecoderCtxArray() {} ObTLDecoderCtxArray(): ctxs_array_(), allocator_("TLDecoderCtx") {}
virtual ~ObTLDecoderCtxArray() virtual ~ObTLDecoderCtxArray()
{ {
FOREACH(it, ctxs_array_) { ctxs_array_.reset();
ObDecoderCtxArray *ctxs = *it; allocator_.reset();
OB_DELETE(ObDecoderCtxArray, ObModIds::OB_SSTABLE_READER, ctxs);
}
} }
static ObDecoderCtxArray *alloc() static ObDecoderCtxArray *alloc()
@ -142,8 +143,7 @@ public:
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("NULL instance", K(ret)); LOG_WARN("NULL instance", K(ret));
} else if (tl_array->ctxs_array_.empty()) { } else if (tl_array->ctxs_array_.empty()) {
ctxs = OB_NEW(ObDecoderCtxArray, ObModIds::OB_SSTABLE_READER); if (OB_ISNULL(ctxs = OB_NEWx(ObDecoderCtxArray, (&tl_array->allocator_), tl_array->allocator_))) {
if (NULL == ctxs) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("alloc memory failed", K(ret)); LOG_WARN("alloc memory failed", K(ret));
} }
@ -165,7 +165,8 @@ public:
// do nothing // do nothing
} else if (OB_FAIL(tl_array->ctxs_array_.push_back(ctxs))) { } else if (OB_FAIL(tl_array->ctxs_array_.push_back(ctxs))) {
LOG_WARN("array push back failed", K(ret)); LOG_WARN("array push back failed", K(ret));
OB_DELETE(ObDecoderCtxArray, ObModIds::OB_SSTABLE_READER, ctxs); ctxs->~ObDecoderCtxArray();
tl_array->allocator_.free(ctxs);
} }
} }
@ -174,6 +175,7 @@ private:
private: private:
ObArray<ObDecoderCtxArray *> ctxs_array_; ObArray<ObDecoderCtxArray *> ctxs_array_;
ObArenaAllocator allocator_;
DISALLOW_COPY_AND_ASSIGN(ObTLDecoderCtxArray); DISALLOW_COPY_AND_ASSIGN(ObTLDecoderCtxArray);
}; };