summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-01-03 23:14:43 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2018-05-22 00:44:18 -0400
commit911809c52ae8fa8eef5a0cdd405d3388959b82f9 (patch)
tree0e50dce5cee477c4f57a20ba4dee3005d2eadf14
parenta74233222b463dd3fcd4f665d0c3a79f892741eb (diff)
bcachefs: bch_move_stats
-rw-r--r--fs/bcachefs/migrate.c9
-rw-r--r--fs/bcachefs/move.c77
-rw-r--r--fs/bcachefs/move.h12
-rw-r--r--fs/bcachefs/movinggc.c7
-rw-r--r--fs/bcachefs/tier.c6
5 files changed, 52 insertions, 59 deletions
diff --git a/fs/bcachefs/migrate.c b/fs/bcachefs/migrate.c
index 35f12f60b2df..2033db817333 100644
--- a/fs/bcachefs/migrate.c
+++ b/fs/bcachefs/migrate.c
@@ -27,7 +27,7 @@ static int bch2_dev_usrdata_migrate(struct bch_fs *c, struct bch_dev *ca,
{
struct btree_iter iter;
struct bkey_s_c k;
- u64 keys_moved, sectors_moved;
+ struct bch_move_stats stats;
unsigned pass = 0;
int ret = 0;
@@ -47,15 +47,14 @@ static int bch2_dev_usrdata_migrate(struct bch_fs *c, struct bch_dev *ca,
0,
ca->dev_idx,
migrate_pred, ca,
- &keys_moved,
- &sectors_moved);
+ &stats);
if (ret) {
bch_err(c, "error migrating data: %i", ret);
return ret;
}
- } while (keys_moved && pass++ < MAX_DATA_OFF_ITER);
+ } while (atomic64_read(&stats.keys_moved) && pass++ < MAX_DATA_OFF_ITER);
- if (keys_moved) {
+ if (atomic64_read(&stats.keys_moved)) {
bch_err(c, "unable to migrate all data in %d iterations",
MAX_DATA_OFF_ITER);
return -1;
diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c
index 1df7ceed6875..b2c228e36459 100644
--- a/fs/bcachefs/move.c
+++ b/fs/bcachefs/move.c
@@ -31,15 +31,10 @@ struct moving_context {
/* Closure for waiting on all reads and writes to complete */
struct closure cl;
- /* Key and sector moves issued, updated from submission context */
- u64 keys_moved;
- u64 sectors_moved;
- atomic64_t sectors_raced;
+ struct bch_move_stats *stats;
struct list_head reads;
-
atomic_t sectors_in_flight;
-
wait_queue_head_t wait;
};
@@ -145,7 +140,7 @@ next:
nomatch:
if (m->ctxt)
atomic64_add(k.k->p.offset - iter.pos.offset,
- &m->ctxt->sectors_raced);
+ &m->ctxt->stats->sectors_raced);
atomic_long_inc(&c->extent_migrate_raced);
trace_move_race(&new->k);
bch2_btree_iter_advance_pos(&iter);
@@ -303,8 +298,8 @@ static int bch2_move_extent(struct bch_fs *c,
io->write.op.devs = devs;
io->write.op.write_point = wp;
- ctxt->keys_moved++;
- ctxt->sectors_moved += k.k->size;
+ atomic64_inc(&ctxt->stats->keys_moved);
+ atomic64_add(k.k->size, &ctxt->stats->sectors_moved);
trace_move_extent(k.k);
@@ -353,24 +348,6 @@ static void bch2_move_ctxt_wait_for_io(struct moving_context *ctxt)
atomic_read(&ctxt->sectors_in_flight) != sectors_pending);
}
-static void bch2_move_ctxt_exit(struct moving_context *ctxt)
-{
- move_ctxt_wait_event(ctxt, !atomic_read(&ctxt->sectors_in_flight));
- closure_sync(&ctxt->cl);
-
- EBUG_ON(!list_empty(&ctxt->reads));
- EBUG_ON(atomic_read(&ctxt->sectors_in_flight));
-}
-
-static void bch2_move_ctxt_init(struct moving_context *ctxt)
-{
- memset(ctxt, 0, sizeof(*ctxt));
- closure_init_stack(&ctxt->cl);
-
- INIT_LIST_HEAD(&ctxt->reads);
- init_waitqueue_head(&ctxt->wait);
-}
-
int bch2_move_data(struct bch_fs *c,
struct bch_ratelimit *rate,
unsigned sectors_in_flight,
@@ -379,20 +356,21 @@ int bch2_move_data(struct bch_fs *c,
int btree_insert_flags,
int move_device,
move_pred_fn pred, void *arg,
- u64 *keys_moved,
- u64 *sectors_moved)
+ struct bch_move_stats *stats)
{
bool kthread = (current->flags & PF_KTHREAD) != 0;
- struct moving_context ctxt;
+ struct moving_context ctxt = { .stats = stats };
struct bch_io_opts opts = bch2_opts_to_inode_opts(c->opts);
- struct btree_iter iter;
BKEY_PADDED(k) tmp;
struct bkey_s_c k;
u64 cur_inum = U64_MAX;
int ret = 0;
- bch2_move_ctxt_init(&ctxt);
- bch2_btree_iter_init(&iter, c, BTREE_ID_EXTENTS, POS_MIN,
+ memset(stats, 0, sizeof(*stats));
+ closure_init_stack(&ctxt.cl);
+ INIT_LIST_HEAD(&ctxt.reads);
+ init_waitqueue_head(&ctxt.wait);
+ bch2_btree_iter_init(&stats->iter, c, BTREE_ID_EXTENTS, POS_MIN,
BTREE_ITER_PREFETCH);
if (rate)
@@ -400,7 +378,7 @@ int bch2_move_data(struct bch_fs *c,
while (!kthread || !(ret = kthread_should_stop())) {
if (atomic_read(&ctxt.sectors_in_flight) >= sectors_in_flight) {
- bch2_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&stats->iter);
move_ctxt_wait_event(&ctxt,
atomic_read(&ctxt.sectors_in_flight) <
sectors_in_flight);
@@ -408,11 +386,11 @@ int bch2_move_data(struct bch_fs *c,
if (rate &&
bch2_ratelimit_delay(rate) &&
- (bch2_btree_iter_unlock(&iter),
+ (bch2_btree_iter_unlock(&stats->iter),
(ret = bch2_ratelimit_wait_freezable_stoppable(rate))))
break;
peek:
- k = bch2_btree_iter_peek(&iter);
+ k = bch2_btree_iter_peek(&stats->iter);
if (!k.k)
break;
ret = btree_iter_err(k);
@@ -420,13 +398,13 @@ peek:
break;
if (!bkey_extent_is_data(k.k))
- goto next;
+ goto next_nondata;
if (cur_inum != k.k->p.inode) {
struct bch_inode_unpacked inode;
/* don't hold btree locks while looking up inode: */
- bch2_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&stats->iter);
opts = bch2_opts_to_inode_opts(c->opts);
if (!bch2_inode_find_by_inum(c, k.k->p.inode, &inode))
@@ -441,7 +419,7 @@ peek:
/* unlock before doing IO: */
bkey_reassemble(&tmp.k, k);
k = bkey_i_to_s_c(&tmp.k);
- bch2_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&stats->iter);
if (bch2_move_extent(c, &ctxt, devs, wp,
btree_insert_flags,
@@ -454,17 +432,24 @@ peek:
if (rate)
bch2_ratelimit_increment(rate, k.k->size);
next:
- bch2_btree_iter_advance_pos(&iter);
- bch2_btree_iter_cond_resched(&iter);
+ atomic64_add(k.k->size * bch2_extent_nr_dirty_ptrs(k),
+ &stats->sectors_seen);
+next_nondata:
+ bch2_btree_iter_advance_pos(&stats->iter);
+ bch2_btree_iter_cond_resched(&stats->iter);
}
- bch2_btree_iter_unlock(&iter);
- bch2_move_ctxt_exit(&ctxt);
+ bch2_btree_iter_unlock(&stats->iter);
+
+ move_ctxt_wait_event(&ctxt, !atomic_read(&ctxt.sectors_in_flight));
+ closure_sync(&ctxt.cl);
- trace_move_data(c, ctxt.sectors_moved, ctxt.keys_moved);
+ EBUG_ON(!list_empty(&ctxt.reads));
+ EBUG_ON(atomic_read(&ctxt.sectors_in_flight));
- *keys_moved = ctxt.keys_moved;
- *sectors_moved = ctxt.sectors_moved;
+ trace_move_data(c,
+ atomic64_read(&stats->sectors_moved),
+ atomic64_read(&stats->keys_moved));
return ret;
}
diff --git a/fs/bcachefs/move.h b/fs/bcachefs/move.h
index 2e884ce0f62d..24d6ddfa9637 100644
--- a/fs/bcachefs/move.h
+++ b/fs/bcachefs/move.h
@@ -1,6 +1,7 @@
#ifndef _BCACHEFS_MOVE_H
#define _BCACHEFS_MOVE_H
+#include "btree_iter.h"
#include "buckets.h"
#include "io_types.h"
@@ -25,10 +26,19 @@ void bch2_migrate_write_init(struct migrate_write *, struct bch_read_bio *);
typedef bool (*move_pred_fn)(void *, struct bkey_s_c_extent);
+struct bch_move_stats {
+ struct btree_iter iter;
+
+ atomic64_t keys_moved;
+ atomic64_t sectors_moved;
+ atomic64_t sectors_seen;
+ atomic64_t sectors_raced;
+};
+
int bch2_move_data(struct bch_fs *, struct bch_ratelimit *,
unsigned, struct bch_devs_mask *,
struct write_point_specifier,
int, int, move_pred_fn, void *,
- u64 *, u64 *);
+ struct bch_move_stats *);
#endif /* _BCACHEFS_MOVE_H */
diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c
index 90eb4ca2959f..d6f2968ec4b1 100644
--- a/fs/bcachefs/movinggc.c
+++ b/fs/bcachefs/movinggc.c
@@ -100,7 +100,7 @@ static void bch2_copygc(struct bch_fs *c, struct bch_dev *ca)
copygc_heap *h = &ca->copygc_heap;
struct copygc_heap_entry e, *i;
struct bucket_array *buckets;
- u64 keys_moved, sectors_moved;
+ struct bch_move_stats move_stats;
u64 sectors_to_move = 0, sectors_not_moved = 0;
u64 buckets_to_move, buckets_not_moved = 0;
size_t b;
@@ -167,8 +167,7 @@ static void bch2_copygc(struct bch_fs *c, struct bch_dev *ca)
BTREE_INSERT_USE_RESERVE,
ca->dev_idx,
copygc_pred, ca,
- &keys_moved,
- &sectors_moved);
+ &move_stats);
down_read(&ca->bucket_lock);
buckets = bucket_array(ca);
@@ -189,7 +188,7 @@ static void bch2_copygc(struct bch_fs *c, struct bch_dev *ca)
buckets_not_moved, buckets_to_move);
trace_copygc(ca,
- sectors_moved, sectors_not_moved,
+ atomic64_read(&move_stats.sectors_moved), sectors_not_moved,
buckets_to_move, buckets_not_moved);
}
diff --git a/fs/bcachefs/tier.c b/fs/bcachefs/tier.c
index f5007864c6b6..6a581097a7e6 100644
--- a/fs/bcachefs/tier.c
+++ b/fs/bcachefs/tier.c
@@ -39,7 +39,8 @@ static int bch2_tiering_thread(void *arg)
struct bch_fs *c = container_of(tier, struct bch_fs, tiers[tier->idx]);
struct io_clock *clock = &c->io_clock[WRITE];
struct bch_dev *ca;
- u64 tier_capacity, available_sectors, keys_moved, sectors_moved;
+ struct bch_move_stats move_stats;
+ u64 tier_capacity, available_sectors;
unsigned long last;
unsigned i, nr_devices;
@@ -91,8 +92,7 @@ static int bch2_tiering_thread(void *arg)
0,
-1,
tiering_pred, tier,
- &keys_moved,
- &sectors_moved);
+ &move_stats);
}
return 0;