public inbox for linux-raid@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] md: skip redundant raid_disks update when value is unchanged
@ 2026-04-25  8:58 Abd-Alrhman Masalkhi
  2026-04-28  8:25 ` Yu Kuai
  0 siblings, 1 reply; 3+ messages in thread
From: Abd-Alrhman Masalkhi @ 2026-04-25  8:58 UTC (permalink / raw)
  To: song, yukuai; +Cc: linux-raid, linux-kernel, Abd-Alrhman Masalkhi

Calling update_raid_disks() with the same value as the current one
can trigger unnecessary work. For example, RAID1 will reallocate
resources such as the mempool for r1bio.

Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
---
It returns -EINVAL for the same value. If silent success is preferred
instead, please let me know so I adjust its behavior.
---
 drivers/md/md.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 0e55639211f2..cb66c4ebbafa 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4409,9 +4409,12 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
 	err = mddev_suspend_and_lock(mddev);
 	if (err)
 		return err;
-	if (mddev->pers)
-		err = update_raid_disks(mddev, n);
-	else if (mddev->reshape_position != MaxSector) {
+	if (mddev->pers) {
+		if (n != mddev->raid_disks)
+			err = update_raid_disks(mddev, n);
+		else
+			err = -EINVAL;
+	} else if (mddev->reshape_position != MaxSector) {
 		struct md_rdev *rdev;
 		int olddisks = mddev->raid_disks - mddev->delta_disks;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] md: skip redundant raid_disks update when value is unchanged
  2026-04-25  8:58 [PATCH] md: skip redundant raid_disks update when value is unchanged Abd-Alrhman Masalkhi
@ 2026-04-28  8:25 ` Yu Kuai
  2026-04-28  9:56   ` Abd-Alrhman Masalkhi
  0 siblings, 1 reply; 3+ messages in thread
From: Yu Kuai @ 2026-04-28  8:25 UTC (permalink / raw)
  To: Abd-Alrhman Masalkhi, song; +Cc: linux-raid, linux-kernel, yukuai

Hi,

在 2026/4/25 16:58, Abd-Alrhman Masalkhi 写道:
> Calling update_raid_disks() with the same value as the current one
> can trigger unnecessary work. For example, RAID1 will reallocate
> resources such as the mempool for r1bio.
>
> Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
> ---
> It returns -EINVAL for the same value. If silent success is preferred
> instead, please let me know so I adjust its behavior.
> ---
>   drivers/md/md.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 0e55639211f2..cb66c4ebbafa 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -4409,9 +4409,12 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
>   	err = mddev_suspend_and_lock(mddev);
>   	if (err)
>   		return err;
> -	if (mddev->pers)
> -		err = update_raid_disks(mddev, n);
> -	else if (mddev->reshape_position != MaxSector) {
> +	if (mddev->pers) {
> +		if (n != mddev->raid_disks)
> +			err = update_raid_disks(mddev, n);
> +		else
> +			err = -EINVAL;

Changing return value in this case is not expected, especially from
success to failure.

> +	} else if (mddev->reshape_position != MaxSector) {
>   		struct md_rdev *rdev;
>   		int olddisks = mddev->raid_disks - mddev->delta_disks;
>   

-- 
Thansk,
Kuai

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] md: skip redundant raid_disks update when value is unchanged
  2026-04-28  8:25 ` Yu Kuai
@ 2026-04-28  9:56   ` Abd-Alrhman Masalkhi
  0 siblings, 0 replies; 3+ messages in thread
From: Abd-Alrhman Masalkhi @ 2026-04-28  9:56 UTC (permalink / raw)
  To: Yu Kuai, song; +Cc: linux-raid, linux-kernel, yukuai

On Tue, Apr 28, 2026 at 16:25 +0800, Yu Kuai wrote:
> Hi,
>
> 在 2026/4/25 16:58, Abd-Alrhman Masalkhi 写道:
>> Calling update_raid_disks() with the same value as the current one
>> can trigger unnecessary work. For example, RAID1 will reallocate
>> resources such as the mempool for r1bio.
>>
>> Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
>> ---
>> It returns -EINVAL for the same value. If silent success is preferred
>> instead, please let me know so I adjust its behavior.
>> ---
>>   drivers/md/md.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index 0e55639211f2..cb66c4ebbafa 100644
>> --- a/drivers/md/md.c
>> +++ b/drivers/md/md.c
>> @@ -4409,9 +4409,12 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
>>   	err = mddev_suspend_and_lock(mddev);
>>   	if (err)
>>   		return err;
>> -	if (mddev->pers)
>> -		err = update_raid_disks(mddev, n);
>> -	else if (mddev->reshape_position != MaxSector) {
>> +	if (mddev->pers) {
>> +		if (n != mddev->raid_disks)
>> +			err = update_raid_disks(mddev, n);
>> +		else
>> +			err = -EINVAL;
>
> Changing return value in this case is not expected, especially from
> success to failure.
>

I’ll adjust the behavior to return success instead.

>> +	} else if (mddev->reshape_position != MaxSector) {
>>   		struct md_rdev *rdev;
>>   		int olddisks = mddev->raid_disks - mddev->delta_disks;
>>   
>
> -- 
> Thansk,
> Kuai

-- 
Best Regards,
Abd-Alrhman

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-28  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-25  8:58 [PATCH] md: skip redundant raid_disks update when value is unchanged Abd-Alrhman Masalkhi
2026-04-28  8:25 ` Yu Kuai
2026-04-28  9:56   ` Abd-Alrhman Masalkhi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox