From 8761624574c817ed44b9289b182fbad5dde4c99b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 26 May 2017 16:02:00 -0400 Subject: [PATCH] os/bluestore: rebuild Buffer buffers with too much waste Avoid pinning extra memory by rebuilding Buffer buffers when we waste too much. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 13 ++++++++++--- src/os/bluestore/BlueStore.h | 13 +++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 647819486f22a..1552b3248e0a1 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1270,14 +1270,18 @@ int BlueStore::BufferSpace::_discard(Cache* cache, uint32_t offset, uint32_t len if (b->data.length()) { bufferlist bl; bl.substr_of(b->data, b->length - tail, tail); - _add_buffer(cache, new Buffer(this, b->state, b->seq, end, bl), 0, b); + Buffer *nb = new Buffer(this, b->state, b->seq, end, bl); + nb->maybe_rebuild(); + _add_buffer(cache, nb, 0, b); } else { - _add_buffer(cache, new Buffer(this, b->state, b->seq, end, tail), 0, b); + _add_buffer(cache, new Buffer(this, b->state, b->seq, end, tail), + 0, b); } if (!b->is_writing()) { cache->_adjust_buffer_size(b, front - (int64_t)b->length); } b->truncate(front); + b->maybe_rebuild(); cache->_audit("discard end 1"); break; } else { @@ -1286,6 +1290,7 @@ int BlueStore::BufferSpace::_discard(Cache* cache, uint32_t offset, uint32_t len cache->_adjust_buffer_size(b, front - (int64_t)b->length); } b->truncate(front); + b->maybe_rebuild(); ++i; continue; } @@ -1300,7 +1305,9 @@ int BlueStore::BufferSpace::_discard(Cache* cache, uint32_t offset, uint32_t len if (b->data.length()) { bufferlist bl; bl.substr_of(b->data, b->length - keep, keep); - _add_buffer(cache, new Buffer(this, b->state, b->seq, end, bl), 0, b); + Buffer *nb = new Buffer(this, b->state, b->seq, end, bl); + nb->maybe_rebuild(); + _add_buffer(cache, nb, 0, b); } else { _add_buffer(cache, new Buffer(this, b->state, b->seq, end, keep), 0, b); } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 5063395f95086..a9db4e509a509 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -49,6 +49,12 @@ class BlueFS; //#define DEBUG_CACHE //#define DEBUG_DEFERRED + + +// constants for Buffer::optimize() +#define MAX_BUFFER_SLOP_RATIO_DEN 8 // so actually 1/N + + enum { l_bluestore_first = 732430, l_bluestore_kv_flush_lat, @@ -210,6 +216,13 @@ public: } length = newlen; } + void maybe_rebuild() { + if (data.length() && + (data.get_num_buffers() > 1 || + data.front().wasted() > data.length() / MAX_BUFFER_SLOP_RATIO_DEN)) { + data.rebuild(); + } + } void dump(Formatter *f) const { f->dump_string("state", get_state_name(state)); -- 2.39.5