From 3bc31746b5d9983920ae68eded1bef2a32ac342a Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Tue, 19 Jul 2016 20:02:48 +0800 Subject: [PATCH] os/bluestore: add a boundary check of cache read By trapping the "==" case and break, we can finish the cache read just in time. As a result, we can avoid two extra operations(adjusting "offset" and "length") and the final loop check. Since this is one of key methods of cache, it deserves this fix. Signed-off-by: xie xingguo --- src/os/bluestore/BlueStore.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index c4ba07b251af5..4e0c93ac40dab 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1008,6 +1008,8 @@ void BlueStore::BufferSpace::read( } else { res[offset].append(b->data); res_intervals.insert(offset, b->length); + if (b->length == length) + break; offset += b->length; length -= b->length; }