From: Sage Weil Date: Wed, 22 Jun 2016 14:30:22 +0000 (-0400) Subject: os/bluestore: discard unreferenced buffers as they are overwritten X-Git-Tag: v11.0.0~80^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F9827%2Fhead;p=ceph.git os/bluestore: discard unreferenced buffers as they are overwritten Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 0626097537fd..506db30ca353 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -813,6 +813,22 @@ bool BlueStore::OnodeSpace::map_any(std::function f) } +// Blob + +#undef dout_prefix +#define dout_prefix *_dout << "bluestore.blob(" << this << ") " + +void BlueStore::Blob::discard_unallocated() +{ + size_t pos = 0; + for (auto e : blob.extents) { + if (!e.is_valid()) { + bc.discard(pos, e.length); + } + pos += e.length; + } +} + // BlobMap #undef dout_prefix @@ -5683,6 +5699,19 @@ void BlueStore::_wctx_finish( vector r; bool compressed = b->blob.is_compressed(); b->blob.put_ref(l.offset, l.length, min_alloc_size, &r); + if (l.blob > 0) { + // blob is owned by the onode; invalidate buffers as *we* drop + // logical refs. + b->bc.discard(l.offset, l.length); + } else { + // blob is shared. we can't invalidate our logical extents as + // we drop them because other onodes may still reference them. + // but we can throw out anything that is no longer allocated. + // Note that this will leave behind edge bits that are no + // longer referenced but not deallocated (until they age out + // of the cache naturally). + b->discard_unallocated(); + } txc->statfs_delta.stored() -= l.length; if (compressed) { txc->statfs_delta.compressed_original() -= l.length; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 78926a094d2a..4bfe89c37d68 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -318,6 +318,9 @@ public: friend ostream& operator<<(ostream& out, const Blob &b) { return out << b.id << ":" << b.blob; } + + /// discard buffers for unallocated regions + void discard_unallocated(); }; /// a map of blobs, indexed by int64_t