Adjusting the Drive File Read-Ahead Parameter
Principles
The principle of file prefetching is to read a certain amount of adjacent data and cache them on the memory when reading data based on the locality principle. If the read-ahead data is subsequently used, the system performance will be improved. If the pre-read data is not subsequently used, the drive bandwidth will be wasted. In sequential drive read scenarios, increasing the prefetch value is especially effective.
Modification Method
The file prefetch parameter is defined in the read_ahead_kb file. In CentOS, the read_ahead_kb file is stored in the /sys/block/$DEVICE-NAME/queue/ directory. You can also run the following command to query its path:
1 | # find / -name read_ahead_kb
|
The default value of this parameter is 128 KB. You can run the echo command to change the value. The following command changes the prefetch value to 4096 KB, assuming CentOS is used:
1 | # echo 4096 > /sys/block/$DEVICE-NAME /queue/read_ahead_kb
|
The value is related to the read model and needs to be adjusted based on actual services.