From: Sage Weil Date: Fri, 10 Jun 2016 15:36:05 +0000 (-0400) Subject: os/bluestore: buffer cache_private field, returned by discard X-Git-Tag: v11.0.0~70^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=98748b36232d6557085c00adfb002dda72552910;p=ceph.git os/bluestore: buffer cache_private field, returned by discard 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 --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 3a5c06c15dbd..00264dc41bf4 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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( diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 247fa1afa266..d504c2aefcae 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -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 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 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) {