UBI文件系统分区开销计算

UBI文件系统:理解空间开销计算
本文介绍了UBI文件系统在使用中产生的空间开销,包括用于存储卷表、损耗均衡、原子LEB改变操作的PEB,以及处理坏PEB的预留空间。此外,还详细解析了根据不同类型的闪存计算开销的公式,并给出了一个NAND闪存的实例计算。

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 unitO 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

 

 

### UBI文件系统与Rootfs根文件系统的区别及用途 #### 定义与基本概念 在嵌入式Linux系统中,`rootfs` 是指根文件系统,它是操作系统启动后加载的第一个文件系统。它包含了运行Linux所需的核心文件和目录结构[^1]。而 `UBIFS`(User-space Block I/O File System)是一种专门设计用于闪存设备的文件系统,通常作为UBI(Universal Flash Storage Interface)的一部分来实现。 #### Rootfs的作用 `rootfs` 的主要作用是在系统引导过程中提供必要的基础环境。它的内容可以存储在多种介质上,比如RAM盘、NAND闪存或者通过网络挂载的NFS共享。对于小型嵌入式系统来说,`initramfs` 或者类似的内存中的临时文件系统可能被用来充当初始的 `rootfs`。 #### UBI/UBIFS的特点及其适用场景 - **UBI (Universal Boot Image)** 提供了一个抽象层,在物理上的NAND芯片之上创建逻辑卷管理功能。这使得它可以更好地处理坏块管理和磨损均衡等问题。 - **UBIFS 文件系统** 构建于UBI之上的一种日志型文件系统,专为MTD(Memory Technology Device)设备优化。相比传统的JFFS2或其他Flash专用文件系统UBIFS提供了更高的性能以及更少的空间开销[^2]。 当涉及到持久化数据存储需求较高的应用场合时,选择基于 Nand flash 并采用 ubi+ubifs 方案会更加合适;而对于那些只需要简单操作且不需要长期保存状态的应用,则可以直接利用 ramdisk 类型的 rootfs 来减少复杂度并提高效率。 #### 技术对比总结表 | UBI vs ROOTFS | 特性 | UBI / UBIFS | Rootfs | |---------------------|------------------------------------|----------------------------------| | 主要目标 | NAND Flash 存储 | 启动过程中的核心文件系统 | | 数据持久性 | 高 | 取决于底层支持 | | 性能 | 较优 | 中等 | | 使用案例 | 嵌入式设备固件更新 | 初始引导阶段 | ```python # 示例 Python 脚本展示如何检测当前使用的文件系统类型 import os def get_filesystem_type(path='/'): """获取指定路径所在分区文件系统类型""" result = os.popen(f'df --output=fstype {path}').read().strip().split('\n')[-1] return result if __name__ == "__main__": fs_type = get_filesystem_type('/') print(f"The current root filesystem type is: {fs_type}") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值