aboutsummaryrefslogtreecommitdiff
path: root/fs/bcachefs/buckets.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* bcachefs: More BCH_SB_MEMBER_INVALID supportKent Overstreet2024-09-091-7/+8
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: fix rebalance accountingKent Overstreet2024-09-011-1/+1
| | | | | Fixes: 49aa7830396b ("bcachefs: Fix rebalance_work accounting") Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix rebalance_work accountingKent Overstreet2024-08-241-25/+49
| | | | | | | | | | rebalance_work was keying off of the presence of rebelance_opts in the extent - but that was incorrect, we keep those around after rebalance for indirect extents since the inode's options are not directly available Fixes: 20ac515a9cc7 ("bcachefs: bch_acct_rebalance_work") Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix locking in __bch2_trans_mark_dev_sb()Kent Overstreet2024-08-161-5/+9
| | | | | | | We run this in full RW mode now, so we have to guard against the superblock buffer being reallocated. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix forgetting to pass trans to fsck_err()Kent Overstreet2024-08-161-1/+1
| | | | | Reported-by: syzbot+e3938cd6d761b78750e6@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bcachefs_metadata_version_disk_accounting_inumKent Overstreet2024-08-131-0/+14
| | | | | | | | | | | | | | | | | | This adds another disk accounting counter to track usage per inode number (any snapshot ID). This will be used for a couple things: - It'll give us a way to tell the user how much space a given file ista consuming in all snapshots; i.e. how much extra space it's consuming due to snapshot versioning. - It counts number of extents and total size of extents (both in btree keyspace sectors and actual disk usage), meaning it gives us average extent size: that is, it'll let us cheaply find fragmented files that should be defragmented. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: improve bch2_dev_usage_to_text()Kent Overstreet2024-08-091-4/+8
| | | | | | Add a line for capacity Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix missing BTREE_TRIGGER_bucket_invalidate flagKent Overstreet2024-07-141-1/+1
| | | | | | This fixes an accounting mismatch for cached data. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Reduce the scope of gc_lockKent Overstreet2024-07-141-2/+0
| | | | | | | gc_lock is now only for synchronization between check_alloc_info and interior btree updates - nothing else Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: fsck_err() may now take a btree_transKent Overstreet2024-07-141-20/+20
| | | | | | | | | fsck_err() now optionally takes a btree_trans; if the current thread has one, it is required that it be passed. The next patch will use this to unlock when waiting for user input. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch_acct_rebalance_workKent Overstreet2024-07-141-0/+9
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch_acct_btreeKent Overstreet2024-07-141-0/+10
| | | | | | Add counters for how much disk space we're using per btree. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch_acct_snapshotKent Overstreet2024-07-141-0/+10
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch_acct_compressionKent Overstreet2024-07-141-10/+47
| | | | | | | | This adds per-compression-type accounting of compressed and uncompressed size as well as number of extents - meaning we can now see compression ratio (without walking the whole filesystem). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Convert gc to new accountingKent Overstreet2024-07-141-153/+32
| | | | | | | | | | Rewrite fsck/gc for the new accounting scheme. This adds a second set of in-memory accounting counters for gc to use; like with other parts of gc we run all trigger in TRIGGER_GC mode, then compare what we calculated to existing in-memory accounting at the end. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Kill fs_usage_onlineKent Overstreet2024-07-141-10/+0
| | | | | | More dead code deletion. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Kill bch2_fs_usage_to_text()Kent Overstreet2024-07-141-39/+0
| | | | | | Dead code. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Delete journal-buf-sharded old style accountingKent Overstreet2024-07-141-55/+6
| | | | | | More deletion of dead code. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: kill bch2_fs_usage_read()Kent Overstreet2024-07-141-34/+0
| | | | | | With bch2_ioctl_fs_usage(), this is now dead code. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Kill bch2_fs_usage_initialize()Kent Overstreet2024-07-141-29/+0
| | | | | | Deleting code for the old disk accounting scheme. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: dev_usage updated by new accountingKent Overstreet2024-07-141-31/+5
| | | | | | | | | | | | | Reading disk accounting now requires an eytzinger lookup (see: bch2_accounting_mem_read()), but the per-device counters are used frequently enough that we'd like to still be able to read them with just a percpu sum, as in the old code. This patch special cases the device counters; when we update in-memory accounting we also update the old style percpu counters if it's a deice counter update. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Disk space accounting rewriteKent Overstreet2024-07-141-243/+48
| | | | | | | | | | | | | | | | | | | | | | | | | Main part of the disk accounting rewrite. This is a wholesale rewrite of the existing disk space accounting, which relies on percepu counters that are sharded by journal buffer, and rolled up and added to each journal write. With the new scheme, every set of counters is a distinct key in the accounting btree; this fixes scaling limitations of the old scheme, where counters took up space in each journal entry and required multiple percpu counters. Now, in memory accounting requires a single set of percpu counters - not multiple for each in flight journal buffer - and in the future we'll probably also have counters that don't use in memory percpu counters, they're not strictly required. An accounting update is now a normal btree update, using the btree write buffer path. At transaction commit time, we apply accounting updates to the in memory counters, which are percpu counters indexed in an eytzinger tree by the accounting key. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: BCH_DATA_unstripedKent Overstreet2024-07-141-3/+11
| | | | | | | Add a new pseudo data type, to track buckets that are members of a stripe, but have unstriped data in them. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch_alloc->stripe_sectorsKent Overstreet2024-07-141-7/+9
| | | | | | | | | | Add a separate counter to bch_alloc_v4 for amount of striped data; this lets us separately track striped and unstriped data in a bucket, which lets us see when erasure coding has failed to update extents with stripe pointers, and also find buckets to continue updating if we crash mid way through creating a new stripe. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Use try_cmpxchg() family of functions instead of cmpxchg()Uros Bizjak2024-07-141-9/+8
| | | | | | | | | | | | | | | | | Use try_cmpxchg() family of functions instead of cmpxchg (*ptr, old, new) == old. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). Also, try_cmpxchg() implicitly assigns old *ptr value to "old" when cmpxchg fails. There is no need to re-read the value in the loop. No functional change intended. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Brian Foster <bfoster@redhat.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix RCU splatKent Overstreet2024-07-101-1/+1
| | | | | Reported-by: syzbot+e74fea078710bbca6f4b@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Check for invalid bucket from bucket_gen(), gc_bucket()Kent Overstreet2024-06-101-15/+35
| | | | | | | Turn more asserts into proper recoverable error paths. Reported-by: syzbot+246b47da27f8e7e7d6fb@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Replace bucket_valid() asserts in bucket lookup with proper checksKent Overstreet2024-06-101-0/+2
| | | | | | | The bucket_gens array and gc_buckets array known their own size; we should be using those members, and returning an error. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix refcount leak in check_fix_ptrs()Kent Overstreet2024-06-101-116/+133
| | | | | | | fsck_err() does a goto fsck_err on error; factor out check_fix_ptr() so that our error label can drop our device ref. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix uninitialized var warningKent Overstreet2024-05-281-1/+1
| | | | | | Can't actually be used uninitialized, but gcc was being silly. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix ref in trans_mark_dev_sbs() error pathKent Overstreet2024-05-201-1/+1
| | | | | Reported-by: syzbot+5c7f715a7107a608a544@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix rcu splat in check_fix_ptrs()Kent Overstreet2024-05-201-5/+6
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: kill bch2_dev_bkey_exists() in bch2_check_fix_ptrs()Kent Overstreet2024-05-091-3/+24
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Kill bch2_dev_bkey_exists() in backpointer codeKent Overstreet2024-05-081-1/+1
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: PTR_BUCKET_POS() now takes bch_devKent Overstreet2024-05-081-1/+1
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch2_bucket_ref_update() now takes bch_devKent Overstreet2024-05-081-21/+26
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: New helpers for device refcountsKent Overstreet2024-05-081-2/+2
| | | | | | | This will be used in the next patch for adding some new debug mode asserts. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Kill opts.buckets_nouseKent Overstreet2024-05-081-16/+27
| | | | | | | | | | Now explicitly allocate and free the buckets_nouse bitmap - this is going to be used for online fsck. To go RW when we haven't check allocations, we'll do a much slimmed down version that just initializes the buckets_nouse bitmaps. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: simplify bch2_trans_start_alloc_update()Kent Overstreet2024-05-081-11/+4
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: __mark_stripe_bucket() now takes bch_alloc_v4Kent Overstreet2024-05-081-1/+0
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: __mark_pointer now takes bch_alloc_v4Kent Overstreet2024-05-081-31/+14
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: kill bch2_dev_usage_update_m()Kent Overstreet2024-05-081-28/+7
| | | | | | by using bucket_m_to_alloc() more, we can get some nice code cleanup. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: dirty_sectors -> replicas_sectorsKent Overstreet2024-05-081-4/+4
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Run bch2_check_fix_ptrs() via triggersKent Overstreet2024-05-081-2/+240
| | | | | | | | | | | | | | | | | Currently, the reflink_p gc trigger does repair as well - turning a reflink_p key into an error key if the reflink_v it points to doesn't exist. This won't work with online check/repair, because the repair path once online will be subject to transaction restarts, but BTREE_TRIGGER_gc is not idempotant - we can't run it multiple times if we get a transaction restart. So we need to split these paths; to do so this patch calls check_fix_ptrs() by a new general path - a new trigger type, BTREE_TRIGGER_check_repair. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch2_bucket_ref_update()Kent Overstreet2024-05-081-23/+32
| | | | | | | | | | | If we hit an inconsistency when updating allocation information, we don't want to fail the update if it's for a deletion - only if it's for a new key. Rename check_bucket_ref() -> bucket_ref_update() so we can centralize the logic to do this. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bucket_data_type_mismatch()Kent Overstreet2024-05-081-10/+1
| | | | | | | | | | We're working on potentially unifying bch2_check_bucket_ref() and bch2_check_fix_ptrs() - or at least eliminating gratuitious differences. Most immediately, there's a bunch of cleanups to be done regarding BCH_DATA_stripe. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: member helper cleanupsKent Overstreet2024-05-081-2/+2
| | | | | | | | | | | | | | Some renaming for better consistency bch2_member_exists -> bch2_member_alive bch2_dev_exists -> bch2_member_exists bch2_dev_exsits2 -> bch2_dev_exists bch_dev_locked -> bch2_dev_locked bch_dev_bkey_exists -> bch2_dev_bkey_exists new helper - bch2_dev_safe Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: iter/update/trigger/str_hash flag cleanupKent Overstreet2024-05-081-37/+40
| | | | | | | | | | | Combine iter/update/trigger/str_hash flags into a single enum, and x-macroize them for a to_text() function later. These flags are all for a specific iter/key/update context, so it makes sense to group them together - iter/update/trigger flags were already given distinct bits, this cleans up and unifies that handling. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: mark_superblock cleanupKent Overstreet2024-05-081-78/+82
| | | | | | | Consolidate mark_superblock() and trans_mark_superblock(), like we did with the other trigger paths. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: prt_printf() now respects \r\n\tKent Overstreet2024-05-081-16/+5
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>