]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: avoid duplicated searches during allocating free extents
authorJianjian Huo <samuel.huo@gmail.com>
Mon, 14 Mar 2016 05:12:50 +0000 (22:12 -0700)
committerJianjian Huo <samuel.huo@gmail.com>
Thu, 17 Mar 2016 06:09:28 +0000 (23:09 -0700)
When StupidAllocator searches for free extents, if hint is not 0(most times),
it will search extents starting from hint and up in each applicable bin,
if not found, then search all extents in those bins again.

If the extent to find(>= needs) exists below hint and is not in the choose_bin(),
let's say it's in the bin_X; then during this twice searches, all extents from
hint and up in bins before bin_X will be searched twice. This patch will eliminate
those unnecessary searches.

Signed-off-by: Jianjian Huo <samuel.huo@gmail.com>
src/os/bluestore/StupidAllocator.cc

index 4d8c5f1359c3c9b5f18648ef2e5e57c84057df23..2a6d1820f6d1695345f54e0a0d05f0a5d6795653 100755 (executable)
@@ -115,10 +115,11 @@ int StupidAllocator::allocate(
     }
   }
 
-  // search up (from origin)
+  // search up (from origin, and skip searched extents by hint)
   for (bin = orig_bin; bin < (int)free.size(); ++bin) {
     p = free[bin].begin();
-    while (p != free[bin].end()) {
+    auto end = hint ? free[bin].lower_bound(hint) : free[bin].end();
+    while (p != end) {
       if (aligned_len(p, alloc_unit) >= need_size) {
        goto found;
       }
@@ -139,10 +140,11 @@ int StupidAllocator::allocate(
     }
   }
 
-  // search down (origin)
+  // search down (from origin, and skip searched extents by hint)
   for (bin = orig_bin; bin >= 0; --bin) {
     p = free[bin].begin();
-    while (p != free[bin].end()) {
+    auto end = hint ? free[bin].lower_bound(hint) : free[bin].end();
+    while (p != end) {
       if (aligned_len(p, alloc_unit) >= alloc_unit) {
        goto found;
       }