Skip to content

Commit 90e0be5

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubi: fastmap: Fix lapsed wear leveling for first 64 PEBs
The anchor PEB must be picked from first 64 PEBs, these PEBs could have large erase counter greater than other PEBs especially when free space is nearly running out. The ubi_update_fastmap will be called as long as pool/wl_pool is empty, old anchor PEB is erased when updating fastmap. Given an UBI device with N PEBs, free PEBs is nearly running out and pool will be filled with 1 PEB every time ubi_update_fastmap invoked. So t=N/POOL_SIZE[1]/64 means that in worst case the erase counter of first 64 PEBs is t times greater than other PEBs in theory. After running fsstress for 24h, the erase counter statistics for two UBI devices shown as follow(CONFIG_MTD_UBI_WL_THRESHOLD=128): Device A(1024 PEBs, pool=50, wl_pool=25): ========================================================= from to count min avg max --------------------------------------------------------- 0 .. 9: 0 0 0 0 10 .. 99: 0 0 0 0 100 .. 999: 0 0 0 0 1000 .. 9999: 0 0 0 0 10000 .. 99999: 960 29224 29282 29362 100000 .. inf: 64 117897 117934 117940 --------------------------------------------------------- Total : 1024 29224 34822 117940 Device B(8192 PEBs, pool=256, wl_pool=128): ========================================================= from to count min avg max --------------------------------------------------------- 0 .. 9: 0 0 0 0 10 .. 99: 0 0 0 0 100 .. 999: 0 0 0 0 1000 .. 9999: 8128 2253 2321 2387 10000 .. 99999: 64 35387 35387 35388 100000 .. inf: 0 0 0 0 --------------------------------------------------------- Total : 8192 2253 2579 35388 The key point is reducing fastmap updating frequency by enlarging POOL_SIZE, so let UBI reserve ubi->fm_pool.max_size PEBs during attaching. Then POOL_SIZE will become ubi->fm_pool.max_size/2 even in free space running out case. Given an UBI device with 8192 PEBs(16384\8192\4096 is common large-capacity flash), t=8192/128/64=1. The fastmap updating will happen in either wl_pool or pool is empty, so setting fm_pool_rsv_cnt as ubi->fm_pool.max_size can fill wl_pool in full state. After pool reservation, running fsstress for 24h: Device A(1024 PEBs, pool=50, wl_pool=25): ========================================================= from to count min avg max --------------------------------------------------------- 0 .. 9: 0 0 0 0 10 .. 99: 0 0 0 0 100 .. 999: 0 0 0 0 1000 .. 9999: 0 0 0 0 10000 .. 99999: 1024 33801 33997 34056 100000 .. inf: 0 0 0 0 --------------------------------------------------------- Total : 1024 33801 33997 34056 Device B(8192 PEBs, pool=256, wl_pool=128): ========================================================= from to count min avg max --------------------------------------------------------- 0 .. 9: 0 0 0 0 10 .. 99: 0 0 0 0 100 .. 999: 0 0 0 0 1000 .. 9999: 8192 2205 2397 2460 10000 .. 99999: 0 0 0 0 100000 .. inf: 0 0 0 0 --------------------------------------------------------- Total : 8192 2205 2397 2460 The difference of erase counter between first 64 PEBs and others is under WL_FREE_MAX_DIFF(2*UBI_WL_THRESHOLD=2*128=256). Device A: 34056 - 33801 = 255 Device B: 2460 - 2205 = 255 Next patch will add a switch to control whether UBI needs to reserve PEBs for filling pool. Fixes: dbb7d2a ("UBI: Add fastmap core") Link: https://bugzilla.kernel.org/show_bug.cgi?id=217787 Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 761893b commit 90e0be5

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

drivers/mtd/ubi/build.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
951951
UBI_FM_MIN_POOL_SIZE);
952952

953953
ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2;
954+
ubi->fm_pool_rsv_cnt = ubi->fm_pool.max_size;
954955
ubi->fm_disabled = (!fm_autoconvert || disable_fm) ? 1 : 0;
955956
if (fm_debug)
956957
ubi_enable_dbg_chk_fastmap(ubi);

drivers/mtd/ubi/fastmap-wl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static void wait_free_pebs_for_pool(struct ubi_device *ubi)
118118
* 4. beb_rsvd_pebs: This value should be get under lock ubi->wl_lock
119119
*/
120120
int reserved = WL_RESERVED_PEBS + EBA_RESERVED_PEBS +
121-
ubi->fm_size / ubi->leb_size - 1;
121+
ubi->fm_size / ubi->leb_size - 1 + ubi->fm_pool_rsv_cnt;
122122

123123
do {
124124
spin_lock(&ubi->wl_lock);

drivers/mtd/ubi/ubi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ struct ubi_debug_info {
494494
* @fast_attach: non-zero if UBI was attached by fastmap
495495
* @fm_anchor: The next anchor PEB to use for fastmap
496496
* @fm_do_produce_anchor: If true produce an anchor PEB in wl
497+
* @fm_pool_rsv_cnt: Number of reserved PEBs for filling pool/wl_pool
497498
*
498499
* @used: RB-tree of used physical eraseblocks
499500
* @erroneous: RB-tree of erroneous used physical eraseblocks
@@ -604,6 +605,7 @@ struct ubi_device {
604605
int fast_attach;
605606
struct ubi_wl_entry *fm_anchor;
606607
int fm_do_produce_anchor;
608+
int fm_pool_rsv_cnt;
607609

608610
/* Wear-leveling sub-system's stuff */
609611
struct rb_root used;

drivers/mtd/ubi/wl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ static bool need_wear_leveling(struct ubi_device *ubi);
1010
static void ubi_fastmap_close(struct ubi_device *ubi);
1111
static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count)
1212
{
13-
/* Reserve enough LEBs to store two fastmaps. */
14-
*count += (ubi->fm_size / ubi->leb_size) * 2;
13+
if (ubi->fm_disabled)
14+
ubi->fm_pool_rsv_cnt = 0;
15+
/* Reserve enough LEBs to store two fastmaps and to fill pools. */
16+
*count += (ubi->fm_size / ubi->leb_size) * 2 + ubi->fm_pool_rsv_cnt;
1517
INIT_WORK(&ubi->fm_work, update_fastmap_work_fn);
1618
}
1719
static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,

0 commit comments

Comments
 (0)