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

[PROBLEM] No custom memory allocator for msg can be provided #4125

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
4f84758
Implement a very simple zero-lock message pool to test performance gains
f18m Aug 13, 2019
ea0dc06
Merge branch 'master' of https://github.com/f18m/libzmq.git
f18m Aug 13, 2019
a24f2af
Allow to choose message sizes as well
f18m Aug 13, 2019
1bd2ae1
Allow using env variables to do some basic overriding
f18m Aug 13, 2019
252e8d4
fix typo
f18m Aug 13, 2019
4a30795
add TCP kernel socket buffer setting
f18m Aug 13, 2019
577232e
Merge remote-tracking branch 'upstream/master'
f18m Aug 25, 2019
ff8d79f
Merge remote-tracking branch 'upstream/master'
f18m Aug 28, 2019
00e514e
First implementation of global memory pool for ZMQ
f18m Aug 28, 2019
18c52c4
Remove changes related to graph generation
f18m Aug 28, 2019
a720a31
allow testing up to 8k msg sizes
f18m Aug 28, 2019
b9e1f01
correctly deallocate memory pool blocks
f18m Aug 30, 2019
1649701
fix build with no draft API
f18m Aug 30, 2019
0baafa4
never use allocator for VSM
f18m Aug 31, 2019
59cbfac
Merge branch 'master' of https://github.com/zeromq/libzmq into memory…
May 2, 2020
f0a7a7f
Fixes cmake build
May 2, 2020
f682600
Changes to base class with virtuals
May 2, 2020
3a3d877
Makes max message size dynamic
May 2, 2020
b416348
Dynamically grows mempool
May 2, 2020
cfd4c85
Updates dynamic global pool
May 3, 2020
1dd2304
Removes unnecessary class
May 3, 2020
d06f868
Adds new files to makefile
May 4, 2020
cfa228b
Adds concurrentqueue to sources
May 4, 2020
d96d616
Fixes some warnings
May 4, 2020
caf7798
Adds includes
May 4, 2020
5fbc4cc
Makes initial number of messages a bit more dynamic
May 5, 2020
d2c53c5
Hides global allocator implementation and option when C++11 not avail…
May 5, 2020
348865f
Fixes msvc __cplusplus reporting
May 5, 2020
59c6a6c
Improves <C++11 support
May 5, 2020
1f5abc1
Fixes missing declaration
May 5, 2020
2c29abc
Adds more c++11 guards
May 5, 2020
d7f9452
Adds test and moves queue to external
May 12, 2020
1450beb
Merge branch 'master' of https://github.com/zeromq/libzmq into memory…
May 12, 2020
f4973dc
Fixes bad path
May 12, 2020
3b9ec2f
Fixes bad path
May 12, 2020
a260668
Fixes formatting
May 12, 2020
7dafdf7
Adds destroy to test
May 13, 2020
a3bfc67
Fixes wrong increment
May 13, 2020
cd90418
Fixes bad c+11
May 13, 2020
a575335
Adds a basic concurrent queue
May 13, 2020
74dd371
Removes some debug code
May 13, 2020
e9c3a01
Adds newline and nullptr
May 13, 2020
aaa10dd
Adds a start on function pointer interface
May 13, 2020
77293ab
Adds missing free
May 13, 2020
1309316
Cleans up some includes
May 16, 2020
d666af8
Fixes bad options
May 16, 2020
73807f8
Moves to draft
May 16, 2020
ffcede1
Fixes formatting
May 16, 2020
312f8c3
Updates copyright years
May 16, 2020
bf495f8
Switches to new/delete
May 16, 2020
61870a4
Switches to alternative log2
May 16, 2020
c13f837
More copyright years
May 16, 2020
ea9c5dc
Fixes more formatting
May 16, 2020
20f49ec
Fixes more bad years
May 16, 2020
ba05e8f
Fixes some concurrency issues and bugs
May 17, 2020
afb858d
Merge branch 'master' into memorypool
Sep 19, 2020
32d827d
Adds destroy fn
Sep 19, 2020
84b4f8f
Adds destroy
Jan 16, 2021
633bf65
Removes pool allocator
Jan 17, 2021
cfd982d
Fixes delete
Jan 17, 2021
e7ad8b4
Fixes non-draft build
Jan 17, 2021
60a9cdf
Fixes formatting
Jan 18, 2021
ef4b77f
Inits group type
Jan 18, 2021
6edbcfd
Fix formatting as clang version mismatch between my install and CI
Jan 18, 2021
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
Prev Previous commit
Next Next commit
Switches to alternative log2
  • Loading branch information
Mark Jan van Kampen committed May 16, 2020
commit 61870a444eb9349fbf458032bed39296fbec8569
6 changes: 3 additions & 3 deletions src/allocator_global_pool.cpp
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ zmq::allocator_global_pool_t::~allocator_global_pool_t ()
// deallocate all message classes
for (size_t i = 0U; i < _storage.size (); i++) {
for (size_t j = 0U; j < _storage[i].raw_data.size (); j++) {
free (_storage[i].raw_data[j]);
operator delete (_storage[i].raw_data[j]);
_storage[i].raw_data[j] = NULL;
}
}
@@ -68,7 +68,7 @@ void zmq::allocator_global_pool_t::allocate_block (size_t bl)
_storage[i].num_msgs =
ZMG_GLOBAL_POOL_INITIAL_BLOCK_SIZE / msg_size;
_storage[i].raw_data.push_back (
(uint8_t *) malloc (_storage[i].num_msgs * msg_size));
(uint8_t *) operator new (_storage[i].num_msgs *msg_size));

uint8_t *msg_memory = _storage[i].raw_data[0];
for (size_t j = 0U; j < _storage[i].num_msgs; j++) {
@@ -87,7 +87,7 @@ void zmq::allocator_global_pool_t::expand_block (size_t bl)
size_t messagesToAdd = _storage[bl].num_msgs;
_storage[bl].num_msgs += messagesToAdd;
_storage[bl].raw_data.push_back (
(uint8_t *) malloc (messagesToAdd * msg_size));
(uint8_t *) operator new (messagesToAdd *msg_size));

uint8_t *msg_memory = _storage[bl].raw_data.back ();
_storage_mutex.unlock ();
30 changes: 8 additions & 22 deletions src/allocator_global_pool.hpp
Original file line number Diff line number Diff line change
@@ -104,32 +104,18 @@ class allocator_global_pool_t
return ZMQ_GLOBAL_POOL_FIRST_BLOCK_SIZE * 2 ^ block;
}

// by Todd Lehman https://stackoverflow.com/questions/994593/how-to-do-an-integer-log2-in-c
inline int uint64_log2 (uint64_t n)
{
#define S(k) \
if (n >= (UINT64_C (1) << k)) { \
i += k; \
n >>= k; \
}
assert (n != 0);
int i = 0;
S (32);
S (16);
S (8);
S (4);
S (2);
S (1);
return i;

#undef S
}

inline size_t BytesToMsgBlock (size_t n)
{
size_t block = 0;
if (n <= ZMQ_GLOBAL_POOL_FIRST_BLOCK_SIZE) {
return 0;
n = n / ZMQ_GLOBAL_POOL_FIRST_BLOCK_SIZE;
while (n > 0) {
block++;
n >>= 1;
}
}
return uint64_log2 (n / ZMQ_GLOBAL_POOL_FIRST_BLOCK_SIZE);
return block;
}
};
}