]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: implement buffer::list::reserve(n)
authorSage Weil <sage@redhat.com>
Wed, 7 Sep 2016 20:45:29 +0000 (16:45 -0400)
committerSage Weil <sage@redhat.com>
Wed, 7 Sep 2016 20:45:29 +0000 (16:45 -0400)
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>
src/include/buffer.h

index 6d77faee4304c2d25e2298e257db83810ab58dd4..ef0ccc15aefb112e32bb1cdb79a1987902dbb812 100644 (file)
@@ -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;