Operating System~Spooling Technology and Buffer Management

What is offline technology

In the traditional batch operating system, we write the input data to the tape uniformly, and write the output data to the tape uniformly. This is an offline technology.

Tips: Why is it called "offline"-input/output operations performed out of the control of the host.
Insert picture description here

Spooling technology-input/output buffer

"Spooling technology", also known as "SPOOLing technology" is to use software to simulate offline technology. The composition of the SPOOLing system is as follows

Insert picture description here

The realization principle of shared printer

Exclusive device-a device that allows serial use of each process. Only one process request can be satisfied in a period of time. Shared device-a device that allows multiple processes to use "simultaneously" (simultaneous use on a macro level, and alternate use on a micro level). Can satisfy the use request of multiple processes at the same time.

Insert picture description here
When multiple user processes request output and printing, the system will agree to their request, but the printer is not actually assigned to them, but the spool management process does two things for each process:

(1) Request a free buffer for the process in the disk output well (that is, the buffer is on the disk), and send the data to be printed into it;
(2) Request a blank print for the user process Request form, and fill the user's print request into the form (in fact, it is used to explain the storage location of the user's print data and other information), and then hang the form on the spool file queue.

When the printer is idle, the output process will take out a print request form from the head of the file queue, and transfer the data to be printed from the output well to the output buffer according to the requirements in the form, and then output to the printer for printing. In this way, all printing tasks can be processed in sequence

Insert picture description here
Although there is only one printer in the system, when each process makes a print request, the system will allocate a storage area for it in the output well (equivalent to assigning a logical device), so that each user process feels that it is monopolizing it. Printers, so as to realize the sharing of printers.

SPoOLing technology can virtualize a physical device into multiple logical devices, and can transform an exclusive device into a shared device.

Buffer management

The buffer is a storage area, which can be composed of dedicated hardware registers, or the memory can be used as a buffer.

The cost of using hardware as a buffer is relatively high, and the capacity is small. It is generally only used in occasions that require very high speed (such as the Lenovo register used in memory management. Due to the extremely high frequency of access to the page table, the use speed is very high. Fast Lenovo register to store a copy of the page table entry)

In general, memory is used as a buffer. The buffer management of "device independence software" is to organize and manage these buffers.

Insert picture description here

The working process of the buffer

Insert picture description here
If the CPU wants to write data, directly write it to the memory buffer. After the buffer is written, use the I/O device to slowly read the data, improve the parallelism between the CPU and the I/O device, and solve the problem between the CPU and the I/O device. /O device speed does not match the problem, reduce the frequency of interruption

Single buffer

Suppose a user process requests a certain block device to read several blocks of data. If the single-buffer strategy is adopted, the operating system will allocate a buffer in the main memory for it (if not specified in the title, the size of a buffer is one block).

Note :
When the buffer data is not empty, data cannot be flushed into the buffer, but data can only be transferred out from the buffer;
when the buffer is empty, data can be flushed into the buffer, but the buffer must be filled later , To transfer data from the buffer.
Insert picture description here

Double buffering

Suppose a user process requests a certain block device to read several blocks of data. If the double buffering strategy is adopted, the operating system will allocate two buffers for it in the main memory

When communicating between two machines, double buffers can be configured for data sending and receiving.
Insert picture description here
If two mutually communicating machines are equipped with double buffers, two-way data transmission can be realized at the same time.
Note: The "pipe" in pipe communication is actually a buffer. To realize the two-way transmission of data, two pipelines must be set up

Circular buffer

Link multiple buffers of equal size into a circular queue.
Note: In the following figure, orange indicates a buffer full of data, and green indicates an empty buffer.
Insert picture description here

Buffer pool

The buffer pool is composed of buffers shared in the system. These buffers can be divided into: empty buffer queue, buffer queue full of input data (input queue), and buffer queue full of output data (output queue) according to usage status.

In addition, according to the different functions of a buffer in the actual operation, four working buffers are set up: working buffer (hin) for storing input data, working buffer (sin) for extracting input data, The working buffer (hout) used to hold output data, the working buffer (sout) used to extract output data
Insert picture description here
①The input process requests input data
Insert picture description here
②The calculation process wants to obtain a piece of input data

Insert picture description here
③The calculation process wants to flush the prepared data into the buffer
Insert picture description here
④The output process requests the output data
Insert picture description here

Guess you like

Origin blog.csdn.net/Shangxingya/article/details/113814372