Using TRIM in Buildroot System in 1 Minute

Open Source Harmony Hardware Solution Leader
Tactile Intelligence

This article is applicable to Tactile Intelligence development boards that support the Buildroot system. This article takes the Purple Pi OH as an example. The Tactile Intelligence Purple Pi OH motherboard is a recommended Harmony development board from the Huawei Laval official community.

Using TRIM in Buildroot System in 1 Minute

Using TRIM in Buildroot System in 1 Minute

This motherboard is mainly aimed at students, geeks, and engineers, greatly lowering the entry barrier for open-source Harmony developers, and has the following advantages:

  • Supports open-source Harmony/Linux/Android 11/Kirin, compatible with Raspberry Pi;

  • Quad-core A55, up to 1.8G main frequency Mali G52-2EE GPU;

  • Supports OpenGL/CL/Vulkan/1T NPU/8MISP;

  • Supports TensorFlow/MXNet/PyTorch/Caffe;

  • Supports 1*Gigabit Ethernet, 3*USB2.0, 1*USB3.0, 3*UART, 2*SPI, 2*I2C, 28*GPIO, 1*MIPI DSI, 1*HDMI;

  • Supports OpenHarmony 3.2/4.0/4.1 versions, open SDK source code;

  • Active developer community, more experts online for technical support;

  • Ultra-small size, extreme cost performance, only 249 yuan;

01
Introduction to TRIM

In the field of computer storage, TRIM is a command used for Solid State Drives (SSD), which informs the SSD about which data blocks are no longer used by the operating system and can be erased. This typically occurs when files are deleted or the recycle bin is emptied; the operating system notifies the SSD that it no longer needs to retain these data blocks, allowing the SSD to safely erase these blocks during future garbage collection processes.

The main benefits of the TRIM command include:

Benefit 1

Performance Maintenance: TRIM helps maintain the performance of SSDs, as SSDs need to erase existing data before writing new data. If the operating system does not inform the SSD via TRIM which blocks are free, the SSD’s controller may mistakenly believe that some blocks still contain important data and avoid erasing them, leading to decreased write performance.

Benefit 2

Extended Lifespan: TRIM helps extend the lifespan of SSDs. Each storage cell in an SSD (or “cell”) has a limited number of erase/write cycles. By effectively reclaiming data blocks that are no longer in use, TRIM reduces unnecessary erase/write operations, thereby extending the lifespan of the SSD.

Benefit 3

Space Optimization: TRIM ensures that the SSD’s garbage collection process can work more efficiently, helping to free up space and providing more available storage cells for new data writing.

Benefit 4

Avoid Write Amplification: Without TRIM, SSDs may retain deleted data blocks until new data needs to be written, which can lead to the phenomenon of “write amplification,” where the actual amount of data written to the SSD is much larger than the original data amount. TRIM helps reduce this occurrence by marking data blocks as free in advance.

In modern operating systems, such as Windows 7 and later, macOS, Linux, etc., TRIM is usually enabled by default. Users can check whether TRIM is enabled and manually trigger TRIM operations using specific system commands or tools.

02
How to Use TRIM in Buildroot System

Using the TRIM command in a system built with Buildroot mainly involves two steps: ensuring that your file system supports TRIM operations and enabling TRIM functionality in the system.

Here are the general steps to use TRIM in a Buildroot system:

Using TRIM in Buildroot System in 1 Minute
2.1 Ensure File System Supports TRIM
Using TRIM in Buildroot System in 1 Minute

Most modern file systems (such as ext4, XFS, Btrfs, and F2FS) support TRIM.

In the Buildroot .config configuration file, ensure that the correct file system and TRIM support options are selected.

For example, if you are using the ext4 file system, ensure that Buildroot is configured with CONFIG_EXT4_FS to use this feature.

Using TRIM in Buildroot System in 1 Minute
2.2 Enable TRIM Functionality
Using TRIM in Buildroot System in 1 Minute

In a Buildroot built system, you can enable TRIM through the following methods:

2.2.2 Check Current Status

Fedora Linux implements a service that runs a systemd timer weekly. To check if it exists and its current status, run systemctl status.

$sudo systemctl status fstrim.timer

The result of executing this statement is shown in the following image:

Using TRIM in Buildroot System in 1 Minute

2.2.3 Enable the Service

Now, enable the service.

$sudo systemctl enable fstrim.timer

This will enable TRIM when the file system is mounted.

03
Build the System and Test

Finally, you can verify whether the timer has been enabled by listing all timers.

$ sudo systemctl list-timers --all
After executing the command, the following lines will be displayed, indicating that fstrim.timer exists. Note that this timer actually activates the fstrim.service service. This is where fstrim is actually called. The time-related fields show as n/a because the service is enabled and has not yet run.
Using TRIM in Buildroot System in 1 Minute

Please note that different versions of file systems and operating systems may have different details regarding TRIM support. Be sure to consult the documentation for the file system and operating system you are using for more detailed guidance. Additionally, TRIM operations for SSDs should be used with caution, as improper use may shorten the lifespan of the SSD.

04
Purchase Link

Purple Pi OH Purchase Link

https://m.tb.cn/h.g1qerYc?tk=ahOAWGe64ky

Using TRIM in Buildroot System in 1 Minute

Purple Pi OH has passed XTS compatibility certification

Using TRIM in Buildroot System in 1 Minute

END
WeChat ID|industio
Bilibili|Industio_Tactile Intelligence

Leave a Comment