Repository navigation
os/bluestore: fix free-run lookup in _try_remove_from_tree() for the three tree allocators - #71656
Conversation
|
Could you please make unit tests to reproduce the issues and check the fixes? |
| cb(start, range_end - start, true); | ||
| start = range_end; | ||
|
|
||
| // _remove_from_tree() returns an iterator to the range it re-inserted, |
There was a problem hiding this comment.
Shouldn't we instead modify _remove_from_tree in a way to always return iterator pointing after removed entry. I.e. use the approach similar to btree and std collections. In other words left-over items shouldn't cause return value assignment...
There was a problem hiding this comment.
Thank you for catching this! I have fixed it. _remove_from_tree returns the iterator that points to the next free run after the range that was removed
4cd130e to
0065bb9
Compare
b52d45b to
69b3812
Compare
| auto length = end - start; | ||
| ceph_assert(num_free >= length); | ||
| num_free -= length; | ||
| return range_tree.lower_bound(end); |
There was a problem hiding this comment.
There are 2 places that use _process_range_removal: _try_remove_from_tree and _remove_from_tree.
Only the first one needs to reacquire iterator, so it would be better to do the action in _try_remove_from_tree.
There was a problem hiding this comment.
fixed it thank you!
Add AvlAllocator coverage to unittest_alloc. Unlike the btree allocators, AvlAllocator does not need a fix here. range_tree is ordered by an overlap comparator (lhs.end <= rhs.start), so every free run overlapping [start, end) compares equal to the search key. boost::intrusive's find() is implemented as lower_bound() followed by an equality check, so it already returns the leftmost overlapping run rather than whichever one a tree traversal reaches first, and the forward walk visits every overlapping run. The tests just verify that this holds for a query spanning several disjoint runs (inserted right-to-left so the leftmost run is not the root) and for a query inside a single run. Also document why find() is correct at the call site. Signed-off-by: Naveen Naidu <[email protected]>
…_from_tree Make BtreeAllocator::_try_remove_from_tree() protected instead of private, so a thin test subclass can re-expose it the same way it already does for AvlAllocator and Btree2Allocator, and extend unittest_alloc with BtreeAllocator coverage. Fixes: https://tracker.ceph.com/issues/80417 Signed-off-by: Naveen Naidu <[email protected]>
…ation in _try_remove_from_tree
_try_remove_from_tree() had two latent defects:
- It looked up the first overlapping free run with range_tree.find(start),
an exact-key lookup that returns end() unless a run begins exactly at
'start'. A run starting before 'start' and extending into [start, end)
was missed entirely. We now use lower_bound(start) and step back to the
preceding run when it actually reaches past 'start'.
Example:
range_tree: `[100, 200), [300, 350)`, Query: `[150, 180)`
The `range_tree.find(150)` returns `[300, 350)` -> WRONG
- It cached the successor iterator (next_rs) before calling
_process_range_removal(), which can insert into range_tree and
invalidate it. The caller now re-acquires the iterator with
range_tree.lower_bound(end) after _process_range_removal() is done with
its tree mutations. This is done in _try_remove_from_tree() rather than
in _process_range_removal(), so that _remove_from_tree(), which doesn't
need the iterator, doesn't pay for the extra lookup.
Example:
range_tree: `[0,10), [20,30), [40,50)`, to remove: `[5, 25)
After `_process_range_removal`:
before: [0, 10) [20, 30) [40, 50)
after: [0, 5) [25, 30) [40, 50)
The issue:
```
auto next_rs = std::next(rs); // points to [20, 30)
_process_range_removal(rs, 5, 25);
rs = next_rs; // unsafe, because rs still points to [20,30) when it should point to [25,30)
```
Fixes: https://tracker.ceph.com/issues/80417
Signed-off-by: Naveen Naidu <[email protected]>
…e_from_tree Fixes: https://tracker.ceph.com/issues/80417 Signed-off-by: Naveen Naidu <[email protected]>
range_tree maps each free range's start to its end. _try_remove_from_tree() finds the first range overlapping [start, end) with lower_bound(), then walks forward trimming ranges through the callback. 1. Wrong step-back. lower_bound(start) may return the range just after the one that straddles 'start', so the code steps back one node. It did this whenever that node started before 'start', without also checking that it ends after 'start'. A non-overlapping predecessor was then used, and range_end = min(prev_end, end) could fall below 'start', invoking _remove_from_tree() with end < start. Fix: step back only if the predecessor ends past 'start'. 2. No forward progress on a left-over split. When a range reaches below 'start', _remove_from_tree() re-inserts the remainder and returns an iterator to it. The loop never skipped it, so it re-processed that segment with range_end < start - the same malformed removal as above. Fix: in _remove_from_tree() step over the remainder once it has been re-inserted, so the returned iterator points to the range following the removed one. If the remainder is spilled over instead, the iterator already points there and is left as is. Fixes: https://tracker.ceph.com/issues/80417 Signed-off-by: Naveen Naidu <[email protected]>
69b3812 to
ba71356
Compare
|
This PR has been added to wip-jaya-bs-testing-10-27-2026. |
|
This is an automated message by src/script/redmine-upkeep.py. I have resolved the following tracker ticket due to the merge of this PR: No backports are pending for the ticket. If this is incorrect, please update the tracker |
Closes: https://tracker.ceph.com/issues/80417
The following are the failures that we see before the fixes happens:
AVLAllocator
No failures seen, because the
range_tree.find()implementation haslower_bound()already in it. Ref: boost avl_tree, find() and boost avl_tree, find() implementationBtreeAllocator
Btree2Allocator
After the fix commits
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.