[PATCH 02/23] md: factor out a helper raid_is_456()

Yu Kuai posted 23 patches 6 months, 4 weeks ago
There is a newer version of this series
[PATCH 02/23] md: factor out a helper raid_is_456()
Posted by Yu Kuai 6 months, 4 weeks ago
From: Yu Kuai <yukuai3@huawei.com>

There are no functional changes, the helper will be used by llbitmap in
following patches.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/md.c | 9 +--------
 drivers/md/md.h | 6 ++++++
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 18e03f651f6b..b0468e795d94 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9037,19 +9037,12 @@ static sector_t md_sync_position(struct mddev *mddev, enum sync_action action)
 
 static bool sync_io_within_limit(struct mddev *mddev)
 {
-	int io_sectors;
-
 	/*
 	 * For raid456, sync IO is stripe(4k) per IO, for other levels, it's
 	 * RESYNC_PAGES(64k) per IO.
 	 */
-	if (mddev->level == 4 || mddev->level == 5 || mddev->level == 6)
-		io_sectors = 8;
-	else
-		io_sectors = 128;
-
 	return atomic_read(&mddev->recovery_active) <
-		io_sectors * sync_io_depth(mddev);
+	       (raid_is_456(mddev) ? 8 : 128) * sync_io_depth(mddev);
 }
 
 #define SYNC_MARKS	10
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 5ba4a9093a92..c241119e6ef3 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -1011,6 +1011,12 @@ static inline bool mddev_is_dm(struct mddev *mddev)
 	return !mddev->gendisk;
 }
 
+static inline bool raid_is_456(struct mddev *mddev)
+{
+	return mddev->level == ID_RAID4 || mddev->level == ID_RAID5 ||
+	       mddev->level == ID_RAID6;
+}
+
 static inline void mddev_trace_remap(struct mddev *mddev, struct bio *bio,
 		sector_t sector)
 {
-- 
2.39.2
Re: [PATCH 02/23] md: factor out a helper raid_is_456()
Posted by Hannes Reinecke 6 months, 3 weeks ago
On 5/24/25 08:12, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> There are no functional changes, the helper will be used by llbitmap in
> following patches.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>   drivers/md/md.c | 9 +--------
>   drivers/md/md.h | 6 ++++++
>   2 files changed, 7 insertions(+), 8 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Re: [PATCH 02/23] md: factor out a helper raid_is_456()
Posted by Christoph Hellwig 6 months, 3 weeks ago
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Re: [PATCH 02/23] md: factor out a helper raid_is_456()
Posted by Xiao Ni 6 months, 4 weeks ago
On Sat, May 24, 2025 at 2:18 PM Yu Kuai <yukuai1@huaweicloud.com> wrote:
>
> From: Yu Kuai <yukuai3@huawei.com>
>
> There are no functional changes, the helper will be used by llbitmap in
> following patches.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>  drivers/md/md.c | 9 +--------
>  drivers/md/md.h | 6 ++++++
>  2 files changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 18e03f651f6b..b0468e795d94 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -9037,19 +9037,12 @@ static sector_t md_sync_position(struct mddev *mddev, enum sync_action action)
>
>  static bool sync_io_within_limit(struct mddev *mddev)
>  {
> -       int io_sectors;
> -
>         /*
>          * For raid456, sync IO is stripe(4k) per IO, for other levels, it's
>          * RESYNC_PAGES(64k) per IO.
>          */
> -       if (mddev->level == 4 || mddev->level == 5 || mddev->level == 6)
> -               io_sectors = 8;
> -       else
> -               io_sectors = 128;
> -
>         return atomic_read(&mddev->recovery_active) <
> -               io_sectors * sync_io_depth(mddev);
> +              (raid_is_456(mddev) ? 8 : 128) * sync_io_depth(mddev);
>  }
>
>  #define SYNC_MARKS     10
> diff --git a/drivers/md/md.h b/drivers/md/md.h
> index 5ba4a9093a92..c241119e6ef3 100644
> --- a/drivers/md/md.h
> +++ b/drivers/md/md.h
> @@ -1011,6 +1011,12 @@ static inline bool mddev_is_dm(struct mddev *mddev)
>         return !mddev->gendisk;
>  }
>
> +static inline bool raid_is_456(struct mddev *mddev)
> +{
> +       return mddev->level == ID_RAID4 || mddev->level == ID_RAID5 ||
> +              mddev->level == ID_RAID6;
> +}
> +
>  static inline void mddev_trace_remap(struct mddev *mddev, struct bio *bio,
>                 sector_t sector)
>  {
> --
> 2.39.2
>

Reviewed-by: Xiao Ni <xni@redhat.com>