In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces what Linux I/O scheduler is, the article is very detailed, has a certain reference value, interested friends must read it!
The Linux I/O scheduler is a component of the Linux kernel that users can tune to optimize system performance.
Introduction to Linux I/O System
The Linux I/O Scheduler is a component of the Linux I/O architecture that sits between the generic block layer and block device drivers. As shown in Figure 1.
Figure 1. Linux I/O scheduler sits between the generic block layer and block device drivers
When a Linux kernel component wants to read or write some data, the kernel does not execute the request as soon as it is issued, but delays its execution. When a new block of data is transmitted, the kernel needs to check if it can pass. The Linux IO scheduler is between the generic block layer and the block device driver, so it receives requests from the generic block layer, tries to merge requests, and finds the most appropriate request to send to the block device driver. The block device driver then calls a function in response to the request.
Linux overall I/O architecture can be divided into seven layers, they are:
1. VFS Virtual File System: The kernel has to deal with a variety of file systems. The kernel abstracts this VFS, which is specially used to adapt to various file systems and provide a unified operating interface.
2. Disk cache: Disk cache is a software mechanism that keeps some data on disk in RAM, which allows faster response times for accessing that data. There are three types of disk cache in Linux: Dentry cache, Page cache, Buffer cache.
3. Mapping Layer: The kernel reads data from the block device, so the kernel must determine where the data is located on the physical device, which is done by the Mapping Layer.
4. Generic Block Layer: Since most I/O operations deal with block devices, Linux provides an abstraction layer for block device operations similar to the vfs layer. The lower layer interfaces with block devices with different attributes, and provides a unified Block IO request standard on the upper layer.
5. I/O scheduling layer: Most block devices are disk devices, so it is necessary to set up different schedulers according to the characteristics of such devices and application characteristics.
6. Block device driver: Block device driver provides advanced device operation interface.
7. Physical hard disk: This layer is the physical device.
5 Types of Linux I/O Scheduler
Linux has supported I/O schedulers since kernel 2.4, and so far there are five types: Linux 2.4 Linux Elevator, Linux 2.6 Deadline, Anticipatory, CFQ, Noop, where Anticipatory has been removed since Linux 2.6.33. Most Linux distributions currently use Deadline, CFQ, and Noop I/O schedulers. Here is a brief introduction in turn:
1 Linus Elevator
It was the first I/O scheduler in kernel 2.4. Its main role is to maintain a query request for each device, and when the kernel receives a new request, merge it if it can. If they cannot merge, they try sorting. If it cannot be merged and there is no suitable place to insert, it is placed at the end of the request queue.
2 Anticipatory
Anticipatory means "expected, expected". As the name implies, when an I/O occurs, if another process requests an I/O operation, it will generate a default 6 millisecond guess time to guess what the next process requests I/O. This I/O scheduler optimizes service time for read operations, making short waits while providing an I/O so that the process can commit to another I/O. The Anticipatory algorithm was removed from Linux version 2.6.33 because CFQ can be configured to achieve the Anticipatory effect.
3 DeadLine
Deadline is an improvement on Linus Elevator, which prevents some requests from being processed for too long. It is also possible to distinguish between read operations and write operations. DEADLINE additionally provides FIFO queues for read I/O and write I/O, respectively. Deadline workflow is shown in Figure 2.
Figure 2 Deadline workflow
4 CFQ
CFQ full name Completely Fair Scheduler, Chinese name completely fair scheduler, it is now the default scheduler of many Linux distributions, CFQ is the kernel default choice of I/O scheduler. It places synchronous requests submitted by processes into multiple process queues and then allocates time slices to each queue to access disk. CFQ is the best choice for general purpose servers, distributing access to I/O bandwidth evenly. CFQ creates a separate queue for each process and thread to manage the requests generated by that process, so that each process can be well allocated to I/O bandwidth. The I/O scheduler executes four requests per process at a time. The algorithm is characterized by sorting I/O requests by address rather than responding in first-come, first-served order. Simply put, all synchronization processes are allocated time slices before queuing for disk access. The CFQ workflow is shown in Figure 3.
Figure 3 CFQ workflow
5 NOOP
NOOP full name No Operation, Chinese name elevator scheduler, this algorithm realizes the simplest FIFO queue, all I/O requests roughly according to the order of first come, first served operation. NOOP implements a simple FIFO queue that organizes I/O requests like an elevator's workhorse. It is the simplest I/O scheduler in the Linux kernel based on the concept of first-in, first-out (FIFO) queues. This scheduler is best suited for solid state drives.
I/O scheduler selection
At present, mainstream Linux distributions use three I/O schedulers: DeadLine, CFQ and NOOP. Generally speaking, Deadline is suitable for most environments, especially file servers with a large number of writes. In principle, DeadLine is a scheduling algorithm that takes improving the throughput of mechanical hard disks as the starting point. It tries to ensure that I/O requests are scheduled when they reach the deadline. It is very suitable for businesses with single services and heavy I/O pressure, such as Web servers and database applications. CFQ allocates equal bandwidth to all processes, suitable for multi-user systems with a large number of processes. CFQ is a relatively general scheduling algorithm. It is a scheduling algorithm that takes processes as the starting point to ensure fairness as much as possible. Allocate equal bandwidth to all processes, suitable for desktop multitasking and multimedia applications. NOOP is the best choice for flash devices and embedded systems. NOOP is the best for SSDs, DeadLine is second, and CFQ is the least efficient.
View I/O Scheduler for Linux Systems
Viewing the I/O scheduler of a Linux system is generally divided into two parts, one is to view the I/O scheduler used by the Linux system as a whole, and the other is to view the I/O scheduler used by a disk.
To view the currently supported I/O schedulers, use the following command:
# dmesg | grep -i scheduler [ 1.508820] io scheduler noop registered [ 1.508827] io scheduler deadline registered [ 1.508850] io scheduler cfq registered (default)
cfq is the current I/O scheduler.
To view the IO scheduling algorithm I/O scheduler of a hard disk, use the following command:
# cat /sys/block/sda/queue/scheduler noop deadline [cfq]
Shows that the scheduler currently in use is cfq, the one enclosed in parentheses.
Modify I/O scheduler of Linux system
There are three ways to modify the Linux I/O scheduler: using shell commands, using grubby commands, or modifying the grub configuration file. The following are introduced in turn:
1. Use shell commands
Changing the I/O scheduler under Linux is simple. No kernel update required, shell commands can be used to modify:
#echo noop > /sys/block/sdb/queue/scheduler
The command in Listing 3 sets noop to a disk I/O scheduler that you can change at any time without restarting your computer.
Permanently modify the default I/O scheduler
Use shell command to modify I/O scheduler, only temporary modification, after system restart, modified scheduler will be invalid, to modify the default scheduler, there are two ways to use grubby command or directly edit the grub configuration file.
Using the grubby command
For example, to adjust the I/O scheduler from cfq to DeadLine, the command is as follows:
# grubby --grub --update-kernel=ALL --args="elevator=deadline"
By setting the kernel load parameter, the system automatically changes the I/O scheduler of all devices to DeadLine when the machine restarts.
3. Use the editor to modify the configuration file
You can also edit the grub configuration file directly. By modifying the grub configuration file, the system automatically changes the I/O scheduler of all devices to cfq. The operation process is as follows:
#vi cat /etc/default/grub #Modify the fifth line to add # elevator= cfq at the end of the line Then save the file and recompile the configuration file,#grub2-mkconfig -o/boot/grub2/grub.cfg
Restart your computer system.
That's all for "What is Linux I/O Scheduler?" Thanks for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.