-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feature-wip] (memory tracker) (step1) Refactor impl of MemTracker, and related use #8322
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ HashTable::HashTable(const std::vector<ExprContext*>& build_expr_ctxs, | |
| _buckets.resize(num_buckets); | ||
| _num_buckets = num_buckets; | ||
| _num_buckets_till_resize = MAX_BUCKET_OCCUPANCY_FRACTION * _num_buckets; | ||
| _mem_tracker->Consume(_buckets.capacity() * sizeof(Bucket)); | ||
| _mem_tracker->consume(_buckets.capacity() * sizeof(Bucket)); | ||
|
|
||
| // Compute the layout and buffer size to store the evaluated expr results | ||
| _results_buffer_size = Expr::compute_results_layout( | ||
|
|
@@ -70,7 +70,7 @@ HashTable::HashTable(const std::vector<ExprContext*>& build_expr_ctxs, | |
| _alloc_list.push_back(_current_nodes); | ||
| _end_list.push_back(_current_nodes + _current_capacity * _node_byte_size); | ||
|
|
||
| _mem_tracker->Consume(_current_capacity * _node_byte_size); | ||
| _mem_tracker->consume(_current_capacity * _node_byte_size); | ||
| if (_mem_tracker->limit_exceeded()) { | ||
| mem_limit_exceeded(_current_capacity * _node_byte_size); | ||
| } | ||
|
|
@@ -85,8 +85,8 @@ void HashTable::close() { | |
| for (auto ptr : _alloc_list) { | ||
| free(ptr); | ||
| } | ||
| _mem_tracker->Release(_total_capacity * _node_byte_size); | ||
| _mem_tracker->Release(_buckets.size() * sizeof(Bucket)); | ||
| _mem_tracker->release(_total_capacity * _node_byte_size); | ||
| _mem_tracker->release(_buckets.size() * sizeof(Bucket)); | ||
| } | ||
|
|
||
| bool HashTable::eval_row(TupleRow* row, const std::vector<ExprContext*>& ctxs) { | ||
|
|
@@ -180,7 +180,7 @@ Status HashTable::resize_buckets(int64_t num_buckets) { | |
|
|
||
| int64_t old_num_buckets = _num_buckets; | ||
| int64_t delta_bytes = (num_buckets - old_num_buckets) * sizeof(Bucket); | ||
| Status st = _mem_tracker->TryConsume(delta_bytes); | ||
| Status st = _mem_tracker->try_consume(delta_bytes); | ||
| if (!st) { | ||
| LOG_EVERY_N(WARNING, 100) << "resize bucket failed: " << st.to_string(); | ||
| mem_limit_exceeded(delta_bytes); | ||
|
|
@@ -244,7 +244,7 @@ void HashTable::grow_node_array() { | |
| _alloc_list.push_back(_current_nodes); | ||
| _end_list.push_back(_current_nodes + alloc_size); | ||
|
|
||
| _mem_tracker->Consume(alloc_size); | ||
| _mem_tracker->consume(alloc_size); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are many codes call mem_tracker->somsume(size_t), Is there a better method to do this automatically? /// Implementation of std::allocator interface that tracks memory with MemoryTracker. template
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yiguolei I've done something similar with reference to clickhouse to automatically track memory usage via TCMalloc Hook Different from Jemalloc, overloading the TCMalloc new/delete operator needs to invade the source code of TCMalloc, so it is implemented by Hook;
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are too many places call memory tracker and we may lost to add mem_tracker.consume in some node or thread. If we are following clickhouse's method, I think it do not need to call memory tracker everywhere and call mem tracker.consume so many times. We could attach the running thread to a conext, the context maybe a query context or a compaction context or olap scanner. And rewrite the new and delete method to update the memory tracker automatically.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is done by following next PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You are right, I have already implemented it like this. In #7198 mentioned above, |
||
| if (_mem_tracker->limit_exceeded()) { | ||
| mem_limit_exceeded(alloc_size); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.