Page 442 - DCAP103_Principle of operating system
P. 442
Unit 14: Case Study of Linux Operating System
Notes
the 2.2 kernel, Linux maintained completely separate page and buffer caches, so a file
residing in a disk block could be cached in both caches. Newer versions of Linux have
a unified cache. A generic block layer holds these components together, and performs
the necessary translations between disk sectors, blocks, buffers and pages of data, and
enables the operations on them.
The cache is a table in the kernel for holding thousands of the most recently used blocks. When
a block is needed from a disk for any purpose (i-node, directory, or data), a check is first made
to see that it is in the cache. If so, it is taken from there and a disk access is avoided, thereby
resulting in great improvements in system performance. If the block is not in the page cache, it
is read from the disk into the cache and from there, copied to where it is needed. Since the page
cache has room for only a fixed number of blocks, the page replacement algorithm described
in the previous section is invoked. The page cache works for writes as well as for reads. When
a program writes a block, it goes to the cache, not to the disk.
Figure 14.22: The Linux I/O System
Virtual File System
Cache
Disk Block Char Network
file device device socket
system file file
I/O
Line Protocol
scheduler
discipline drivers
Block Char Network
device device device
driver driver driver
In addition to avoid having blocks stay too long in the cache before being written to the disk,
all the dirty blocks are written to the disk every 30 seconds. In order to minimize the latency
of repetitive disk head movements, Linux relies on an I/O scheduler. The purpose of the I/O
scheduler is to reorder or bundle read/write requests to block devices. There are many scheduler
variants, optimized for different types of workloads. The basic Linux scheduler is based on the
original Linus Elevator scheduler. The operations of the elevator scheduler can be summarized
as follows—disk operations are sorted in a doubly linked list, ordered by the address of the
sector of the disk request. New requests are inserted in this list in a sorted manner. This prevents
repeated costly disk head movements.
The request list is than merged so that adjacent operations are issued via a single disk request.
The basic elevator scheduler can lead to starvation. Therefore, the revised version of the Linux
disk scheduler includes two additional lists, maintaining read or write operations ordered by
their deadline. The default deadlines are 0.5 sec for read requests and 5 sec for write requests.
If a system defined deadline for the oldest write operation is about to expire, that write request
will be serviced before any of the requests on the main doubly linked list. The interaction with
character devices is much simpler. Since character devices produce or consume streams of
LOVELY PROFESSIONAL UNIVERSITY 435