-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix memory leak for static_partitioner #1404
Open
pavelkumbrasev
wants to merge
3
commits into
master
Choose a base branch
from
dev/pavelkkumbrasev/fix_static_partitiner_mem_leak
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright (c) 2005-2023 Intel Corporation | ||
Copyright (c) 2005-2024 Intel Corporation | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -20,6 +20,7 @@ | |
#include "common/spin_barrier.h" | ||
#include "common/utils_concurrency_limit.h" | ||
#include "common/cpu_usertime.h" | ||
#include "common/memory_usage.h" | ||
|
||
#include "tbb/task.h" | ||
#include "tbb/task_group.h" | ||
|
@@ -840,3 +841,28 @@ TEST_CASE("Check correct arena destruction with enqueue") { | |
tbb::finalize(handle, std::nothrow_t{}); | ||
} | ||
} | ||
|
||
//! \brief \ref regression | ||
TEST_CASE("Check that memory does not leak with static_partitioner + global_control") { | ||
tbb::global_control gbl_ctrl{ tbb::global_control::max_allowed_parallelism, std::size_t(tbb::this_task_arena::max_concurrency() / 2) }; | ||
|
||
size_t current_memory_usage = 0, previous_memory_usage = 0, stability_counter = 0; | ||
bool no_memory_leak = false; | ||
std::size_t num_iterations = 100; | ||
for (std::size_t i = 0; i < num_iterations; ++i) { | ||
for (std::size_t j = 0; j < 100; ++j) { | ||
tbb::parallel_for(0, 1000, [] (int) {}, tbb::static_partitioner{}); | ||
} | ||
|
||
current_memory_usage = utils::GetMemoryUsage(); | ||
stability_counter = current_memory_usage==previous_memory_usage ? stability_counter + 1 : 0; | ||
// If the amount of used memory has not changed during 5% of executions, | ||
// then we can assume that the check was successful | ||
if (stability_counter > num_iterations / 20) { | ||
no_memory_leak = true; | ||
break; | ||
} | ||
previous_memory_usage = current_memory_usage; | ||
} | ||
REQUIRE_MESSAGE(no_memory_leak, "Seems we get memory leak here."); | ||
Comment on lines
+847
to
+867
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. Wrap it into the loop with gradual decrease of the std::size_t current_limit = std::size_t(tbb::this_task_arena::max_concurrency());
while (current_limit /= 2) {
tbb::global_control gc{ tbb::global_control::max_allowed_parallelism, current_limit };
// iterations loop goes here {
// repetitions loop goes here {
// }
// }
} |
||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks a little bit clumsy, don't you think? Does it make sense to move calculation of
maximum_arena_concurrency
into some dedicated function that could be reused inget_initial_auto_partitioner_divisor
as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. if need to introduce new method for these 2 lines. (we check not arena concurrency
min(arena_concurrency, allowed_concurrency)
but rather available amount of workers).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to move it into something like
get_num_possible_workers()
to highlight that the solution is based on the immediate value of workers asstd::min(...)
does not mean much to reader.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove from affinity