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

Wang, Qiong (Q.) qwang34 at yfve.com.cn
Mon Mar 26 02:16:42 PDT 2018


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.

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?

Best Regards,
汪琼/Wang Qiong

软件与测试部/软件工程师Software Design&Test Dept./Software Engineer
Tel +86 25 8106 9232
E-mail: qwang34 at yfve.com.cn
延锋伟世通电子科技(南京)有限公司
Yanfeng Visteon Electronics Technology (Nanjing) Co., Ltd
江苏省南京市江宁区苏源大道19号国际企业总部园C1座7楼
Address: 7F, C1, Jiulonghu International Corporate Headquarters, No. 19 Suyuan Road, Jiangning Development Zone, Nanjing, China



More information about the linux-mtd mailing list