High performance SD card tuning using the EXT4 file system
While trying to dual-record from two 1080P@30fps input channels at the same time, we faced the problem of saving all these huge amount of incoming data to the filesystem that eventually drowned the system. The setup was an ext3 filesystem in a Class 10 SD card, but that was not enough and just some seconds after starting writing the files the system would stall.
Solution
The solution involves using an ext4 filesystem instead of ext3, and then optimizing this filesystem for a better write performance. Additionally, depending on how intense your gstreamer pipeline is, you may be required to tune the kernel's virtual memory (vm) subsystem, to avoid peaks on the CPU load when the pdflush daemon wakes up to write, minimizing any chance to stall the system.
1. Enable ext4 support in the kernel
Kernel Configuration:
File Systems -> <*> The Extended 4 (ext4) filesystem [*] Ext4 extended attributes [*] Ext4 POSIX Access Control Lists [*] Ext4 Security Labels Enable the block layer [*] Support for large (2TB+) block devices and files
2. Prepare your SD card with an optimized ext4 filesystem
2.1 Create the ext4 partition
There could be many tools to prepare an ext4 partition in your SD card. Probably, the simplest way is to use gparted.
sudo gparted
See Figure 1 for an example setup of a new ext4 partition in an 8GB SD card using gparted. In this example, the SD card was assigned the device node /dev/sdb, and the new partition will be mapped to /dev/sdb1. This could be different in your computer.
Note: Please be careful, you don't want to format the wrong device or lose information.
2.2 Optimize the ext4 partition
The optimization consists on selecting the data mode for our fileystem as data=writeback. Over the three existing possible data modes (the other two being data=ordered and data=journal), writeback is the one that gets the best write performance out of ext4 by disabling journaling. For more information, read the "Data Mode" section from the Ext4 Filesystem kernel documentation.
sudo tune2fs -o journal_data_writeback /dev/sdb1 sudo tune2fs -O ^has_journal /dev/sdb1 sudo e2fsck -f /dev/sdb1
You can check your filesystem setup using:
dumpe2fs /dev/sdb1 | less
3. Mount the ext4 partition in your system
Mount the ext4 partition specifying the following flags for optimization:
- noatime,nodiratime - avoid writing access times
- data=writeback - tell mount we are mounting a filesystem with no journaling
To mount the ext4 fileystem at /mnt/sd in your board:
mkdir -p /mnt/sd mount -t ext4 -O noatime,nodirame,data=writeback /dev/mmcblk0p1 /mnt/sd
References
http://blogofterje.wordpress.com/2012/01/14/optimizing-fs-on-sd-card/
https://www.kernel.org/doc/Documentation/filesystems/ext4.txt