[PATCH 13/15] md/raid1: clean up sync IO size calculation in raid1_sync_request

[email protected]
Newsgroups gmane.linux.kernel,gmane.linux.raid
Message-ID <[email protected]>
From: Li Nan <[email protected]>

Use 'nr_sectors' directly for sync IO size calculation. Prepare folio
allocation failure fallback.

No functional changes.

Signed-off-by: Li Nan <[email protected]>
---
 drivers/md/raid1.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 38f86de45dea..2be2277d4e7e 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2970,21 +2970,19 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
 		max_sector = mddev->resync_max; /* Don't do IO beyond here */
 	if (max_sector > sector_nr + good_sectors)
 		max_sector = sector_nr + good_sectors;
-	nr_sectors = 0;
 	do {
 		struct folio *folio;
-		int len = RESYNC_BLOCK_SIZE;
-		if (sector_nr + (len>>9) > max_sector)
-			len = (max_sector - sector_nr) << 9;
-		if (len == 0)
+
+		nr_sectors = max_sector - sector_nr;
+		if (nr_sectors == 0)
 			break;
 		if (!md_bitmap_start_sync(mddev, sector_nr,
 					  &sync_blocks, still_degraded) &&
 		    !conf->fullsync &&
 		    !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
 			break;
-		if ((len >> 9) > sync_blocks)
-			len = sync_blocks<<9;
+		if (nr_sectors > sync_blocks)
+			nr_sectors = sync_blocks;
 
 		for (i = 0 ; i < conf->raid_disks * 2; i++) {
 			struct resync_folio *rf;
@@ -2998,11 +2996,10 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
 				 * won't fail because the vec table is big
 				 * enough to hold all these pages
 				 */
-				bio_add_folio_nofail(bio, folio, len, 0);
+				bio_add_folio_nofail(bio, folio, nr_sectors << 9, 0);
 			}
 		}
-		nr_sectors += len>>9;
-		sector_nr += len>>9;
+		sector_nr += nr_sectors;
 	} while (0);
 
 	r1_bio->sectors = nr_sectors;
-- 
2.39.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.