Skip to contentSkip to conversation

md: skip redundant raid_disks update when value is unchanged

PATCH Superseded Abd-Alrhman Masalkhi 2 participants 3 messages Apr 25 – Apr 28 MD RAID

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md: skip redundant raid_disks update when value is unchanged

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.

---
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(-)
drivers/md/md.c +6 -3
index 0e55639211f2..cb66c4ebbafa 100644
@@ -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;
 
Signature · 1 line
2.43.0
#1 lore raw

Hi,

Quoted 18 lines · 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.

---
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(-)
drivers/md/md.c +0 -0
index 0e55639211f2..cb66c4ebbafa 100644
@@ -4409,9 +4409,12 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
  	err = mddev_suspend_and_lock(mddev);

drivers/md/md.c raid_disks_store(struct mddev *mddev, const char *buf, size_t len) · line 4416

Quoted 10 lines
drivers/md/md.c +5 -3
  	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.

Quoted 4 lines
drivers/md/md.c +1 -0
+	} else if (mddev->reshape_position != MaxSector) {
  		struct md_rdev *rdev;
  		int olddisks = mddev->raid_disks - mddev->delta_disks;
 
Signature · 2 lines
Thansk,
Kuai
#2 lore raw
Quoted 26 lines · Yu Kuai

Hi,

Quoted 23 lines · 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.

---
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(-)
drivers/md/md.c +0 -3
index 0e55639211f2..cb66c4ebbafa 100644
@@ -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) {
Quoted 9 lines

drivers/md/md.c raid_disks_store(struct mddev *mddev, const char *buf, size_t len) · line 4416

Quoted 5 lines
drivers/md/md.c +5 -0
+	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.

Quoted 8 lines
Quoted 4 lines
drivers/md/md.c +1 -0
+	} else if (mddev->reshape_position != MaxSector) {
  		struct md_rdev *rdev;
  		int olddisks = mddev->raid_disks - mddev->delta_disks;
 
Signature · 2 lines
Thansk,
Kuai
Signature · 2 lines
Best Regards,
Abd-Alrhman