-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Feature] Use mem_pool property to create shared mem_tracker across resource groups #64112
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
Merged
murphyatwork
merged 9 commits into
StarRocks:main
from
martinr0x:mbogusz/use-mem-pool-be
Nov 12, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c7ad224
use mem_pool to obtain shared mem_tracker
martinr0x cc12965
use mem_pool property to select mem_tracker
martinr0x 1c22cfa
rename test
martinr0x 23e39e4
add license
martinr0x daa6068
use full path
martinr0x 06f9618
format test file
martinr0x 6e349f6
format
martinr0x c1b8483
make error message more descriptive
martinr0x 9f41d21
change uin64_t to int64_t in mem_tracker_manager.cpp
martinr0x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "mem_tracker_manager.h" | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "runtime/exec_env.h" | ||
| #include "runtime/mem_tracker.h" | ||
| #include "work_group.h" | ||
|
|
||
| namespace starrocks::workgroup { | ||
| MemTrackerManager::MemTrackerPtr MemTrackerManager::get_parent_mem_tracker(const WorkGroupPtr& wg) { | ||
| if (WorkGroup::DEFAULT_MEM_POOL == wg->mem_pool()) { | ||
| return GlobalEnv::GetInstance()->query_pool_mem_tracker_shared(); | ||
| } | ||
|
|
||
| const double mem_limit_fraction = wg->mem_limit(); | ||
| const int64_t memory_limit_bytes = | ||
| static_cast<int64_t>(GlobalEnv::GetInstance()->query_pool_mem_tracker()->limit() * mem_limit_fraction); | ||
|
|
||
| // Frontend (FE) validation ensures that active resource groups (RGs) sharing | ||
| // the same mem_pool also have the same mem_limit. | ||
| if (_shared_mem_trackers.contains(wg->mem_pool())) { | ||
| // We must handle an edge case: | ||
| // 1. All RGs using a specific mem_pool are deleted. | ||
| // 2. The shared tracker for that pool remains cached here. | ||
| // 3. A new RG is created with the same mem_pool name but a different mem_limit. | ||
| // Therefore, we must verify the cached tracker's limit matches the current RG's limit. | ||
| if (auto& shared_mem_tracker = _shared_mem_trackers.at(wg->mem_pool()); | ||
| shared_mem_tracker->limit() == memory_limit_bytes) { | ||
| return shared_mem_tracker; | ||
| } | ||
| } | ||
|
|
||
| auto shared_mem_tracker = | ||
| std::make_shared<MemTracker>(MemTrackerType::RESOURCE_GROUP_SHARED_MEMORY_POOL, memory_limit_bytes, | ||
| wg->mem_pool(), GlobalEnv::GetInstance()->query_pool_mem_tracker()); | ||
|
|
||
| _shared_mem_trackers.insert_or_assign(wg->mem_pool(), shared_mem_tracker); | ||
murphyatwork marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return shared_mem_tracker; | ||
| } | ||
| } // namespace starrocks::workgroup | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
martinr0x marked this conversation as resolved.
Show resolved
Hide resolved
martinr0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include <memory> | ||
|
|
||
| #include "runtime/mem_tracker.h" | ||
| #include "work_group_fwd.h" | ||
|
|
||
| namespace starrocks::workgroup { | ||
| struct MemTrackerManager { | ||
| public: | ||
| using MemTrackerPtr = std::shared_ptr<MemTracker>; | ||
| MemTrackerPtr get_parent_mem_tracker(const WorkGroupPtr& wg); | ||
murphyatwork marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| std::unordered_map<std::string, MemTrackerPtr> _shared_mem_trackers{}; | ||
| }; | ||
| } // namespace starrocks::workgroup | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.