}
-unsigned int dmz_nr_unmap_rnd_zones(struct dmz_metadata *zmd)
+unsigned int dmz_nr_unmap_rnd_zones(struct dmz_metadata *zmd, int idx)
{
- unsigned int nr_unmap_rnd_zones = 0;
- int i;
-
- for (i = 0; i < zmd->nr_devs; i++)
- nr_unmap_rnd_zones += atomic_read(&zmd->dev[i].unmap_nr_rnd);
- return nr_unmap_rnd_zones;
+ return atomic_read(&zmd->dev[idx].unmap_nr_rnd);
}
unsigned int dmz_nr_cache_zones(struct dmz_metadata *zmd)
@@ -300,24 +295,14 @@ unsigned int dmz_nr_unmap_cache_zones(struct dmz_metadata *zmd)
return atomic_read(&zmd->unmap_nr_cache);
}
-unsigned int dmz_nr_seq_zones(struct dmz_metadata *zmd)
+unsigned int dmz_nr_seq_zones(struct dmz_metadata *zmd, int idx)
{
- unsigned int nr_seq_zones = 0;
- int i;
-
- for (i = 0; i < zmd->nr_devs; i++)
- nr_seq_zones += zmd->dev[i].nr_seq;
- return nr_seq_zones;
+ return zmd->dev[idx].nr_seq;
}
-unsigned int dmz_nr_unmap_seq_zones(struct dmz_metadata *zmd)
+unsigned int dmz_nr_unmap_seq_zones(struct dmz_metadata *zmd, int idx)
{
- unsigned int nr_unmap_seq_zones = 0;
- int i;
-
- for (i = 0; i < zmd->nr_devs; i++)
- nr_unmap_seq_zones += atomic_read(&zmd->dev[i].unmap_nr_seq);
- return nr_unmap_seq_zones;
+ return atomic_read(&zmd->dev[idx].unmap_nr_seq);
}
static struct dm_zone *dmz_get(struct dmz_metadata *zmd, unsigned int zone_id)
@@ -1530,7 +1515,20 @@ static int dmz_init_zones(struct dmz_metadata *zmd)
*/
zmd->sb[0].zone = dmz_get(zmd, 0);
- zoned_dev = &zmd->dev[1];
+ for (i = 1; i < zmd->nr_devs; i++) {
+ zoned_dev = &zmd->dev[i];
+
+ ret = blkdev_report_zones(zoned_dev->bdev, 0,
+ BLK_ALL_ZONES,
+ dmz_init_zone, zoned_dev);
+ if (ret < 0) {
+ DMDEBUG("(%s): Failed to report zones, error %d",
+ zmd->devname, ret);
+ dmz_drop_zones(zmd);
+ return ret;
+ }
+ }
+ return 0;
}
/*
@@ -2921,10 +2919,14 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev,
zmd->nr_data_zones, zmd->nr_chunks);
dmz_zmd_debug(zmd, " %u cache zones (%u unmapped)",
zmd->nr_cache, atomic_read(&zmd->unmap_nr_cache));
- dmz_zmd_debug(zmd, " %u random zones (%u unmapped)",
- dmz_nr_rnd_zones(zmd), dmz_nr_unmap_rnd_zones(zmd));
- dmz_zmd_debug(zmd, " %u sequential zones (%u unmapped)",
- dmz_nr_seq_zones(zmd), dmz_nr_unmap_seq_zones(zmd));
+ for (i = 0; i < zmd->nr_devs; i++) {
+ dmz_zmd_debug(zmd, " %u random zones (%u unmapped)",
+ dmz_nr_rnd_zones(zmd, i),
+ dmz_nr_unmap_rnd_zones(zmd, i));
+ dmz_zmd_debug(zmd, " %u sequential zones (%u unmapped)",
+ dmz_nr_seq_zones(zmd, i),
+ dmz_nr_unmap_seq_zones(zmd, i));
+ }
dmz_zmd_debug(zmd, " %u reserved sequential data zones",
zmd->nr_reserved_seq);
dmz_zmd_debug(zmd, "Format:");
diff --git a/drivers/md/dm-zoned-reclaim.c b/drivers/md/dm-zoned-reclaim.c
index fba0d48e38a7..f2e053b5f2db 100644
--- a/drivers/md/dm-zoned-reclaim.c
+++ b/drivers/md/dm-zoned-reclaim.c
@@ -442,15 +442,18 @@ static unsigned int dmz_reclaim_percentage(struct dmz_reclaim *zrc)
{
struct dmz_metadata *zmd = zrc->metadata;
unsigned int nr_cache = dmz_nr_cache_zones(zmd);
- unsigned int nr_rnd = dmz_nr_rnd_zones(zmd);
- unsigned int nr_unmap, nr_zones;
+ unsigned int nr_unmap = 0, nr_zones = 0;
if (nr_cache) {
nr_zones = nr_cache;
nr_unmap = dmz_nr_unmap_cache_zones(zmd);
} else {
- nr_zones = nr_rnd;
- nr_unmap = dmz_nr_unmap_rnd_zones(zmd);
+ int i;
+
+ for (i = 0; i < dmz_nr_devs(zmd); i++) {
+ nr_zones += dmz_nr_rnd_zones(zmd, i);
+ nr_unmap += dmz_nr_unmap_rnd_zones(zmd, i);
+ }
}
return nr_unmap * 100 / nr_zones;
}
@@ -460,7 +463,11 @@ static unsigned int dmz_reclaim_percentage(struct dmz_reclaim *zrc)
*/
static bool dmz_should_reclaim(struct dmz_reclaim *zrc, unsigned int p_unmap)
{
- unsigned int nr_reclaim = dmz_nr_rnd_zones(zrc->metadata);
+ int i;
+ unsigned int nr_reclaim = 0;
+
+ for (i = 0; i < dmz_nr_devs(zrc->metadata); i++)
+ nr_reclaim += dmz_nr_rnd_zones(zrc->metadata, i);
if (dmz_nr_cache_zones(zrc->metadata))
nr_reclaim += dmz_nr_cache_zones(zrc->metadata);
@@ -487,8 +494,8 @@ static void dmz_reclaim_work(struct work_struct *work)
{
struct dmz_reclaim *zrc = container_of(work, struct dmz_reclaim, work.work);
struct dmz_metadata *zmd = zrc->metadata;
- unsigned int p_unmap;
- int ret;
+ unsigned int p_unmap, nr_unmap_rnd = 0, nr_rnd = 0;
+ int ret, i;
if (dmz_dev_is_dying(zmd))
return;
@@ -513,14 +520,17 @@ static void dmz_reclaim_work(struct work_struct *work)
zrc->kc_throttle.throttle = min(75U, 100U - p_unmap / 2);
}
+ for (i = 0; i < dmz_nr_devs(zmd); i++) {
+ nr_unmap_rnd += dmz_nr_unmap_rnd_zones(zmd, i);
+ nr_rnd += dmz_nr_rnd_zones(zmd, i);
+ }
DMDEBUG("(%s): Reclaim (%u): %s, %u%% free zones (%u/%u cache %u/%u random)",
dmz_metadata_label(zmd),
zrc->kc_throttle.throttle,
(dmz_target_idle(zrc) ? "Idle" : "Busy"),
p_unmap, dmz_nr_unmap_cache_zones(zmd),
dmz_nr_cache_zones(zmd),
- dmz_nr_unmap_rnd_zones(zmd),
- dmz_nr_rnd_zones(zmd));
+ nr_unmap_rnd, nr_rnd);
ret = dmz_do_reclaim(zrc);
if (ret && ret != -EINTR) {