在阅读了一些关于 Linux VFS 页面缓存和可调参数的文章后,dirty_ratio
我的印象是页面缓存将作为读写缓存层运行。
但是使用下面的简单测试可以很好地提高位于页面缓存中但似乎不适用于写入的文件的读取速度。
例如
清除缓存并写入文件。
# swapoff -a
# echo 3 > /proc/sys/vm/drop_caches
# dd if=/dev/zero of=/home/flo/test bs=1M count=30
30+0 records in
30+0 records out
31457280 bytes (31 MB) copied, 0.182474 s, 172 MB/s
Run Code Online (Sandbox Code Playgroud)
检查文件实际上是否在页面缓存中
# vmtouch /home/flo/test
Files: 1
Directories: 0
Resident Pages: 7680/7680 30M/30M 100%
Elapsed: 0.000673 seconds
Run Code Online (Sandbox Code Playgroud)
从文件中读取以确认实际上来自缓存。
# dd if=/home/flo/test of=/dev/null bs=1M count=30
30+0 records in
30+0 records out
31457280 bytes (31 MB) copied, 0.00824169 s, 3.8 GB/s
Run Code Online (Sandbox Code Playgroud)
删除缓存并再次读取以证明速度差异。
# echo 3 …
Run Code Online (Sandbox Code Playgroud)