From: Sage Weil Date: Wed, 7 Sep 2016 20:45:29 +0000 (-0400) Subject: buffer: implement buffer::list::reserve(n) X-Git-Tag: v11.0.1~298^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9035883c339219003eed8cec8d0147a36525918d;p=ceph.git 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 --- diff --git a/src/include/buffer.h b/src/include/buffer.h index 6d77faee4304..ef0ccc15aefb 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -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;