diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-02-14 15:42:41 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:16 -0400 |
commit | 73c27c60956ed55d165d41658745dead49d689c4 (patch) | |
tree | 7acdb25accef17d0e342abe75cb3f5ba7a454987 /fs/bcachefs/buckets.c | |
parent | 8c96cfccf045efff12d8287a41f2b8f4ef3094c2 (diff) | |
download | lwn-73c27c60956ed55d165d41658745dead49d689c4.tar.gz lwn-73c27c60956ed55d165d41658745dead49d689c4.zip |
bcachefs: fixes for cached data accounting
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/buckets.c')
-rw-r--r-- | fs/bcachefs/buckets.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 16d82832277c..949541f15e7d 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -432,7 +432,7 @@ static int __bch2_invalidate_bucket(struct bch_fs *c, struct bch_dev *ca, if (old.cached_sectors) update_cached_sectors(c, fs_usage, ca->dev_idx, - -old.cached_sectors); + -((s64) old.cached_sectors)); if (!gc) *ret = old; @@ -561,7 +561,7 @@ static s64 ptr_disk_sectors_delta(struct extent_ptr_decoded p, * loop, to avoid racing with the start of gc clearing all the marks - GC does * that with the gc pos seqlock held. */ -static void bch2_mark_pointer(struct bch_fs *c, +static bool bch2_mark_pointer(struct bch_fs *c, struct extent_ptr_decoded p, s64 sectors, enum bch_data_type data_type, struct bch_fs_usage *fs_usage, @@ -589,7 +589,7 @@ static void bch2_mark_pointer(struct bch_fs *c, BUG_ON(!test_bit(BCH_FS_ALLOC_READ_DONE, &c->flags)); EBUG_ON(!p.ptr.cached && test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags)); - return; + return true; } if (!p.ptr.cached) @@ -620,6 +620,8 @@ static void bch2_mark_pointer(struct bch_fs *c, bch2_dev_usage_update(c, ca, fs_usage, old, new, gc); BUG_ON(!gc && bucket_became_unavailable(old, new)); + + return false; } static int bch2_mark_stripe_ptr(struct bch_fs *c, @@ -702,13 +704,13 @@ static int bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k, s64 disk_sectors = data_type == BCH_DATA_BTREE ? sectors : ptr_disk_sectors_delta(p, sectors); - - bch2_mark_pointer(c, p, disk_sectors, data_type, - fs_usage, journal_seq, flags, gc); + bool stale = bch2_mark_pointer(c, p, disk_sectors, data_type, + fs_usage, journal_seq, flags, gc); if (p.ptr.cached) { - update_cached_sectors(c, fs_usage, p.ptr.dev, - disk_sectors); + if (disk_sectors && !stale) + update_cached_sectors(c, fs_usage, p.ptr.dev, + disk_sectors); } else if (!p.ec_nr) { dirty_sectors += disk_sectors; r.e.devs[r.e.nr_devs++] = p.ptr.dev; |