@@ -52,20 +52,6 @@ void StupidAllocator::_insert_free(uint64_t off, uint64_t len)
5252 }
5353}
5454
55- // / return the effective length of the extent if we align to alloc_unit
56- uint64_t StupidAllocator::_aligned_len (
57- StupidAllocator::interval_set_t ::iterator p,
58- uint64_t alloc_unit)
59- {
60- uint64_t skew = p.get_start () % alloc_unit;
61- if (skew)
62- skew = alloc_unit - skew;
63- if (skew > p.get_len ())
64- return 0 ;
65- else
66- return p.get_len () - skew;
67- }
68-
6955int64_t StupidAllocator::allocate_int (
7056 uint64_t want_size, uint64_t alloc_unit, int64_t hint,
7157 uint64_t *offset, uint32_t *length)
@@ -89,7 +75,7 @@ int64_t StupidAllocator::allocate_int(
8975 for (bin = orig_bin; bin < (int )free.size (); ++bin) {
9076 p = free[bin].lower_bound (hint);
9177 while (p != free[bin].end ()) {
92- if (_aligned_len (p, alloc_unit ) >= want_size) {
78+ if (p. get_len ( ) >= want_size) {
9379 goto found;
9480 }
9581 ++p;
@@ -102,7 +88,7 @@ int64_t StupidAllocator::allocate_int(
10288 p = free[bin].begin ();
10389 auto end = hint ? free[bin].lower_bound (hint) : free[bin].end ();
10490 while (p != end) {
105- if (_aligned_len (p, alloc_unit ) >= want_size) {
91+ if (p. get_len ( ) >= want_size) {
10692 goto found;
10793 }
10894 ++p;
@@ -114,7 +100,7 @@ int64_t StupidAllocator::allocate_int(
114100 for (bin = orig_bin; bin >= 0 ; --bin) {
115101 p = free[bin].lower_bound (hint);
116102 while (p != free[bin].end ()) {
117- if (_aligned_len (p, alloc_unit ) >= alloc_unit) {
103+ if (p. get_len ( ) >= alloc_unit) {
118104 goto found;
119105 }
120106 ++p;
@@ -127,7 +113,7 @@ int64_t StupidAllocator::allocate_int(
127113 p = free[bin].begin ();
128114 auto end = hint ? free[bin].lower_bound (hint) : free[bin].end ();
129115 while (p != end) {
130- if (_aligned_len (p, alloc_unit ) >= alloc_unit) {
116+ if (p. get_len ( ) >= alloc_unit) {
131117 goto found;
132118 }
133119 ++p;
@@ -137,11 +123,9 @@ int64_t StupidAllocator::allocate_int(
137123 return -ENOSPC;
138124
139125 found:
140- uint64_t skew = p.get_start () % alloc_unit;
141- if (skew)
142- skew = alloc_unit - skew;
143- *offset = p.get_start () + skew;
144- *length = std::min (std::max (alloc_unit, want_size), p2align ((p.get_len () - skew), alloc_unit));
126+ *offset = p.get_start ();
127+ *length = std::min (std::max (alloc_unit, want_size), p2align (p.get_len (), alloc_unit));
128+
145129 if (cct->_conf ->bluestore_debug_small_allocations ) {
146130 uint64_t max =
147131 alloc_unit * (rand () % cct->_conf ->bluestore_debug_small_allocations );
@@ -158,7 +142,7 @@ int64_t StupidAllocator::allocate_int(
158142
159143 free[bin].erase (*offset, *length);
160144 uint64_t off, len;
161- if (*offset && free[bin].contains (*offset - skew - 1 , &off, &len)) {
145+ if (*offset && free[bin].contains (*offset - 1 , &off, &len)) {
162146 int newbin = _choose_bin (len);
163147 if (newbin != bin) {
164148 ldout (cct, 30 ) << __func__ << " demoting 0x" << std::hex << off << " ~" << len
0 commit comments