[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20230504124828.679770-12-linan666@huaweicloud.com>
Date: Thu, 4 May 2023 20:48:28 +0800
From: linan666@...weicloud.com
To: axboe@...nel.dk, linan122@...wei.com, vishal.l.verma@...el.com,
dan.j.williams@...el.com
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
yukuai3@...wei.com, yi.zhang@...wei.com, houtao1@...wei.com,
yangerkun@...wei.com
Subject: [PATCH v2 11/11] block/badblocks: try to merge badblocks as much as possible
From: Li Nan <linan122@...wei.com>
If we set a new badblocks, we first merge it with existing region, then
try to combine lo and hi. If there are still badblocks need to be set,
create it. It is a bad way when setting a laget number of badblocks. for
example, it will become chaotic if we set as below:
# echo 1 1 > bad_blocks
# echo 512 1 > bad_blocks
# echo 0 513 > bad_blocks
# cat bad_blocks
0 512
512 1
512 1
Fix it by trying to merge as much as possible. If we have merged any
badblocks, retry to merge next sectors. Do not check sectors while
combining, we should combine lo and hi each sycle.
Fixes: 9e0e252a048b ("badblocks: Add core badblock management code")
Signed-off-by: Li Nan <linan122@...wei.com>
---
block/badblocks.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/block/badblocks.c b/block/badblocks.c
index bb0324b66f57..7e6fce10c82d 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -347,8 +347,6 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
lo = 0;
hi = bb->count;
if (bb->count) {
- int merged_sectors;
-
/* Find the last range that starts at-or-before 's' */
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
@@ -360,12 +358,19 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
hi = mid;
}
- merged_sectors = badblocks_merge(bb, s, sectors, acknowledged,
- &lo, &hi, &changed);
- s += merged_sectors;
- sectors -= merged_sectors;
- if (sectors == 0)
+ while (sectors) {
+ int merged_sectors;
+
+ merged_sectors = badblocks_merge(bb, s, sectors, acknowledged,
+ &lo, &hi, &changed);
+ /* can't merge, break to create */
+ if (!merged_sectors)
+ break;
+
+ s += merged_sectors;
+ sectors -= merged_sectors;
badblocks_combine(bb, lo);
+ }
}
rv = badblocks_create(bb, s, sectors, hi, acknowledged, &changed);
--
2.31.1
Powered by blists - more mailing lists