Skip to content

Cascaded allocator #2113

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

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bd320b1
can compiled successfully on Windows Plat
smithAchang Sep 3, 2023
37dc8f4
Allocator_Cascaded_Test.cpp增加
smithAchang Sep 3, 2023
c61b9be
add the 2*sum(Allocator of hierarchy) testing case
smithAchang Sep 4, 2023
6166f88
bin/fuzz.pl find trailing whitespace
smithAchang Sep 4, 2023
32d3d1f
bin/fuzz.pl find trailing whitespace 2
smithAchang Sep 4, 2023
e2a5511
compiler error
smithAchang Sep 4, 2023
6835890
dsfdsdfMerge branch 'cascadedAllocator' of github.com:smithAchang/ACE…
smithAchang Sep 4, 2023
150eb7b
use std::vector
smithAchang Sep 4, 2023
089af45
linux compiling error & fix issue
smithAchang Sep 5, 2023
ac87bd4
according the routine of test framework
smithAchang Sep 5, 2023
b71f82d
key design comment for free API
smithAchang Sep 5, 2023
34abb6e
fix space indent & const member field
smithAchang Sep 5, 2023
cf39680
using instead of typedef, will be fitter for template declaration
smithAchang Sep 5, 2023
78e7165
remove duplicate empty lines
smithAchang Sep 5, 2023
e5e55bc
free protected when malloc in constructor failed
smithAchang Sep 5, 2023
00016bf
1. add assert for free API
smithAchang Sep 5, 2023
912d9db
add comments for ACE_NEW fail in constructor
smithAchang Sep 6, 2023
833bc87
Merge branch 'master' into cascadedAllocator
smithAchang Sep 6, 2023
40675b0
fix ""One line, indent is always 2 spaces
smithAchang Sep 7, 2023
148734d
Merge branch 'cascadedAllocator' of github.com:smithAchang/ACE_TAO in…
smithAchang Sep 7, 2023
6e9a17c
for g++ -fno-implicit-templates consideration
smithAchang Sep 8, 2023
d065069
implement the dump API
smithAchang Sep 16, 2023
eba85a4
fix for statement of dump API
smithAchang Sep 16, 2023
1e1862d
fix trailing whitespace
smithAchang Sep 16, 2023
0f26ecb
add hierarchy_.size () for dump API
smithAchang Sep 18, 2023
4a7fcd0
1、fix some coding style using this keyword to distinguish vars
smithAchang Sep 22, 2023
cf686b3
add the pool_sum api
smithAchang Sep 22, 2023
4c27ab0
1、fix constructor description
smithAchang Sep 23, 2023
8210ac0
1、split ACE_NEW* with empty line, the macro function may end the flow
smithAchang Sep 23, 2023
e8d9b51
1、fix unsupported API return nullptr
smithAchang Sep 25, 2023
63e543f
add deeply test case for calloc API
smithAchang Sep 26, 2023
d4e7d14
modify growth strategy to exponential growth when hierarchy grows fo…
smithAchang Sep 29, 2023
874d9cb
keep the consistent to cascaded malloc branch
smithAchang Sep 29, 2023
92066a1
add exception safety for the growth of chunk sum
smithAchang Sep 29, 2023
4a9c114
fix the exception safety for calling vector push_back API
smithAchang Sep 29, 2023
8450156
Using std::unique_ptr will be more exception-safe literally
smithAchang Sep 29, 2023
0c8067c
delete defence codes
smithAchang Sep 29, 2023
cc4053c
delete unused temp stack var
smithAchang Sep 29, 2023
ac5f611
fix invalid document of class
smithAchang Sep 29, 2023
fec93be
fix coding style of comment
smithAchang Oct 8, 2023
42b409e
fix for right const coding style
smithAchang Oct 8, 2023
a837b5d
format using clang-format
smithAchang Oct 8, 2023
c9ead44
fix for coding style of function call
smithAchang Oct 8, 2023
021ef62
optimization for cascaded allocator considering the character that on…
smithAchang Jan 13, 2024
92c3499
Merge branch 'master' into cascadedAllocator
smithAchang Jan 13, 2024
b84e0c4
modify the branch judgement of the last allocator using const var
smithAchang Apr 4, 2024
58da8c3
Merge branch 'master' into cascadedAllocator
jwillemsen Feb 4, 2025
818c631
fix coderabbitai's refactor suggestions
smithAchang Feb 11, 2025
76ceba9
Merge branch 'cascadedAllocator' of github.com:smithAchang/ACE_TAO in…
smithAchang Feb 11, 2025
c19e903
Merge branch 'master' into cascadedAllocator
smithAchang Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions ACE/ace/Malloc_T.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,16 @@ ACE_Cascaded_Dynamic_Cached_Allocator<ACE_LOCK>::ACE_Cascaded_Dynamic_Cached_All
// If ACE_NEW fails, the hierarchy_ will be reconstructed when malloc API is called.
ACE_NEW (tmp, comb_alloc_type(this->initial_n_chunks_, this->chunk_size_));

// Increase the chunk sum if succeed.
this->chunk_sum_ += tmp->pool_depth();
// Consider the exception of vector push_back call
this->hierarchy_.push_back(tmp);
if (0 == this->hierarchy_.size())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when push_back fails it will throw, maybe use std::unique_ptr?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These APIs have strong exception safety guarantee, so there is no need to use std::unique_ptr.

Is it true ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I can see the result of these calls to judge whether potential exceptions have occurred

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://en.cppreference.com/w/cpp/language/exceptions, push_back can throw, when it does the state of the std::vector is guaranteed at that moment, but it will not just return. The exception should go back to the caller to my idea, your allocator should not leak when push_back (or any operation it uses) throws

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when using unique_ptr the check after the push_back seems invalid

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used std::unique_ptr for idiom in new commit

But for a vector of pointer, I think sdt::vector can keep strong exception guarantee.

If an exception is thrown (which can be due to Allocator::allocate() or element copy/move constructor/assignment), this > function has no effect ([strong exception guarantee]> (https://en.cppreference.com/w/cpp/language/exceptions#Exception_safety)).


Strong exception guarantee — If the function throws an exception, the state of the program is rolled back to the state > just before the function call (for example, [std::vector::push_back]>(https://en.cppreference.com/w/cpp/container/vector/push_back)).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, Your idea is right!

The APIs provide strong exception guarantee, but not Nothrow

I will delete the defence codes

{
delete tmp;
return;
}

// Increase the chunk sum if all points having potential risk of exception is passed.
this->chunk_sum_ += tmp->pool_depth ();
}

template <class ACE_LOCK>
Expand Down Expand Up @@ -227,11 +234,21 @@ ACE_Cascaded_Dynamic_Cached_Allocator<ACE_LOCK>::malloc (size_t nbytes)
if(ptr == nullptr)
{
comb_alloc_ptr tmp;
ACE_NEW_RETURN (tmp, comb_alloc_type(this->initial_n_chunks_ * 2 * this->hierarchy_.size(), this->chunk_size_), nullptr);
ACE_NEW_RETURN (tmp, comb_alloc_type(this->initial_n_chunks_ * (1 << this->hierarchy_.size()),
this->chunk_size_),
nullptr);

// Increase the chunk sum if succeed.
this->chunk_sum_ += tmp->pool_depth();
// Consider the exception of vector push_back call
const auto old_size = this->hierarchy_.size();
this->hierarchy_.push_back(tmp);
if (old_size == this->hierarchy_.size())
{
delete tmp;
return nullptr;
}

// Increase the chunk sum if all points having potential risk of exception is passed.
this->chunk_sum_ += tmp->pool_depth ();
ptr = tmp->malloc(nbytes);
}

Expand Down
5 changes: 3 additions & 2 deletions ACE/tests/Allocator_Cascaded_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ do \
{ \
if (expression) \
{ \
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (message)), 1);\
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT_CHAR_TO_TCHAR (message)), 1);\
} \
} \
while (0)
Expand Down Expand Up @@ -84,7 +84,8 @@ run_cascaded_allocator_test ()
ptr1 = alloc.malloc (nbytes);
ACE_TEST_EXCEPTION_RETURN (ptr1 == nullptr,
" pool must return valid ptr, cascaded pool must support to alloc more times secondly\n");
ACE_TEST_EXCEPTION_RETURN (alloc.pool_depth () != 1,
pool_depth = alloc.pool_depth ();
ACE_TEST_EXCEPTION_RETURN (pool_depth != 1,
" cascaded pool depth must support to alloc twice\n");

old_pool_depth = alloc.pool_depth();
Expand Down