Flash 比傳統的 HardDisk 會遇上以下幾個問題,
- block allocation (NAND flash chips pages of 2-4KB, multi-channel access 後: 8-16KB)
- garbage collection(Erasing blocks) (idle 時要自動去清空可用的 block, 一般成 2 MB 大 !!, allocation group 後, 4 MB)
- Wear leveling [寫入次數 Flash10^3 (for MLC NAND), 10^5 (NOR, SLC NAND)]
- Bad eraseblocks 管理
不過它們全由 controller 解決
Memory Technology Devices
MTD 是 Linux 系統用來 Flash Controller 的軟件層來
把 HardDisk 看成 mtd
modprobe block2mtd
echo "/dev/loop0" > /sys/module/block2mtd/parameters/block2mtd
cat /proc/mtd
OR
modprobe block2mtd block2mtd=/dev/sdb1
軟件包:
mtd-utils
/usr/sbin/mkfs.jffs2
/usr/sbin/mtdinfo
logfs-tools (/sbin/mklogfs, man 8 mklogfs)
(replace JFFS2 for most uses)
-c, --compress
LogFS
特點:
-
stores the inode tree on the drive; JFFS2 does not.
(which requires it to scan the entire drive at mount and cache the entire tree in RAM) -
packing multiple file-system blocks into a single flash-memory block.
(A "sum" entry at the end of the flash-memory block records what data is stored in it.)
Format 它:
mkfs.logfs /dev/sdb1
Will create filesystem with the following details: hex: decimal: fssize= 1e940000 513015808 segsize= 40000 262144 blocksize= 1000 4096 writesize= 1 1 Do you wish to continue (yes/no)
奇怪的是在 Ubuntu 12.04 是 mount 不到 logfs 的 ....
grep -i logfs /boot/config-3.* /boot/config-3.2.0-33-generic:# CONFIG_LOGFS is not set /boot/config-3.2.0-34-generic:# CONFIG_LOGFS is not set /boot/config-3.2.0-35-generic:# CONFIG_LOGFS is not set
注意
USB-Sticks, SD-Card 它們是 block devices 來 !! 原因是它有 FTL (Flash Translation Layer) 在硬件裡面
所以對它們而言, 用 ext2 及 "noatime,relatime" mount option 是最優化的.
- atime: 會記錄最後讀取時間
- noatime: 不記錄最後讀取時間
- relatime: 當最後讀取時間比最後更改時間早時才更新