linux/fs/bcachefs
Brian Foster 385a82f62a bcachefs: serialize on cached key in early bucket allocator
bcachefs had a transient bug where freespace_initialized was not
properly being set, which lead to unexpected use of the early bucket
allocator at runtime. This issue has been fixed, but the existence
of it uncovered a coherency issue in the early bucket allocation
code that is somewhat related to how uncached iterators deal with
the key cache.

The problem itself manifests as occasional failure of generic/113
due to corruption, often seen as a duplicate backpointer or multiple
data types per-bucket error. The immediate cause of the error is a
racing bucket allocation along the lines of the following sequence:

- Task 1 selects key A in bch2_bucket_alloc_early() and schedules.
- Task 2 selects the same key A, but proceeds to complete the
  allocation and associated I/O, after which it releases the
  open_bucket.
- Task 1 resumes with key A, but does not recognize the bucket is
  now allocated because the open_bucket has been removed
  from the hash when it was released in the previous step.

This generally shouldn't happen because the allocating task updates
the alloc btree key before releasing the bucket. This is not
sufficient in this particular instance, however, because an uncached
iterator for a cached btree doesn't actually lock the key cache slot
when no key exists for a given slot in the cache. Thus the fact that
the allocation side updates the cached key means that multiple
uncached iters can stumble across the same alloc key and duplicate
the bucket allocation as described above.

This is something that probably needs a longer term fix in the
iterator code. As a short term fix, close the race through explicit
use of a cached iterator for likely allocation candidates. We don't
want to scan the btree with a cached iterator because that would
unnecessarily pollute the cache. This mitigates cache pollution by
primarily scanning the tree with an uncached iterator, but closes
the race by creating a key cache entry for any prospective slot
prior to the bucket allocation attempt (also similar to how
_alloc_freelist() works via try_alloc_bucket()). This survives many
iterations of generic/113 on a kernel hacked to always use the early
bucket allocator.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-11-04 22:19:13 -04:00
..
acl.c
acl.h
alloc_background.c bcachefs: Ensure copygc does not spin 2023-11-04 14:17:11 -04:00
alloc_background.h bcachefs: Ensure copygc does not spin 2023-11-04 14:17:11 -04:00
alloc_foreground.c bcachefs: serialize on cached key in early bucket allocator 2023-11-04 22:19:13 -04:00
alloc_foreground.h
alloc_types.h
backpointers.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
backpointers.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
bbpos_types.h bcachefs: move: convert to bbpos 2023-10-31 12:18:37 -04:00
bbpos.h bcachefs: move: convert to bbpos 2023-10-31 12:18:37 -04:00
bcachefs_format.h bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
bcachefs_ioctl.h
bcachefs.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
bkey_buf.h
bkey_cmp.h
bkey_methods.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
bkey_methods.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
bkey_sort.c
bkey_sort.h
bkey.c
bkey.h
bset.c
bset.h
btree_cache.c bcachefs: Fix shrinker names 2023-10-31 12:18:37 -04:00
btree_cache.h bcachefs: bch2_btree_id_str() 2023-10-31 12:18:37 -04:00
btree_gc.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
btree_gc.h
btree_io.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
btree_io.h
btree_iter.c bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
btree_iter.h bcachefs: Ensure srcu lock is not held too long 2023-11-04 14:17:11 -04:00
btree_journal_iter.c
btree_journal_iter.h
btree_key_cache.c bcachefs: Don't downgrade locks on transaction restart 2023-11-01 21:11:08 -04:00
btree_key_cache.h
btree_locking.c bcachefs: Ensure srcu lock is not held too long 2023-11-04 14:17:11 -04:00
btree_locking.h bcachefs: Don't downgrade locks on transaction restart 2023-11-01 21:11:08 -04:00
btree_trans_commit.c bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
btree_types.h bcachefs: Ensure srcu lock is not held too long 2023-11-04 14:17:11 -04:00
btree_update_interior.c bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
btree_update_interior.h bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
btree_update.c
btree_update.h
btree_write_buffer_types.h
btree_write_buffer.c
btree_write_buffer.h
buckets_types.h
buckets_waiting_for_journal_types.h
buckets_waiting_for_journal.c
buckets_waiting_for_journal.h
buckets.c bcachefs: Fix an integer overflow 2023-11-01 21:11:08 -04:00
buckets.h bcachefs: All triggers are BTREE_TRIGGER_WANTS_OLD_AND_NEW 2023-10-31 12:18:37 -04:00
chardev.c bcachefs: move: convert to bbpos 2023-10-31 12:18:37 -04:00
chardev.h
checksum.c
checksum.h
clock_types.h
clock.c
clock.h
compress.c bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
compress.h bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
counters.c
counters.h
darray.h
data_update.c bcachefs: Don't downgrade locks on transaction restart 2023-11-01 21:11:08 -04:00
data_update.h bcachefs: move: convert to bbpos 2023-10-31 12:18:37 -04:00
debug.c bcachefs: bch2_btree_id_str() 2023-10-31 12:18:37 -04:00
debug.h
dirent.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
dirent.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
disk_groups_types.h bcachefs: bch2_disk_path_to_text() no longer takes sb_lock 2023-10-31 12:18:37 -04:00
disk_groups.c bcachefs: bch2_disk_path_to_text() no longer takes sb_lock 2023-10-31 12:18:37 -04:00
disk_groups.h bcachefs: bch2_disk_path_to_text() no longer takes sb_lock 2023-10-31 12:18:37 -04:00
ec_types.h
ec.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
ec.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
errcode.c
errcode.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
error.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
error.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
extent_update.c
extent_update.h
extents_types.h
extents.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
extents.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
eytzinger.h
fifo.h
fs-common.c
fs-common.h
fs-io-buffered.c
fs-io-buffered.h
fs-io-direct.c
fs-io-direct.h
fs-io-pagecache.c
fs-io-pagecache.h
fs-io.c
fs-io.h
fs-ioctl.c
fs-ioctl.h
fs.c
fs.h
fsck.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
fsck.h bcachefs: Check for too-large encoded extents 2023-10-31 12:18:37 -04:00
inode.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
inode.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
io_misc.c bcachefs: Fix an integer overflow 2023-11-01 21:11:08 -04:00
io_misc.h bcachefs: Fix an integer overflow 2023-11-01 21:11:08 -04:00
io_read.c bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
io_read.h
io_write_types.h
io_write.c bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
io_write.h
journal_io.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
journal_io.h
journal_reclaim.c
journal_reclaim.h
journal_sb.c
journal_sb.h
journal_seq_blacklist.c
journal_seq_blacklist.h
journal_types.h
journal.c bcachefs: Ensure devices are always correctly initialized 2023-10-31 12:18:37 -04:00
journal.h bcachefs: Ensure devices are always correctly initialized 2023-10-31 12:18:37 -04:00
Kconfig bcachefs: Fix MEAN_AND_VARIANCE kconfig options 2023-11-04 14:17:11 -04:00
keylist_types.h
keylist.c
keylist.h
logged_ops.c
logged_ops.h
lru.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
lru.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
Makefile bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
mean_and_variance_test.c
mean_and_variance.c
mean_and_variance.h
migrate.c
migrate.h
move_types.h bcachefs: move: move_stats refactoring 2023-10-31 12:18:38 -04:00
move.c bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
move.h bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
movinggc.c bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
movinggc.h
nocow_locking_types.h
nocow_locking.c
nocow_locking.h
opts.c bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
opts.h bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
printbuf.c bcachefs: Fix bch2_prt_bitflags() 2023-10-31 12:18:37 -04:00
printbuf.h
quota_types.h
quota.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
quota.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
rebalance_types.h bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
rebalance.c bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
rebalance.h bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
recovery_types.h bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
recovery.c bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
recovery.h
reflink.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
reflink.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
replicas_types.h
replicas.c bcachefs: Fix error path in bch2_replicas_gc_end() 2023-11-01 21:11:08 -04:00
replicas.h
sb-clean.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
sb-clean.h
sb-errors_types.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
sb-errors.c bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
sb-errors.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
sb-members.c bcachefs: Skip deleted members in member_to_text() 2023-11-01 21:11:08 -04:00
sb-members.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
seqmutex.h
siphash.c
siphash.h
six.c six locks: Lock contended tracepoints 2023-10-30 22:26:45 -04:00
six.h
snapshot.c bcachefs: Fix deleted inodes btree in snapshot deletion 2023-11-01 21:11:08 -04:00
snapshot.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
str_hash.h
subvolume_types.h
subvolume.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
subvolume.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
super_types.h bcachefs: Split out disk_groups_types.h 2023-10-31 12:18:37 -04:00
super-io.c bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
super-io.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
super.c bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
super.h
sysfs.c bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
sysfs.h
tests.c
tests.h
trace.c bcachefs: move: move_stats refactoring 2023-10-31 12:18:38 -04:00
trace.h bcachefs: Don't downgrade locks on transaction restart 2023-11-01 21:11:08 -04:00
two_state_shared_lock.c
two_state_shared_lock.h
util.c
util.h
varint.c
varint.h
vstructs.h
xattr.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
xattr.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00