Is it really reasonable to reserve a percentage of the total nand flash size for bad block handling for UBI?

Richard Weinberger richard.weinberger at gmail.com
Mon Mar 26 02:35:38 PDT 2018


Wang, Qiong (Q.) ,

On Mon, Mar 26, 2018 at 11:16 AM, Wang, Qiong (Q.) <qwang34 at yfve.com.cn> wrote:
> Hello,
>
> I’m creating a 16MiB UBIFS partition out of a 512MiB nand flash.After it is successfully mounted I discovered that 80 PEBs are reserved for the bad block handling. Since the PEB size is 128KiB for my nand flash,that is totally 10MiB, taking more than half size of my partition size.

This is the problem, there is no such thing as a "UBIFS partition.
UBI expects that you use the vast majority of the MTD for UBI such
that the wear-leveling domain is as large as possible.
If you want multiple UBIFS instances, create one UBI with multiples UBI volumes.

> After checking the ubi source code I discovered that is because ubi uses the total nand flash size to multiply the max bad PEB percentage to get the reserved bad block. I listed the source code below:
>
> drivers/mtd/ubi/build.c
>
> static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024)
> {
>          int limit, device_pebs;
>          uint64_t device_size;
>
>          if (!max_beb_per1024)
>                   return 0;
>
>          /*
>          * Here we are using size of the entire flash chip and
>          * not just the MTD partition size because the maximum
>          * number of bad eraseblocks is a percentage of the
>          * whole device and bad eraseblocks are not fairly
>          * distributed over the flash chip. So the worst case
>          * is that all the bad eraseblocks of the chip are in
>          * the MTD partition we are attaching (ubi->mtd).
>          */
>          device_size = mtd_get_device_size(ubi->mtd);
>          device_pebs = mtd_div_by_eb(device_size, ubi->mtd);
>          limit = mult_frac(device_pebs, max_beb_per1024, 1024);
>
>          /* Round it up */
>          if (mult_frac(limit, 1024, max_beb_per1024) < device_pebs)
>                   limit += 1;
>
>          return limit;
> }
>
> The comment explained that the worst case is that all the bad eraseblocks of the chip are in the MTD partition we are attaching but I do think it’s a rather rare situation. I wonder is it really necessary to reserve so many PEBs for bad block handling for such small partition? What if I need a small ubifs partition without so many PEBs reserved for bad block handling?

See above.

HTH

-- 
Thanks,
//richard



More information about the linux-mtd mailing list