Commit 38585367 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Bucket invalidate path improvements

 - invalidate_one_bucket() now returns 1 when we don't have any buckets
   on this device to invalidate, ensuring we don't spin
 - the tracepoint invocation is moved to after the transaction commit,
   and we now include the number of cached sectors in the tracepoint
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 962ad1a7
...@@ -1077,7 +1077,8 @@ void bch2_do_discards(struct bch_fs *c) ...@@ -1077,7 +1077,8 @@ void bch2_do_discards(struct bch_fs *c)
percpu_ref_put(&c->writes); percpu_ref_put(&c->writes);
} }
static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca) static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca,
struct bpos *bucket_pos, unsigned *cached_sectors)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct btree_iter lru_iter, alloc_iter = { NULL }; struct btree_iter lru_iter, alloc_iter = { NULL };
...@@ -1095,8 +1096,10 @@ static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca) ...@@ -1095,8 +1096,10 @@ static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca)
if (ret) if (ret)
goto out; goto out;
if (!k.k || k.k->p.inode != ca->dev_idx) if (!k.k || k.k->p.inode != ca->dev_idx) {
ret = 1;
goto out; goto out;
}
if (k.k->type != KEY_TYPE_lru) { if (k.k->type != KEY_TYPE_lru) {
prt_printf(&buf, "non lru key in lru btree:\n "); prt_printf(&buf, "non lru key in lru btree:\n ");
...@@ -1116,8 +1119,9 @@ static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca) ...@@ -1116,8 +1119,9 @@ static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca)
idx = k.k->p.offset; idx = k.k->p.offset;
bucket = le64_to_cpu(bkey_s_c_to_lru(k).v->idx); bucket = le64_to_cpu(bkey_s_c_to_lru(k).v->idx);
a = bch2_trans_start_alloc_update(trans, &alloc_iter, *bucket_pos = POS(ca->dev_idx, bucket);
POS(ca->dev_idx, bucket));
a = bch2_trans_start_alloc_update(trans, &alloc_iter, *bucket_pos);
ret = PTR_ERR_OR_ZERO(a); ret = PTR_ERR_OR_ZERO(a);
if (ret) if (ret)
goto out; goto out;
...@@ -1139,6 +1143,11 @@ static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca) ...@@ -1139,6 +1143,11 @@ static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca)
} }
} }
if (!a->v.cached_sectors)
bch_err(c, "invalidating empty bucket, confused");
*cached_sectors = a->v.cached_sectors;
SET_BCH_ALLOC_V4_NEED_INC_GEN(&a->v, false); SET_BCH_ALLOC_V4_NEED_INC_GEN(&a->v, false);
a->v.gen++; a->v.gen++;
a->v.data_type = 0; a->v.data_type = 0;
...@@ -1151,8 +1160,6 @@ static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca) ...@@ -1151,8 +1160,6 @@ static int invalidate_one_bucket(struct btree_trans *trans, struct bch_dev *ca)
BTREE_TRIGGER_BUCKET_INVALIDATE); BTREE_TRIGGER_BUCKET_INVALIDATE);
if (ret) if (ret)
goto out; goto out;
trace_invalidate_bucket(c, a->k.p.inode, a->k.p.offset);
out: out:
bch2_trans_iter_exit(trans, &alloc_iter); bch2_trans_iter_exit(trans, &alloc_iter);
bch2_trans_iter_exit(trans, &lru_iter); bch2_trans_iter_exit(trans, &lru_iter);
...@@ -1165,7 +1172,8 @@ static void bch2_do_invalidates_work(struct work_struct *work) ...@@ -1165,7 +1172,8 @@ static void bch2_do_invalidates_work(struct work_struct *work)
struct bch_fs *c = container_of(work, struct bch_fs, invalidate_work); struct bch_fs *c = container_of(work, struct bch_fs, invalidate_work);
struct bch_dev *ca; struct bch_dev *ca;
struct btree_trans trans; struct btree_trans trans;
unsigned i; struct bpos bucket;
unsigned i, sectors;
int ret = 0; int ret = 0;
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
...@@ -1178,10 +1186,12 @@ static void bch2_do_invalidates_work(struct work_struct *work) ...@@ -1178,10 +1186,12 @@ static void bch2_do_invalidates_work(struct work_struct *work)
ret = __bch2_trans_do(&trans, NULL, NULL, ret = __bch2_trans_do(&trans, NULL, NULL,
BTREE_INSERT_USE_RESERVE| BTREE_INSERT_USE_RESERVE|
BTREE_INSERT_NOFAIL, BTREE_INSERT_NOFAIL,
invalidate_one_bucket(&trans, ca)); invalidate_one_bucket(&trans, ca, &bucket,
&sectors));
if (ret) if (ret)
break; break;
trace_invalidate_bucket(c, bucket.inode, bucket.offset, sectors);
this_cpu_inc(c->counters[BCH_COUNTER_bucket_invalidate]); this_cpu_inc(c->counters[BCH_COUNTER_bucket_invalidate]);
} }
} }
......
...@@ -542,24 +542,27 @@ TRACE_EVENT(discard_buckets, ...@@ -542,24 +542,27 @@ TRACE_EVENT(discard_buckets,
); );
TRACE_EVENT(invalidate_bucket, TRACE_EVENT(invalidate_bucket,
TP_PROTO(struct bch_fs *c, unsigned dev, u64 bucket), TP_PROTO(struct bch_fs *c, unsigned dev, u64 bucket, u32 sectors),
TP_ARGS(c, dev, bucket), TP_ARGS(c, dev, bucket, sectors),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(dev_t, dev ) __field(dev_t, dev )
__field(u32, dev_idx ) __field(u32, dev_idx )
__field(u32, sectors )
__field(u64, bucket ) __field(u64, bucket )
), ),
TP_fast_assign( TP_fast_assign(
__entry->dev = c->dev; __entry->dev = c->dev;
__entry->dev_idx = dev; __entry->dev_idx = dev;
__entry->sectors = sectors;
__entry->bucket = bucket; __entry->bucket = bucket;
), ),
TP_printk("%d:%d invalidated %u:%llu", TP_printk("%d:%d invalidated %u:%llu cached sectors %u",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
__entry->dev_idx, __entry->bucket) __entry->dev_idx, __entry->bucket,
__entry->sectors)
); );
/* Moving IO */ /* Moving IO */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment