Skip to content

Commit 0af8a06

Browse files
author
Kent Overstreet
committed
bcachefs: deallocate_extra_replicas()
When allocating from devices with different durability, we might end up with more replicas than required; this changes bch2_alloc_sectors_start() to check for this, and drop replicas that aren't needed to hit the number of replicas requested. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 8a443d3 commit 0af8a06

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

fs/bcachefs/alloc_foreground.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,30 @@ static struct write_point *writepoint_find(struct btree_trans *trans,
12971297
return wp;
12981298
}
12991299

1300+
static noinline void
1301+
deallocate_extra_replicas(struct bch_fs *c,
1302+
struct open_buckets *ptrs,
1303+
struct open_buckets *ptrs_no_use,
1304+
unsigned extra_replicas)
1305+
{
1306+
struct open_buckets ptrs2 = { 0 };
1307+
struct open_bucket *ob;
1308+
unsigned i;
1309+
1310+
open_bucket_for_each(c, ptrs, ob, i) {
1311+
unsigned d = bch_dev_bkey_exists(c, ob->dev)->mi.durability;
1312+
1313+
if (d && d <= extra_replicas) {
1314+
extra_replicas -= d;
1315+
ob_push(c, ptrs_no_use, ob);
1316+
} else {
1317+
ob_push(c, &ptrs2, ob);
1318+
}
1319+
}
1320+
1321+
*ptrs = ptrs2;
1322+
}
1323+
13001324
/*
13011325
* Get us an open_bucket we can allocate from, return with it locked:
13021326
*/
@@ -1385,6 +1409,9 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
13851409
if (ret)
13861410
goto err;
13871411

1412+
if (nr_effective > nr_replicas)
1413+
deallocate_extra_replicas(c, &ptrs, &wp->ptrs, nr_effective - nr_replicas);
1414+
13881415
/* Free buckets we didn't use: */
13891416
open_bucket_for_each(c, &wp->ptrs, ob, i)
13901417
open_bucket_free_unused(c, ob);

0 commit comments

Comments
 (0)