I/O Buffering & Disk I/O In Operating Systems

I/O Buffering & Disk I/O In Operating Systems

The two main jobs of a computer system are I/O and processing. In many cases, the main job is I/O. The role of the operating system in a computer is to manage and control I/O operations and I/O devices. The I/O devices can be roughly grouped into 3 categories.

  1. Human readable: This type of I/O device establishes communication between the computer and the user. Examples are a keyboard, mouse, printer, video display terminal, etc.,
  2. Machine-readable: Suitable for communication with electronic equipment. Examples are disk drives, tape drives, sensors, controllers, etc.,
  3. Communication: Suitable for communication with remote devices. Examples are digital line drivers and modems.

There are so many differences between I/O devices in various aspects. These are:

1. Data Rate: Data rates vary between I/O device to I/O device. Generally, data rates are measured by Kb/s. Out of all devices, the keyboard has the least data transmission rate (0.01 Kb/s). The graphics display is the highest transmission rate (30,000 Kb/s).

2. Application: The function of the I/O device is dependent on the application. For example, a disk is used to store the files in an ordinary manner, and the same disk is used as a spooler disk (temporary storage) in spooling. And the same disk is used as a swap disk in demand paging. So, the purpose of I/O is depended on the application.

3. The complexity of control: A mouse or a keyboard requires a relatively simple control interface. A disk is much more complex.

4. Unit of transfer: Data may be transferred as a stream of bytes (or) characters (ex: terminal) or in large blocks (ex: A disk).

5. Data Representation: Different data encoding schemes are used by different devices, including differences in character code and parity conventions.

6. Error Conditions: The nature of errors, the way in which they are reported, their consequences, and the available range of responses differ widely from one device to another.

I/O Buffering

A Buffer is a temporary storage area. Generally, a buffer stores the data when data is transferred between two devices or in one device and one application. For example, a user wants to take a printout of his program and issue a print command. Then the program temporarily stored data in the printer buffer and the printer consumes this data from the Printer Buffer. This type of mechanism is called Buffering.

Buffering is done for three reasons.

  1. If the producer device is a high speed and the consumer device is at low speed. At that time buffering is required. For example, hard disk (producer) and printer (consumer).
  2. If two devices have different data transfer sizes (block size), then buffering is required. For example, in networks, a large message is divided into a number of small packets. The packets are sent over the network. Then the receiving side places these packets into the buffer to convert them into the packet sizes of the source devices.
  3. A third use of buffering is to support copy semantics for the application I/O. For example, copying the data between kernel buffers and application data space.

Generally, there are 3 types of buffering:

  1. Single buffering
  2. Double buffering
  3. Circular buffering

1. Single buffering

In this buffering, only one buffer is used to transfer the data between two devices. The producer produces one block of data into the buffer. After that, the consumer consumes the buffer only when the buffer is empty. After that, the processor again produces the data to send. For example, consider the below figure.


The main drawback of this method is the data transfer rate is very low because the producer has to wait while the consumer consumes the data.

2. Double Buffering

This method overcomes the drawbacks faced in single buffering. In this scheme, two buffers are used in place of one. In this scheme, the producer produces one buffer, and at the same time, the consumer consumes another buffer. So, the producer does need not to wait for filling the buffer. For a better understanding consider the below figure.


3. Circular buffering

When more than two buffers are used, the collection of buffers is itself referred to as a circular buffer. Consider the below figure for a better understanding. Each individual buffer is one unit in the circular buffer. The data transfer rate will increase using the circular buffer rather than the double buffering.


Disk I/O

Disk Structure

A hard disk is a collection of platters and each disk platter has a flat circular shape like a compact disk (CD). The common platter diameter ranges from 1.8 to 5.25 inches. The two surfaces of a platter are covered with magnetic material. We can store information by recording it magnetically on the platters. Consider the below figure.


A read/write head is located just above each surface of every platter. The space of the platter is logically divided into circular Tracks. the tracks are subdivided into Sectors. The set of tracks that are at one arm position forms a Cylinder. The heads are attached to a disk arm, in which all the heads are a unit. The storage capacity of common disk drives is measured in gigabytes.

Disk performance parameter

When the disk is in use, a drive motor spins it at high speed. Most drives rotate 60 to 150 times per second. To read or write, the head must be positioned at the desired track and at the beginning of the desired sector on the track.

The time it takes to position the head at the desired track is called Seek Time. Once the track is selected the disk controller waits until the desired sector reaches the read/write head. The time it takes to reach the desired sector is called Latency Time or Rotational Delay. The sum of seek time and rotational delay is the Access Time. When the desired sector reached the read/write head, then the real data transferring starts.

Seek time: The time required to reach the desired track by read/write head is the Seek Time. The seek time consists of two key components. The internal startup time and the time taken to traverse the cylinders. The linear formula for seek time is

Ts = m *n + s
Ts = Estimated seek time.
n = Number of tracks traversed.
m = Constant that depends on the disk drive.
s = startup time.

Rotational delay: The time required to reach the desired sector by the read/write head is called rotational delay. Generally, the average rotational delay will be between 100 and 200m seconds.

Transfer time: The transfer time is depended on the rotation speed of the disk. The formula for transfer time is:

T =  B/R * N
T = Transfer rate.
B = Number of bytes to be transferred.
N = Number of bytes on track.
R = Rotation speed in revolutions per second.

Thus, the total average access time can be expressed as
Ta = Ts + 1/2R + B/R*N
where Ts is the average seek time.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top