From d571be230590971faa421b3d29deefa6820a00da Mon Sep 17 00:00:00 2001 From: Jianjian Huo Date: Sun, 13 Mar 2016 22:12:50 -0700 Subject: [PATCH] os/bluestore: avoid duplicated searches during allocating free extents 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 --- src/os/bluestore/StupidAllocator.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index 4d8c5f1359c3c..2a6d1820f6d16 100755 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -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; } -- 2.39.5