From 04fe26921fd2900e9cfa7f6b6fe78d91291311e0 Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang Date: Tue, 7 Apr 2015 13:43:36 +0800 Subject: [PATCH 1/2] librbd: start readahead from m_last_pos when the size of the continuing triggering request is big enough If the size of the read triggering the continuing readahead is such big that exceeding m_readahead_pos, should do the readahead starting from m_last_pos. Signed-off-by: Zhiqiang Wang --- src/common/Readahead.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/Readahead.cc b/src/common/Readahead.cc index a3f5bfc7e4e..77ab92eba4f 100644 --- a/src/common/Readahead.cc +++ b/src/common/Readahead.cc @@ -70,6 +70,9 @@ Readahead::extent_t Readahead::_compute_readahead(uint64_t limit) { } else { // continuing readahead trigger m_readahead_size *= 2; + if (m_last_pos > m_readahead_pos) { + m_readahead_pos = m_last_pos; + } } m_readahead_size = MAX(m_readahead_size, m_readahead_min_bytes); m_readahead_size = MIN(m_readahead_size, m_readahead_max_bytes); From b47a5499a0d2591c09e93d1edb3c8827f6353c49 Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang Date: Tue, 7 Apr 2015 14:23:38 +0800 Subject: [PATCH 2/2] librbd: don't do readahead when m_readahead_pos reaching limit When m_readahead_pos reaches the limit, there's no need to call _compute_readahead to calculate the readahead. Just return with no readahead. Signed-off-by: Zhiqiang Wang --- src/common/Readahead.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/Readahead.cc b/src/common/Readahead.cc index 77ab92eba4f..b1ee2e099c6 100644 --- a/src/common/Readahead.cc +++ b/src/common/Readahead.cc @@ -30,6 +30,10 @@ Readahead::extent_t Readahead::update(const vector& extents, uint64_t for (vector::const_iterator p = extents.begin(); p != extents.end(); ++p) { _observe_read(p->first, p->second); } + if (m_readahead_pos >= limit) { + m_lock.Unlock(); + return extent_t(0, 0); + } pair extent = _compute_readahead(limit); m_lock.Unlock(); return extent; @@ -38,6 +42,10 @@ Readahead::extent_t Readahead::update(const vector& extents, uint64_t Readahead::extent_t Readahead::update(uint64_t offset, uint64_t length, uint64_t limit) { m_lock.Lock(); _observe_read(offset, length); + if (m_readahead_pos >= limit) { + m_lock.Unlock(); + return extent_t(0, 0); + } extent_t extent = _compute_readahead(limit); m_lock.Unlock(); return extent; @@ -52,6 +60,7 @@ void Readahead::_observe_read(uint64_t offset, uint64_t length) { m_consec_read_bytes = 0; m_readahead_trigger_pos = 0; m_readahead_size = 0; + m_readahead_pos = 0; } m_last_pos = offset + length; }