Configure the context readahead feature of file systems to improve file access performance

更新时间:
复制 MD 格式

Linux uses the readahead technique to pre-fetch data into the page cache, speeding up file access in buffer I/O mode. The context readahead algorithm extends this by detecting interleaved sequential streams. In workloads with heavy random access, context readahead often misreads access patterns and prefetches more pages than needed, which degrades performance. Alibaba Cloud Linux 2 and 3 expose the vm.enable_context_readahead parameter so you can tune this behavior to match your workload.

Supported operating systems

The vm.enable_context_readahead parameter is supported on:

  • Alibaba Cloud Linux 2 with kernel version 4.19.91-18 or later

  • Alibaba Cloud Linux 3

Check the current status

Run either of the following commands. The output is 1 (enabled) or 0 (disabled).

cat /proc/sys/vm/enable_context_readahead
sysctl -n vm.enable_context_readahead

Configure context readahead

Use the /proc/sys/vm/enable_context_readahead parameter file or the sysctl interface to enable or disable context readahead.

Disable context readahead (recommended for random access workloads):

# Using the parameter file
sudo sh -c 'echo 0 > /proc/sys/vm/enable_context_readahead'

# Using sysctl
sudo sysctl -w vm.enable_context_readahead=0

Enable context readahead (default state):

# Using the parameter file
sudo sh -c 'echo 1 > /proc/sys/vm/enable_context_readahead'

# Using sysctl
sudo sysctl -w vm.enable_context_readahead=1