The nr_requests is a parameter for block device, it controls maximum requests may be allocated in the block layer for read or write requests, the default value is 128. Occasionally, it may be suggested to adjust the value, generally speaking:
- Increasing the value will improve the I/O throughput, but will also increase the memory usage.
- Decreasing the value will benefit the real-time applications that are sensitive to latency, but it also decreases the I/O throughput.
This post elaborates on how to set the parameter permanently across system reboots.
1. Create a new udev rule.
For example, create the file /etc/udev/rules.d/71-nr-requests.rules, with the following content:
SUBSYSTEM!="block", GOTO="end_rule" ENV{DEVTYPE}=="partition", GOTO="end_rule" ACTION!="add|change", GOTO="end_rule" KERNEL=="sd*", ATTR{queue/nr_requests}="256" LABEL="end_rule"
The rules above will set nr_requests to 256 for all sd* devices, if you need to blacklist some (e.g. sda, and sdb), use the rules like:
SUBSYSTEM!="block", GOTO="end_rule" ENV{DEVTYPE}=="partition", GOTO="end_rule" ACTION!="add|change", GOTO="end_rule" KERNEL=="sda|sdb", GOTO="end_rule" KERNEL=="sd*", ATTR{queue/nr_requests}="256" LABEL="end_rule"
2. Apply the rule
Before applying the rule verify the value of “nr_requests” parameter:
$ grep "" /sys/block/sd*/queue/nr_requests /sys/block/sda/queue/nr_requests:128 /sys/block/sdb/queue/nr_requests:128
Apply the rule on CentOS/RHEL 6 or above:
# udevadm trigger
Use this in CentOS/RHEL 5
# udevtrigger
After applying the rule verify the “nr_requests” parameter value:
$ grep "" /sys/block/sd*/queue/nr_requests /sys/block/sda/queue/nr_requests:256 /sys/block/sdb/queue/nr_requests:256