summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-11-23 16:34:03 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-02-15 22:08:00 -0500
commitbec2af80b5b7e20ddf574e45664d9d2b6835b8b5 (patch)
tree689a715e0e191ba099b7f312a48be17f72027773
parent9323d74ef05d15635c6865384e1d6d3cda7f1a33 (diff)
bcachefs: BCH_DATA_unstriped
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>
-rw-r--r--fs/bcachefs/alloc_background.h5
-rw-r--r--fs/bcachefs/bcachefs_format.h3
-rw-r--r--fs/bcachefs/buckets.c14
-rw-r--r--fs/bcachefs/chardev.c2
4 files changed, 19 insertions, 5 deletions
diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
index 069255643367..a478e0141ae5 100644
--- a/fs/bcachefs/alloc_background.h
+++ b/fs/bcachefs/alloc_background.h
@@ -90,6 +90,11 @@ static inline unsigned bch2_bucket_sectors_fragmented(struct bch_dev *ca,
return d ? max(0, ca->mi.bucket_size - d) : 0;
}
+static inline unsigned bch2_bucket_sectors_unstriped(struct bch_alloc_v4 a)
+{
+ return a.data_type == BCH_DATA_stripe ? a.dirty_sectors : 0;
+}
+
static inline u64 alloc_lru_idx_read(struct bch_alloc_v4 a)
{
return a.data_type == BCH_DATA_cached ? a.io_time[READ] : 0;
diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h
index 8aa5241b5517..3a452bd0a5bd 100644
--- a/fs/bcachefs/bcachefs_format.h
+++ b/fs/bcachefs/bcachefs_format.h
@@ -686,7 +686,8 @@ LE64_BITMASK(BCH_KDF_SCRYPT_P, struct bch_sb_field_crypt, kdf_flags, 32, 48);
x(parity, 6) \
x(stripe, 7) \
x(need_gc_gens, 8) \
- x(need_discard, 9)
+ x(need_discard, 9) \
+ x(unstriped, 10)
enum bch_data_type {
#define x(t, n) BCH_DATA_##t,
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c
index 0a6df9893905..b5ccb15d2e92 100644
--- a/fs/bcachefs/buckets.c
+++ b/fs/bcachefs/buckets.c
@@ -320,12 +320,20 @@ void bch2_dev_usage_update(struct bch_fs *c, struct bch_dev *ca,
u->d[old->data_type].sectors -= bch2_bucket_sectors_dirty(*old);
u->d[new->data_type].sectors += bch2_bucket_sectors_dirty(*new);
- u->d[BCH_DATA_cached].sectors += new->cached_sectors;
- u->d[BCH_DATA_cached].sectors -= old->cached_sectors;
-
u->d[old->data_type].fragmented -= bch2_bucket_sectors_fragmented(ca, *old);
u->d[new->data_type].fragmented += bch2_bucket_sectors_fragmented(ca, *new);
+ u->d[BCH_DATA_cached].sectors -= old->cached_sectors;
+ u->d[BCH_DATA_cached].sectors += new->cached_sectors;
+
+ unsigned old_unstriped = bch2_bucket_sectors_unstriped(*old);
+ u->d[BCH_DATA_unstriped].buckets -= old_unstriped != 0;
+ u->d[BCH_DATA_unstriped].sectors -= old_unstriped;
+
+ unsigned new_unstriped = bch2_bucket_sectors_unstriped(*new);
+ u->d[BCH_DATA_unstriped].buckets += new_unstriped != 0;
+ u->d[BCH_DATA_unstriped].sectors += new_unstriped;
+
preempt_enable();
}
diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c
index a2f30f45f93f..0319abe7e8ce 100644
--- a/fs/bcachefs/chardev.c
+++ b/fs/bcachefs/chardev.c
@@ -589,7 +589,7 @@ static long bch2_ioctl_dev_usage(struct bch_fs *c,
arg.bucket_size = ca->mi.bucket_size;
arg.nr_buckets = ca->mi.nbuckets - ca->mi.first_bucket;
- for (i = 0; i < BCH_DATA_NR; i++) {
+ for (i = 0; i < ARRAY_SIZE(arg.d); i++) {
arg.d[i].buckets = src.d[i].buckets;
arg.d[i].sectors = src.d[i].sectors;
arg.d[i].fragmented = src.d[i].fragmented;