summaryrefslogtreecommitdiff
path: root/libbcachefs/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbcachefs/alloc.c')
-rw-r--r--libbcachefs/alloc.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/libbcachefs/alloc.c b/libbcachefs/alloc.c
index f7ff8027..f3833846 100644
--- a/libbcachefs/alloc.c
+++ b/libbcachefs/alloc.c
@@ -1859,6 +1859,27 @@ int bch2_dev_allocator_start(struct bch_dev *ca)
return 0;
}
+static void allocator_start_issue_discards(struct bch_fs *c)
+{
+ struct bch_dev *ca;
+ unsigned i, dev_iter;
+ size_t bu;
+
+ for_each_rw_member(ca, c, dev_iter) {
+ unsigned done = 0;
+
+ fifo_for_each_entry(bu, &ca->free_inc, i) {
+ if (done == ca->nr_invalidated)
+ break;
+
+ blkdev_issue_discard(ca->disk_sb.bdev,
+ bucket_to_sector(ca, bu),
+ ca->mi.bucket_size, GFP_NOIO, 0);
+ done++;
+ }
+ }
+}
+
static int __bch2_fs_allocator_start(struct bch_fs *c)
{
struct bch_dev *ca;
@@ -1938,6 +1959,8 @@ static int __bch2_fs_allocator_start(struct bch_fs *c)
*/
if (invalidating_data)
set_bit(BCH_FS_HOLD_BTREE_WRITES, &c->flags);
+ else
+ allocator_start_issue_discards(c);
/*
* XXX: it's possible for this to deadlock waiting on journal reclaim,
@@ -1959,12 +1982,12 @@ static int __bch2_fs_allocator_start(struct bch_fs *c)
return ret;
}
+ if (invalidating_data)
+ allocator_start_issue_discards(c);
+
for_each_rw_member(ca, c, dev_iter)
while (ca->nr_invalidated) {
BUG_ON(!fifo_pop(&ca->free_inc, bu));
- blkdev_issue_discard(ca->disk_sb.bdev,
- bucket_to_sector(ca, bu),
- ca->mi.bucket_size, GFP_NOIO, 0);
ca->nr_invalidated--;
}
@@ -1983,7 +2006,7 @@ again:
if (btree_node_dirty(b) && (!b->written || b->level)) {
rcu_read_unlock();
six_lock_read(&b->lock);
- bch2_btree_node_write(c, b, NULL, SIX_LOCK_read);
+ bch2_btree_node_write(c, b, SIX_LOCK_read);
six_unlock_read(&b->lock);
goto again;
}