In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to enable SSD TRIM function under Linux". In daily operation, I believe many people have doubts about how to enable SSD TRIM function under Linux. Xiaobian consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the doubts of "how to enable SSD TRIM function under Linux"! Next, please follow the small series to learn together!
I knew SSD had TRIM function before, but I didn't delve into it until my colleague asked recently. At present, the information is as follows. If there is any error, please correct it.
SSD has the concept of page and block when accessing data in flash memory unit. SSD is divided into many blocks, and blocks are divided into many pages.
SSD Read and Write are page based, while Erase is block based. However, SSD Write can only be written to empty pages, and cannot be overwritten directly like traditional mechanical disks. When modifying data, the operation flow is read-modify-write: read the contents of the original page, modify it in cache, write the new empty page, modify the logical address to the new page, and the original page is marked as 'stale' and is not cleared.
Linux file systems are only marked as unused for delete operations, and are not actually cleared, and underlying storage such as SSD and traditional mechanical disks do not know which data blocks are available and which data blocks can be erased. Therefore, for non-empty pages, SSD must perform an Erase before writing, then the writing process is read-erase-modify-write: Read the contents of the entire block to cache, and write the entire block from SSD to cache block, and write the updated block in cache to flash media. This phenomenon is called write amplification.
To address this issue, SSDs began supporting TRIM, which enables the operating system to notify SSDs which pages no longer contain valid data. The TRIM feature helps extend SSD long-term performance and longevity. To enable TRIM, verify that the SSD, operating system, and file system support TRIM.
According to Red Hat's SOLID-STATE DISK DEPLOYMENT GUIDELINES, SSD performance begins to degrade as the blocks used approach disk capacity, and the degree of performance impact varies from vendor to vendor, but all devices experience some performance degradation. To address performance degradation, the Linux operating system supports sending discard requests to inform memory which blocks are no longer in use.
Check if SSD supports TRIM
SSD support TRIM can be judged by the information under/sys/block, discard_granularity is not 0 means support.
# cat /sys/block/sda/queue/discard_granularity0# cat /sys/block/nvme0n1/queue/discard_granularity512
You can also use lsblk to detect directly, DISC-GRAN (discard granularity) and DISC-MAX (discard max bytes) columns are not 0 to indicate that the SSD supports TRIM function.
# lsblk --discardNAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZEROsda 0 0B 0B 0├─sda1 0 0B 0B 0├─sda2 0 0B 0B 0└─sda3 0 0B 0B 0sr0 0 0B 0B 0nvme0n1 512 512B 2T 1nvme1n1 512 512B 2T 1
There are also articles on hdparm to detect, but I did not return this information in the Intel P4500 SSD test.
# hdparm -I /dev/sda | grep TRIM* Data Set Management TRIM supported (limit 1 block)Continuous TRIM
Red Hat Enterprise Linux 6.3 and earlier, only ext4 file systems fully support discard. Starting with Red Hat Enterprise Linux 6.4, ext4 and XFS have full support for discard.
For ext4 file systems, TRIM can be enabled by adding the discard parameter to/etc/fstab. Make sure your SSD supports TRIM before adding it.
/dev/sdb1 /data1 ext4 defaults,noatime,discard 0 0
The following is an introduction to the mount parameters in ext4 documentation:
discard
nodiscard(*)
Controls whether ext4 should issue discard/TRIM. commands to the underlying block device when blocks are freed.
Periodic TRIM
util-linux comes with the fstrim tool (Discard unused blocks on a mounted filesystem.) Usually use-a option (-a, --all trim all mounted file systems that are supported) more often, you can automatically detect whether the hard disk supports trim function, and in the mounted file system to execute trim.
Interested students can see fstrim source code specific implementation.
Here are my tests on CentOS 7.4./dev/nvme0n1 and/dev/nvme1n1 are Intel P4500 NVMe SSDs with ext4 file system.
# fstrim -a -v/data2: 3.4 TiB (3710506934272 bytes) trimmed/data1: 3.2 TiB (3546946879488 bytes) trimmed # df -h file system Capacity Used Available Used % Mount Point/dev/sda2 267G 7.0G 246G 3% /devtmpfs 63G 0 63G 0% /devtmpfs 63G 0 63G 0% /dev/shmtmpfs 63G 1.1G 62G 2% /runtmpfs 63G 0 63G 0% /sys/fs/cgroup/dev/sda1 190M 147M 29M 84% /boot/dev/nvme0n1 3.6T 365G 3.1T 11% /data1/dev/nvme1n1 3.6T 212G 3.2T 7% /data2tmpfs 13G 0 13G 0% /run/user/1000
During the fstrim process, the disk IO utilization rate is still relatively high, and the two disks add up to 2 minutes.
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %utilnvme0n1 0.00 319.00 592.00 716.00 2368.00 76391672.00 116810.46 1.10 0.84 0.20 1.37 0.74 97.40nvme1n1 0.00 0.00 0.00 6.00 0.00 24.00 8.00 0.00 0.00 0.00 0.00 0.00 0.00sda 0.00 9.00 0.00 2.00 0.00 44.00 44.00 0.00 0.00 0.00 0.00 0.00 0.00
Linux distributions that use systemd generally come with fstrim.timer and fstrim.service, and fstrim is executed once a week when enabled. The following is the service file in CentOS 7.4.
# systemctl enable fstrim.timer# systemctl start fstrim.timer# cat /usr/lib/systemd/system/fstrim.timer[Unit]Description=Discard unused blocks once a weekDocumentation=man:fstrim[Timer]OnCalendar=weeklyAccuracySec=1hPersistent=true[Install]WantedBy=multi-user.target# cat /usr/lib/systemd/system/fstrim.service[Unit]Description=Discard unused blocks[Service]Type= oneshotStart =/usr/sbin/fstrim -a Reference
Arch Wiki: Solid State Drive
How to properly activate TRIM for your SSD on Linux: fstrim, lvm and dm-crypt
How To Configure Periodic TRIM for SSD Storage on Linux Servers
Optimize performance of persistent disks and local SSDs
Intel engineers learned that Intel Optane SSD is different from NAND, using write-in-place technology, no garbage collection, no trim. Intel P4500 and P4600 series NVMe SSDs are NAND products, and active trim can optimize performance and extend life.
At this point, the study of "how to enable SSD TRIM function under Linux" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.