Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement](mem-tracker) Use thread local mem tracker to track s3 file buffer memory usage #40597

Merged
merged 7 commits into from
Sep 26, 2024
Merged
6 changes: 3 additions & 3 deletions be/src/io/fs/s3_file_bufferpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ FileBuffer::FileBuffer(BufferType type, std::function<FileBlocksHolderPtr()> all
_size(0),
_state(std::move(state)),
_inner_data(std::make_unique<FileBuffer::PartData>()),
_capacity(_inner_data->size()) {}
_capacity(_inner_data->size()),
_mem_tracker(doris::thread_context()->thread_mem_tracker_mgr->limiter_mem_tracker()) {}

FileBuffer::~FileBuffer() {
SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(ExecEnv::GetInstance()->s3_file_buffer_tracker());
SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(_mem_tracker);
_inner_data.reset();
}

Expand Down Expand Up @@ -240,7 +241,6 @@ FileBufferBuilder& FileBufferBuilder::set_allocate_file_blocks_holder(
}

Status FileBufferBuilder::build(std::shared_ptr<FileBuffer>* buf) {
SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(ExecEnv::GetInstance()->s3_file_buffer_tracker());
OperationState state(_sync_after_complete_task, _is_cancelled);

if (_type == BufferType::UPLOAD) {
Expand Down
2 changes: 2 additions & 0 deletions be/src/io/fs/s3_file_bufferpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "common/status.h"
#include "io/cache/file_block.h"
#include "runtime/memory/mem_tracker_limiter.h"
#include "util/crc32c.h"
#include "util/slice.h"
#include "util/threadpool.h"
Expand Down Expand Up @@ -127,6 +128,7 @@ struct FileBuffer {
struct PartData;
std::unique_ptr<PartData> _inner_data;
size_t _capacity;
std::shared_ptr<MemTrackerLimiter> _mem_tracker;
};

struct DownloadFileBuffer final : public FileBuffer {
Expand Down
Loading