linux 磁盘队列深度 nr_requests 和 queue_depth

发布于 2021-12-30  625 次阅读


原文地址

nr_requests 和 queue_depth

本文主要介绍 Linux 操作系统中 nr_requests 和 queue_depth 的参数意义和工作原理。以及结合 iostat 的 avgqu-sz 之间关系分析。

1.nr_requests 和 queue_depth

操作系统中 nr_requests 参数,可以提高系统的吞吐量,似乎越大越好,但是该请求队列的也不能过大,因为这样会消耗大量的内存空间。该值的调整需要综合多处因素,
比如: 文件系统、sheduler 类型、io 的特点。
命令: echo xxx > /sys/block//queue/nr_requests,nr_requests 的大小设置至少是 / sys/block//device/queue_depth 的两倍,所以,修改 nr_requtests 的时候要注意。

[root@node-1 ~]# cat /sys/block/sdj/queue/nr_requests 
256
[root@node-1 ~]# cat /sys/block/sdj/device/queue_depth 
64

2. 修改配置值

$ echo “512” > /sys/block/sda/queue/nr_requests     IO调度队列大小
$ echo “512” > /sys/block/sda/device/queue_depth    磁盘队列深度

3.nr_requests 和 queue_depth 区别

  • nr_requests:请求的 IO 调度队列大小
  • queue_depth:请求在磁盘设备上的队列深度
  • I/O 调度器中的最大 I/O 操作数是 nr_requests * 2。读和写是分开的。
  • 已经分配到底层设备的 I/O 操作是 queue_depth。
  • 一个磁盘设备的 I/O 操作的最大未完成限制为 (nr_requests * 2)+(queue_depth) 。对应 iostat 的 avgqu-sz。

英文解释

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-storage_and_file_systems-configuration_tools

nr_requests
Specifies the maximum number of read and write requests that can be queued at one time. 
The default value is 128, which means that 128 read requests and 128 write requests can be queued before the next process to request a read or write is put to sleep.

For latency-sensitive applications, lower the value of this parameter and limit the command queue depth on the storage so that write-back I/O cannot fill the device queue with write requests. 
When the device queue fills, other processes attempting to perform I/O operations are put to sleep until queue space becomes available. 
Requests are then allocated in a round-robin manner, which prevents one process from continuously consuming all spots in the queue.

The maximum number of I/O operations within the I/O scheduler is nr_requests*2. 
As stated, nr_requests is applied separately for reads and writes. 
Note that nr_requests only applies to the I/O operations within the I/O scheduler and not to I/O operations already dispatched to the underlying device. 

Therefore, the maximum outstanding limit of I/O operations against a device is (nr_requests*2)+(queue_depth) where queue_depth is /sys/block/sdN/device/queue_depth, sometimes also referred to as the LUN queue depth. 
You can see this total outstanding number of I/O operations in, for example, the output of iostat in the avgqu-sz column.

指定一次可以排队的读请求和写请求的最大数目。
默认值是128,这意味着128个读请求和128个写请求可以在请求读或写的下一个进程进入睡眠状态之前排队。

对于对延迟敏感的应用程序,可以降低该参数的值,并限制存储上的命令队列深度,以防止回写I/O用写请求填满设备队列。
当设备队列满时,其他试图执行I/O操作的进程将进入休眠状态,直到队列空间可用。
然后以循环的方式分配请求,这可以防止一个进程持续地消耗队列中的所有位置。

I/O调度器中的最大I/O操作数是nr_requests*2。
如前所述,对于读和写,分别应用nr_requests。
注意,nr_requests仅适用于I/O调度器中的I/O操作,而不适用已经分配到底层设备的I/O操作。

因此,对一个设备的I/O操作的最大未完成限制为(nr_requests*2)+(queue_depth),其中queue_depth为/sys/block/sdN/device/queue_depth,有时也称为LUN队列深度。
例如,您可以在avgqu-sz列中的iostat输出中看到这个未完成的I/O操作总数。

4.iostat 的 avgqu-sz

该值大小为:(nr_requests*2)+(queue_depth)

5.lsscsi -l 的队列大小

Lun queue depth 值来自 /sys/block/sdj/device/queue_depth

[root@node-1 ~]# echo "128" >/sys/block/sdj/device/queue_depth
[root@node-1 ~]# lsscsi -l | grep -A 1 sdj
[0:0:16:0]   disk    SEAGATE  ST1000NX0453     NS02  /dev/sdj 
  state=running queue_depth=128 scsi_level=7 type=0 device_blocked=0 timeout=90
[root@node-1 ~]# echo "256" >/sys/block/sdj/device/queue_depth 
[root@node-1 ~]# lsscsi -l | grep -A 1 sdj
[0:0:16:0]   disk    SEAGATE  ST1000NX0453     NS02  /dev/sdj 
  state=running queue_depth=256 scsi_level=7 type=0 device_blocked=0 timeout=90

6.iostat

The default value is 1 (enabled). 
Setting iostats to 0 disables the gathering of I/O statistics for the device, which removes a small amount of overhead with the I/O path. 
Setting iostats to 0 might slightly improve performance for very high performance devices, such as certain NVMe solid-state storage devices.
It is recommended to leave iostats enabled unless otherwise specified for the given storage model by the vendor.

If you disable iostats, the I/O statistics for the device are no longer present within the /proc/diskstats file. 
The content of /sys/diskstats is the source of I/O information for monitoring I/O tools, such as sar or iostats. 
Therefore, if you disable the iostats parameter for a device, the device is no longer present in the output of I/O monitoring tools.

缺省值为1(启用)。
将iostats设置为0将禁用收集设备的I/O统计信息,这将减少I/O路径的少量开销。
将iostats设置为0可能会略微提高非常高性能设备的性能,比如某些NVMe固态存储设备。
除非供应商为给定的存储模型特别指定,否则建议保持启用iostats。
如果禁用iostats,设备的I/O统计信息将不再存在于/proc/diskstats文件中。
/sys/diskstats的内容是用于监视I/O工具(如sar或iostats)的I/O信息的来源。
因此,如果对某个设备禁用iostats参数,该设备将不再出现在I/O监控工具的输出中。

或许明日太阳西下倦鸟已归时