mirror of
https://github.com/ceph/ceph
synced 2025-02-19 17:08:05 +00:00
buffer: implement buffer::list::reserve(n)
Make sure we have N bytes of append_buffer reserved. On a new or cleared list, this allocates exactly that much runway, allowing us to control memory usage. Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
9cd042a566
commit
9035883c33
@ -387,8 +387,7 @@ namespace buffer CEPH_BUFFER_API {
|
||||
list() : _len(0), _memcopy_count(0), last_p(this) {}
|
||||
// cppcheck-suppress noExplicitConstructor
|
||||
list(unsigned prealloc) : _len(0), _memcopy_count(0), last_p(this) {
|
||||
append_buffer = buffer::create(prealloc);
|
||||
append_buffer.set_length(0); // unused, so far.
|
||||
reserve(prealloc);
|
||||
}
|
||||
|
||||
list(const list& other) : _buffers(other._buffers), _len(other._len),
|
||||
@ -500,6 +499,13 @@ namespace buffer CEPH_BUFFER_API {
|
||||
unsigned align_memory);
|
||||
bool rebuild_page_aligned();
|
||||
|
||||
void reserve(size_t prealloc) {
|
||||
if (append_buffer.unused_tail_length() < prealloc) {
|
||||
append_buffer = buffer::create(prealloc);
|
||||
append_buffer.set_length(0); // unused, so far.
|
||||
}
|
||||
}
|
||||
|
||||
// assignment-op with move semantics
|
||||
const static unsigned int CLAIM_DEFAULT = 0;
|
||||
const static unsigned int CLAIM_ALLOW_NONSHAREABLE = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user