summaryrefslogtreecommitdiff
path: root/fs/bcachefs/btree_iter.c
AgeCommit message (Collapse)Author
2021-06-08bcachefs: Fix a spurious debug mode assertionKent Overstreet
When we switched to using bch2_btree_bset_insert_key() for extents it turned out it started leaving invalid keys around - of type deleted but nonzero size - but this is fine (if ugly) because they're never written out. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-06-04bcachefs: btree_iter->should_be_lockedKent Overstreet
Add a field to struct btree_iter for tracking whether it should be locked - this fixes spurious transaction restarts in bch2_trans_relock(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-06-04bcachefs: Improve btree iterator tracepointsKent Overstreet
This patch adds some new tracepoints to the btree iterator code, and adds new fields to the existing tracepoints - primarily for the iterator position. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-30bcachefs: Assorted endianness fixesKent Overstreet
Found by sparse Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: made changes to support clang, fixed a couple bugsBrett Holman
fs/bcachefs/bset.c edited prefetch macro to add clang support fs/bcachefs/btree_iter.c bugfix: initialize iter->real_pos in bch2_btree_iter_init for later use fs/bcachefs/io.c bugfix: eliminated undefined behavior (negative bitshift) fs/bcachefs/buckets.c bugfix: invert sign to handle 64bit abs()
2021-05-19bcachefs: Fix bch2_btree_iter_peek_with_updates()Kent Overstreet
By not re-fetching the next update we were going into an infinite loop. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: New tracepoint for bch2_trans_get_iter()Kent Overstreet
Trying to debug an issue where after traverse_all() we shouldn't have to traverse any iterators... yet we are Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Fix __bch2_trans_get_iter()Kent Overstreet
We need to also set iter->uptodate to indicate it needs to be traversed. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Add a mempool for the replicas delta listKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Add a mempool for btree_trans bump allocatorKent Overstreet
This allocation is required for filesystem operations to make forward progress, thus needs a mempool. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Fix transaction restarts due to upgrading of cloned iteratorsKent Overstreet
This fixes a regression from 52d86202fd bcachefs: Improve bch2_btree_iter_traverse_all() We want to avoid mucking with other iterators in the btree transaction in operations that are only supposed to be touching individual iterators - that patch was a cleanup to move lock ordering handling to bch2_btree_iter_traverse_all(). But it broke upgrading of cloned iterators. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Improve trans_restart_mem_realloced tracepointKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Don't downgrade iterators in bch2_trans_get_iter()Kent Overstreet
This fixes a livelock with btree node splits. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Improve bch2_btree_iter_traverse_all()Kent Overstreet
By changing it to upgrade iterators to intent locks to avoid lock restarts we can simplify __bch2_btree_node_lock() quite a bit - this fixes a probable bug where it could potentially drop a lock on an unrelated error but still succeed instead of causing a transaction restart. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Better iterator pickingKent Overstreet
Avoid cloning iterators if we don't have to. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Fix bch2_trans_relock()Kent Overstreet
The patch that changed bch2_trans_relock() to not look at iter->uptodate also tried to add an optimization by only having it relock btree_iter_key() iterators (iterators that are live or have been marked as keep). But, this wasn't thought through - this pops internal iterator assertions because on transaction restart, when we're traversing iterators we traverse all iterators marked as linked, and having bch2_trans_relock() skip some of those mean that it can skil the iterator that bch2_btree_iter_traverse_one() is currently traversing. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Fix BTREE_ITER_NOT_EXTENTSKent Overstreet
bch2_btree_iter_peek() wasn't properly checking for BTREE_ITER_IS_EXTENTS when updating iter->pos. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Don't flush btree writes more aggressively because of btree key cacheKent Overstreet
We need to flush the btree key cache when it's too dirty, because otherwise the shrinker won't be able to reclaim memory - this is done by journal reclaim. But journal reclaim also kicks btree node writes: this meant that btree node writes were getting kicked much too often just because we needed to flush btree key cache keys. This patch splits journal pins into two different lists, and teaches journal reclaim to not flush btree node writes when it only needs to flush key cache keys. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Kill bch2_fs_usage_scratch_get()Kent Overstreet
This is an important cleanup, eliminating an unnecessary copy in the transaction commit path. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Increase commality between BTREE_ITER_NODES and BTREE_ITER_KEYSKent Overstreet
Eventually BTREE_ITER_NODES should be going away. This patch is to fix a transaction iterator overflow in the btree node merge path because BTREE_ITER_NODES iterators couldn't be reused. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Drop trans->nounlockKent Overstreet
Since we're no longer doing btree node merging post commit, we can now delete a bunch of code. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Improve bch2_trans_relock()Kent Overstreet
We're getting away from relying on iter->uptodate - this changes bch2_trans_relock() to more directly specify which iterators should be relocked. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Move btree lock debugging to slowpath fnKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Start using bpos.snapshot fieldKent Overstreet
This patch starts treating the bpos.snapshot field like part of the key in the btree code: * bpos_successor() and bpos_predecessor() now include the snapshot field * Keys in btrees that will be using snapshots (extents, inodes, dirents and xattrs) now always have their snapshot field set to U32_MAX The btree iterator code gets a new flag, BTREE_ITER_ALL_SNAPSHOTS, that determines whether we're iterating over keys in all snapshots or not - internally, this controlls whether bkey_(successor|predecessor) increment/decrement the snapshot field, or only the higher bits of the key. We add a new member to struct btree_iter, iter->snapshot: when BTREE_ITER_ALL_SNAPSHOTS is not set, iter->pos.snapshot should always equal iter->snapshot, which will be 0 for btrees that don't use snapshots, and alsways U32_MAX for btrees that will use snapshots (until we enable snapshot creation). This patch also introduces a new metadata version number, and compat code for reading from/writing to older versions - this isn't a forced upgrade (yet). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Split out bpos_cmp() and bkey_cmp()Kent Overstreet
With snapshots, we're going to need to differentiate between comparisons that should and shouldn't include the snapshot field. bpos_cmp is now the comparison function that does include the snapshot field, used by core btree code. Upper level filesystem code generally does _not_ want to compare against the snapshot field - that code wants keys to compare as equal even when one of them is in an ancestor snapshot. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Add a mechanism for running callbacks at trans commit timeKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Fix for bch2_trans_commit() unlocking when it's not supposed toKent Overstreet
When we pass BTREE_INSERT_NOUNLOCK bch2_trans_commit isn't supposed to unlock after a successful commit, but it was calling bch2_trans_cond_resched() - oops. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Split btree_iter_traverse and bch2_btree_iter_traverse()Kent Overstreet
External (to the btree iterator code) users of bch2_btree_iter_traverse expect that on success the iterator will be pointed at iter->pos and have that position locked - but since we split iter->pos and iter->real_pos, that means it has to update iter->real_pos if necessary. Internal users don't expect it to modify iter->real_pos, so we need two separate functions. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Update iter->real_pos lazilyKent Overstreet
peek() has to update iter->real_pos - there's no need for bch2_btree_iter_set_pos() to update it as well. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Consolidate bch2_btree_iter_peek() and peek_with_updates()Kent Overstreet
Ideally we'll be getting rid of peek_with_updates(), but the callers will need to be checked. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Improve iter->real_pos handlingKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Internal btree iterator renamingKent Overstreet
This just gives some internal helpers some better names. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Kill btree_iter_peek_uptodate()Kent Overstreet
Since we're no longer doing next() immediately followed by peek(), this optimization isn't doing anything anymore. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Iterators are now always consistent with iter->real_posKent Overstreet
This means bch2_btree_iter_traverse_one() can be made more efficient. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Have btree_iter_next_node() use btree_iter_set_search_pos()Kent Overstreet
btree node iterators need to obey the regular btree node invarionts w.r.t. iter->real_pos; once they do, bch2_btree_iter_traverse will have less that it needs to check. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Replace bch2_btree_iter_next() calls with bch2_btree_iter_advanceKent Overstreet
The way btree iterators work internally has been changing, particularly with the iter->real_pos changes, and bch2_btree_iter_next() is no longer hyper optimized - it's just advance followed by peek, so it's more efficient to just call advance where we're not using the return value of bch2_btree_iter_next(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Optimize bch2_btree_iter_verify_level()Kent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Fix iterator pickingKent Overstreet
comparison was wrong Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Assert that iterators aren't being double freedKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: Require all btree iterators to be freedKent Overstreet
We keep running into occasional bugs with btree transaction iterators overflowing - this will make those bugs more visible. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-05-19bcachefs: btree_iter_set_dontneed()Kent Overstreet
This is a bit clearer than using bch2_btree_iter_free(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: Fsck code refactoringKent Overstreet
Change fsck code to always put btree iterators - also, make some flow control improvements to deal with lock restarts better, and refactor check_extents() to not walk extents twice for counting/checking i_sectors. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: Kill btree_iter_pos_changed()Kent Overstreet
this is used in only one place now, so just inline it into the caller. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: Fix a btree iterator leakKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: __bch2_trans_get_iter() refactoring, BTREE_ITER_NOT_EXTENTSKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: Simplify bch2_btree_iter_peek_prev()Kent Overstreet
Since we added iter->real_pos, btree_iter_set_pos_to_(next|prev)_leaf no longer modify iter->pos, so we don't have to save it at the start anymore. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: Fix bpos_diff()Kent Overstreet
Previously, bpos_diff() did not handle borrows correctly. Minor thing considering how it was used, but worth fixing. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: Use bch2_bpos_to_text() more consistentlyKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: btree_iter_prev_slot()Kent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-04-27bcachefs: btree_iter_live()Kent Overstreet
New helper to clean things up a bit - also, improve iter->flags handling. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>