]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: buffer cache_private field, returned by discard
authorSage Weil <sage@redhat.com>
Fri, 10 Jun 2016 15:36:05 +0000 (11:36 -0400)
committerSage Weil <sage@redhat.com>
Wed, 22 Jun 2016 15:28:41 +0000 (11:28 -0400)
2Q (and likly MQ?) need to know when we re-add a block that was previously
evicted.  We track these as STATE_EMPTY buffers, but we throw them out
with _discard before we add the (re)read data into the BufferSpace. Add
a Buffer field called cache_private that is returned by discard (actually,
a max over everything that is discarded) that a cache implementation can
use to discover it has re-read a recently evicted item.

The Cache implemention needs to set cache_private values such that the MAX
over them is what it actually wants...

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 3a5c06c15dbd00a9bcc4ac1857ee3406202ea436..00264dc41bf4fb1651336100087bd7755f1fa1cb 100644 (file)
@@ -600,8 +600,10 @@ void BlueStore::BufferSpace::_clear()
   }
 }
 
-void BlueStore::BufferSpace::_discard(uint64_t offset, uint64_t length)
+int BlueStore::BufferSpace::_discard(uint64_t offset, uint64_t length)
 {
+  // note: we already hold cache->lock
+  int cache_private = 0;
   cache->_audit("discard start");
   auto i = _data_lower_bound(offset);
   uint64_t end = offset + length;
@@ -610,6 +612,9 @@ void BlueStore::BufferSpace::_discard(uint64_t offset, uint64_t length)
     if (b->offset >= end) {
       break;
     }
+    if (b->cache_private > cache_private) {
+      cache_private = b->cache_private;
+    }
     if (b->offset < offset) {
       int64_t front = offset - b->offset;
       if (b->end() > end) {
@@ -625,7 +630,7 @@ void BlueStore::BufferSpace::_discard(uint64_t offset, uint64_t length)
        cache->_adjust_buffer_size(b, front - (int64_t)b->length);
        b->truncate(front);
        cache->_audit("discard end 1");
-       return;
+       break;
       } else {
        // drop tail
        cache->_adjust_buffer_size(b, front - (int64_t)b->length);
@@ -651,8 +656,9 @@ void BlueStore::BufferSpace::_discard(uint64_t offset, uint64_t length)
       _rm_buffer(i);
     }
     cache->_audit("discard end 2");
-    return;
+    break;
   }
+  return cache_private;
 }
 
 void BlueStore::BufferSpace::read(
index 247fa1afa266ba7421e21db62f11ca245c7389ac..d504c2aefcaea4e1f2a6e6f452639215ac0d82f1 100644 (file)
@@ -137,8 +137,9 @@ public:
     }
 
     BufferSpace *space;
-    uint32_t state;            ///< STATE_*
-    uint32_t flags;            ///< FLAG_*
+    uint16_t state;             ///< STATE_*
+    uint16_t cache_private = 0; ///< opaque (to us) value used by Cache impl
+    uint32_t flags;             ///< FLAG_*
     uint64_t seq;
     uint64_t offset, length;
     bufferlist data;
@@ -253,18 +254,19 @@ public:
     // must be called under protection of the Cache lock
     void _clear();
 
-    void discard(uint64_t offset, uint64_t length) {
+    // return value is the highest cache_private of a trimmed buffer, or 0.
+    int discard(uint64_t offset, uint64_t length) {
       std::lock_guard<std::mutex> l(cache->lock);
-      _discard(offset, length);
+      return _discard(offset, length);
     }
-    void _discard(uint64_t offset, uint64_t length);
+    int _discard(uint64_t offset, uint64_t length);
 
     void write(uint64_t seq, uint64_t offset, bufferlist& bl, unsigned flags) {
       std::lock_guard<std::mutex> l(cache->lock);
-      _discard(offset, bl.length());
-      _add_buffer(new Buffer(this, Buffer::STATE_WRITING, seq, offset, bl,
-                            flags),
-                 (flags & Buffer::FLAG_NOCACHE) ? 0 : 1, nullptr);
+      Buffer *b = new Buffer(this, Buffer::STATE_WRITING, seq, offset, bl,
+                            flags);
+      b->cache_private = _discard(offset, bl.length());
+      _add_buffer(b, (flags & Buffer::FLAG_NOCACHE) ? 0 : 1, nullptr);
     }
     void finish_write(uint64_t seq);
     void did_read(uint64_t offset, bufferlist& bl) {