Linux operating system block device parameter tuning

       

Table of contents

1. Queue depth

2. Scheduling algorithm

3. Amount of pre-reading

4. I/O alignment


1. Queue depth

        The queue depth determines the maximum number of concurrent write I/Os to the block device. For Linux systems, the default value is 128. Generally, users are not recommended to modify this parameter. Users can use the cat command to query the current block device queue depth.

 linux-ob3a:~ # cat /sys/block/sdc/queue/nr_requests

128 

        When performing extreme performance tests on the system, this parameter can be appropriately increased in order to increase the pressure on the host to write I/O and the probability of I/O being merged in the queue. You can temporarily modify the queue depth of a block device through the following methods.

echo 256 > /sys/block/sdc/queue/nr_requests

https://download.huawei.com/mdl/image/download?uuid=298fc6778043430aac2b93a309236082

Temporarily modifying the block device queue depth can be used for performance tuning. When the application server is restarted, the block device queue depth will be restored to the default value.

2. Scheduling algorithm

        The Linux operating system 2.6 kernel supports four block device scheduling algorithms: noop, anticipatory, deadline and cfq. The default scheduling algorithm is cfq. Users can use the cat command to query the current block device scheduling algorithm.

 linux-ob3a:~ # cat /sys/block/sdc/queue/scheduler

noop deadline [cfq]  

        Improper configuration of the scheduling algorithm will affect system performance, such as I/O concurrency, etc. You can temporarily modify the scheduling algorithm of block devices through the following methods.

echo noop > /sys/block/sdc/queue/scheduler

https://download.huawei.com/mdl/image/download?uuid=298fc6778043430aac2b93a309236082

Temporarily modifying the scheduling algorithm can be used for performance tuning. When the application server is restarted, the scheduling algorithm will be restored to the default value.

3. Amount of pre-reading

        Linux 's read-ahead function is similar to the array's read-ahead algorithm. It is only effective for sequential reads and will identify the sequential stream and read data of "read_ahead_kb" (unit: sector) length in advance. For example, the default read-ahead size of the SUSE 11 operating system is 512 sectors, which is 256KB. Users can use the cat command to query the current block device read-ahead amount.

 linux-ob3a:~ # cat /sys/block/sdc/queue/read_ahead_kb

512 

When your business needs to read a large number of large files, you can improve performance by appropriately increasing this parameter. You can modify the read-ahead amount of block devices through the following methods.

echo 1024 > /sys/block/sdc/queue/read_ahead_kb

4. I/O alignment

        When using MBR format to create a partition in an operating system prior to Linux or Windows Server 2003, the first 63 sectors of the disk will be reserved for the master boot record and partition table. The first partition starts from sector 64 by default. . This causes the host's data blocks (database or file system) to be misaligned with the storage data blocks, resulting in reduced I/O processing efficiency.

There are two ways to solve I/O misalignment in the Linux operating system:

  • Method 1: Change the starting position of the partition.

        When using MBR format to create a partition in a Linux system, it is recommended to enter the expert mode of the fdisk command and set the starting position of the first partition to the starting position of the second extent of the LUN (the default extent size is 4MB). The following quick command is used to create a partition in MBR format on /dev/sdb, using all the space of /dev/sdb, and setting the start sector to 8192, which is 4MB.

printf "n\np\n1\n\n\nx\nb\n1\n 8192\nw\n" | fdisk /dev/sdb

  • Method 2: Directly use GPT format partition.

        The following quick command is used to create 1 partition on /dev/sdb using GPT format, using the entire space of /dev/sdb, with the start sector set to 8192, which is 4MB.

parted -s -- /dev/sdb "mklabel gpt" "unit s" "mkpart primary 8192 -1" "print"

When creating an MBR partition in systems prior to Windows Server 2003, it is recommended to use the diskpart command to set partition alignment.

diskpart> select disk 1

diskpart> create partition primary align=4096

Guess you like

Origin blog.csdn.net/u013253075/article/details/132105249