]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: discard unreferenced buffers as they are overwritten 9827/head
authorSage Weil <sage@redhat.com>
Wed, 22 Jun 2016 14:30:22 +0000 (10:30 -0400)
committerSage Weil <sage@redhat.com>
Wed, 22 Jun 2016 14:30:27 +0000 (10:30 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 0626097537fdf37ab61b1ed18302ae5f65f41137..506db30ca35344f520b70a57e25f9aa14976f227 100644 (file)
@@ -813,6 +813,22 @@ bool BlueStore::OnodeSpace::map_any(std::function<bool(OnodeRef)> 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<bluestore_pextent_t> 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;
index 78926a094d2a1695c8bf7f38cd5397ba8ad1ae3d..4bfe89c37d68a3894ee07e5a38af53b74363975f 100644 (file)
@@ -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