• Zhihao Cheng's avatar
    ubi: fastmap: may_reserve_for_fm: Don't reserve PEB if fm_anchor exists · eada823e
    Zhihao Cheng authored
    This is the part 1 to fix cyclically reusing single fastmap data PEBs.
    
    After running fsstress on UBIFS for a while, UBI (16384 blocks, fastmap
    takes 2 blocks) has an erase block(PEB: 8031) with big erase counter
    greater than any other pebs:
    
    =========================================================
    from              to     count      min      avg      max
    ---------------------------------------------------------
    0        ..        9:        0        0        0        0
    10       ..       99:      532       84       92       99
    100      ..      999:    15787      100      147      229
    1000     ..     9999:       64     4699     4765     4826
    10000    ..    99999:        0        0        0        0
    100000   ..      inf:        1   272935   272935   272935
    ---------------------------------------------------------
    Total               :    16384       84      180   272935
    
    Not like fm_anchor, there is no candidate PEBs for fastmap data area,
    so old fastmap data pebs will be reused after all free pebs are filled
    into pool/wl_pool:
    ubi_update_fastmap
     for (i = 1; i < new_fm->used_blocks; i++)
      erase_block(ubi, old_fm->e[i]->pnum)
      new_fm->e[i] = old_fm->e[i]
    
    According to wear leveling algorithm, UBI selects one small erase
    counter PEB from ubi->used and one big erase counter PEB from wl_pool,
    the reused fastmap data PEB is not in these trees. UBI won't schedule
    this PEB for wl even it is in ubi->used because wl algorithm expects
    small erase counter for used PEB.
    
    Don't reserve PEB for fastmap in may_reserve_for_fm() if fm_anchor
    already exists. Otherwise, when UBI is running out of free PEBs,
    the only one free PEB (pnum < 64) will be skipped and fastmap data
    will be written on the same old PEB.
    
    Fixes: dbb7d2a8 ("UBI: Add fastmap core")
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=217787Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
    Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
    eada823e
wl.c 56.4 KB