UBI文件系统分区开销计算

UBI的空间开销计算公式

Flash空间开销(overhead)
UBI使用了一部分的flash空间用于它自身功能的实现,因此UBI用户所获得的空间会比实际的flash空间要少。也就是说:

Ø 两个PEB用来存储卷表

Ø 一个PEB被保留,用以损耗均衡

Ø 一个PEB被保留,用以原子LEB改变操作

Ø 一定数量的PEB被保留,用以处理坏PEB;这个是用于NANDflash而不是NOR flash;保留的数量是可配置的,默认情况是每1024块保留20块。

Ø 在每个PEB的开头存储EC头和VID头;这个所占用的字节数因flash类型的不同而不同,接下来将会进行解释。

符号解释:

Ø W--flash芯片上的PEB总数(注意:是整块芯片,而不是MTD分区)

Ø P—MTD分区上PEB总数

Ø SP--PEB大小

Ø SL –LEB大小

Ø BB –MTD分区坏块数

Ø BR –为处理坏PEB而预留的PEB数。对于NANDflash默认等于20*W/1024,NOR flash为0

Ø B—MAX

Ø O—存储EC和VID头的开销,单位为字节。例如O = SP – SL

这样UBI的开销为(B +4) * SP + O * (P – B – 4)。这就是用户所不能获得的总字节数

 

具体信息可参考官方文档

=======================================================================

http://www.linux-mtd.infradead.org/doc/ubi.html#L_overhead

Flash space overhead

UBI uses some amount of flash space for its own purposes, thus reducing the amount of flash space available for UBI users. Namely:

  • 2 PEBs are used to store the volume table;
  • 1 PEB is reserved for wear-leveling purposes;
  • 1 PEB is reserved for the atomic LEB change operation;
  • some amount of PEBs is reserved for bad PEB handling; this is applicable for NAND flash, but not for NOR flash; the amount of reserved PEBs is configurable and is equal to 20 blocks per 1024 blocks by default;
  • UBI stores the EC and VID headers at the beginning of each PEB; the amount of bytes used for these purposes depends on the flash type and is explained below.

Let's introduce symbols:

  • W - total number of physical eraseblocks on the flash chip (NB: the entire chip, not the MTD partition);
  • P - total number of physical eraseblocks on the MTD partition);
  • SP - physical eraseblock size;
  • SL - logical eraseblock size;
  • BB - number of bad blocks on the MTD partition;
  • BR - number of PEBs reserved for bad PEB handling. it is 20 * W/1024 for NAND by default, and 0 for NOR and other flash types which do not have bad PEBs;
  • B - MAX(BR,BB);
  • O - the overhead related to storing EC and VID headers in bytes, i.e. O = SP - SL.

The UBI overhead is (B + 4) * SP + O * (P - B - 4) i.e., this amount of bytes will not be accessible for users. O is different for different flashes:

  • in case of NOR flash which has 1 byte minimum input/output unit, O is 128 bytes;
  • in case of NAND flash which does not have sub-pages (e.g., MLC NAND), O is 2 NAND pages, i.e. 4KiB in case of 2KiB NAND page and 1KiB in case of 512 bytes NAND page;
  • in case of NAND flash which has sub-pages, UBI optimizes its on-flash layout and puts the EC and VID headers at the same NAND page, but different sub-pages; in this case O is only one NAND page;
  • for other flashes the overhead should be 2 min. I/O units if the min. I/O unit size is greater or equivalent to 64 bytes, and 2 times 64 bytes aligned to the min. I/O unit size if the min. I/O unit size is less than 64 bytes.

N.B.: the formula above counts bad blocks as a UBI overhead. The real UBI overhead is: (B - BB + 4) * SP + O * (P - B - 4).

=======================================================================

实例:

Nandflash 总大小128M
1page=2048(byte)
1block=64page=128K

PEB=1block=128K=131072(byte)
LEB=(64-2)*2048=126976(byte)

以分区8M为例
SP=131072 
SL=126976 
O=4096 
P=64 
W=1024 
BB=20 
BR=20 
B=20 
overhead=3309568 
flash_size=134217728 
partition_size=8388608

(B +4) * SP + O * (P – B – 4)
=(20+4)*131072 + 4096*(64-20-4)
= 3145728 + 163840
= 3309568
= 3M + 163840

 

 

你可能感兴趣的:(Linux)