mirror of
https://github.com/torvalds/linux.git
synced 2024-11-26 22:21:42 +00:00
90e0be5614
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: dbb7d2a88d
("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>
33 lines
1.4 KiB
C
33 lines
1.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef UBI_WL_H
|
|
#define UBI_WL_H
|
|
#ifdef CONFIG_MTD_UBI_FASTMAP
|
|
static void update_fastmap_work_fn(struct work_struct *wrk);
|
|
static struct ubi_wl_entry *find_anchor_wl_entry(struct rb_root *root);
|
|
static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
|
|
static struct ubi_wl_entry *next_peb_for_wl(struct ubi_device *ubi);
|
|
static bool need_wear_leveling(struct ubi_device *ubi);
|
|
static void ubi_fastmap_close(struct ubi_device *ubi);
|
|
static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count)
|
|
{
|
|
if (ubi->fm_disabled)
|
|
ubi->fm_pool_rsv_cnt = 0;
|
|
/* Reserve enough LEBs to store two fastmaps and to fill pools. */
|
|
*count += (ubi->fm_size / ubi->leb_size) * 2 + ubi->fm_pool_rsv_cnt;
|
|
INIT_WORK(&ubi->fm_work, update_fastmap_work_fn);
|
|
}
|
|
static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
|
|
struct ubi_wl_entry *e,
|
|
struct rb_root *root);
|
|
#else /* !CONFIG_MTD_UBI_FASTMAP */
|
|
static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi);
|
|
static inline void ubi_fastmap_close(struct ubi_device *ubi) { }
|
|
static inline void ubi_fastmap_init(struct ubi_device *ubi, int *count) { }
|
|
static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi,
|
|
struct ubi_wl_entry *e,
|
|
struct rb_root *root) {
|
|
return e;
|
|
}
|
|
#endif /* CONFIG_MTD_UBI_FASTMAP */
|
|
#endif /* UBI_WL_H */
|