linux 磁盤隊列深度nr_requests 和 queue_depth

  1. nr_requests 和 queue_depth
  2. 修改配置值
  3. nr_requests 和 queue_depth 區別
  4. iostat 的avgqu-sz
  5. lsscsi -l 的隊列大小
  6. iostat

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監控工具的輸出中。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章