How to use Trim/discard to mount rbd block devices
Today, I will talk to you about how to use Trim/discard to mount rbd block devices. Many people may not know much about it. In order to let you know more, Xiaobian summarizes the following contents for you. I hope you can gain something according to this article.
1. If you do not use the discard option to mount rbd block devices, you will have the following problems
$ rbd create rbd/myrbd --size=20480$ mkfs.xfs /dev/rbd0$ rbd diff rbd/myrbd | awk '{ SUM += $2 } END { print SUM/1024/1024 " MB" }'14.4062 MB$ mount /dev/rbd0 /mnt/myrbd$ dd if=/dev/zero of=/mnt/myrbd/testfile bs=1M count=1024$ rbd diff rbd/myrbd | awk '{ SUM += $2 } END { print SUM/1024/1024 " MB" }'1038.41 MB$ rm /mnt/myrbd/testfile$ rbd diff rbd/myrbd | awk '{ SUM += $2 } END { print SUM/1024/1024 " MB" }'1038.41 MB
You will notice that the rbd pool is not getting smaller. I think I did a similar test before, I need to restart ceph or system to reflect the change, I can't remember clearly.
2. Mount rbd block devices with discard option
mount -o discard /dev/rbd0 /mnt/myrbd Repeat the above operation, and then perform the following operations: $ fstrim /mnt/myrbd$ rbd diff rbd/myrbd| awk '{ SUM += $2 } END { print SUM/1024/1024 " MB" }'10.6406 MB
That's normal again.
The performance tests for the two different mount modes are as follows:
1. Discard option not used
$ mount /dev/rbd0 /mnt/rbd0$ mkdir testdir; cd testdir$ dd if=/dev/zero of=mainfile bs=1M count=200$ split -b 4048 -a 7 mainfile; sync # 4k file / ~51k files$ cd ..$ time rm -rf testdir; time sync[root@mon0 nfs]# time rm -rf testdir/; time syncreal 0m21.866suser 0m0.155ssys 0m5.466sreal 0m0.897suser 0m0.001ssys 0m0.011s
2. Use discard option
Give only time [root@mon0 nfs]# time rm -rf testdir; time syncreal 0m8.791suser 0m0.100ssys 0m2.858sreal 0m2.367suser 0m0.001ssys 0m0.001s
There is a significant improvement in performance. The author's words are:
In cases where file systems are heavily used, it may be advantageous to use fstrim for many small files, such as once a day.
After reading the above, do you have any further understanding of how to use Trim/discard to mount rbd block devices? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.