-
Notifications
You must be signed in to change notification settings - Fork 6
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
[update] reduce chainbase memory usage #19
Conversation
When using 42 bit offsets as pointers in `undo_index`, the existing test using `std::allocator` was failing (as 64 bit pointers were truncated to 42 bits). This uses `chainbase_node_allocator` (which uses `bip::offset_ptr<T>` as pointers), which when truncated to 42 bits allow to address 2TB of memory.
since the offset values are shifted by 3 bits, is it possible to collide with the special value 1 which is re-purposed for representing nullptr? |
No, I don't think so. I explained why in the comment:
Do you think I missed a possible issue?
Striking the comment above, because we store offsets between |
ah i see. that's a good catch. thanks! |
@taokayan how did you measure memory usage showing the 20% reduction? |
you can use the db_size plugin API: http://127.0.0.1:8888/v1/db_size/get |
… a 4 byte alignment.
return static_cast<hook<index0_type, Allocator>&>(to_node(obj))._color; | ||
} | ||
static void set_removed_field(const value_type& obj, int val) { | ||
static_cast<hook<index0_type, Allocator>&>(to_node(obj))._color = val; | ||
} |
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 like this change.
// A concern could be that `1` is a special value meaning `nullptr`. However we could not | ||
// get an offset of 4, since `sizeof(offset_node_base) == 16`, so we could not have | ||
// difference between two different `node_ptr` be less than 16. | ||
// -------------------------------------------------------------------------------------- |
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.
Did you run any performance comparisons with these changes?
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.
No, I didn't. Do you know of a good way to make a performance comparison? Maybe it would require to write a small benchmarking test.
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.
You could write one I suppose, but you could also just do a replay comparison of some range of blocks.
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 think I'll write a small test.
[alternate from PR 14 by @taokayan, description copied]. This builds upon @taokayan's work.
Reduce offset_node_base memory usage inside the RBtree of chainbase
This PR will reduce the chainbase memory usage
old implementation:
_parent
,_left
,_right
,_color
consume 32 bytes together (8 bytes each).new implementation
_parent
,_left
,_right
,_color
consume 16 bytes (42 + 42 + 42 + 2 bits) together.erased_flag
since _color is a 2 bit signed int.limitations:
_parent
,_left
&_right
only have signed 42-bit each (so 41-bit absolute value), shifted by two bits thanks to alignment, implying a maximum of chainbase size of 2^43 = 8TB.offset_node_base
objects must always be allocated within the same segment due to the 42-bit offset limit. Using a stack variable ofoffset_node_base
is no longer valid (as stack address starts from 0x7fffxxxxxxxx which is too far away from heap addresses).tested results:
using mainnet snapshot snapshot-308122667.bin.tar.gz:
28799134736
23136280976
(around 20% reduction)[greg 8/21/2023] retested with the current PR version and confirmed the memory savings as reported by
curl -X POST http://127.0.0.1:8888/v1/db_size/get
after loading snapshot.