Sie sind auf Seite 1von 15

Kernels provide many services related to I/O.

Several services are given below


1. The management of the name space for file and devices
2. Access control to files and devices
3. Operation control (for example, a modem cannot seek ())
4. File System space allocation
5. Device allocation
6. Buffering, caching, and spooling
7. I/O scheduling
8. Device status monitoring, error handling and failure recovery
9. Device driver configuration and initialization
1. Access control to files and device
Owner: The user who created the file is the owner.

Group: A set of user who is sharing the file and need similar access is a group, or work group.

Universe: All other users in the system constitute the universe.

Access Lists and Groups


The most common approach to the protection problem is to make access dependent on the
identity of the user. Various users may need different identity-dependent access is to associate with
each file and directory an Access-Control List (ACL)
• Mode of access: read, write, execute
• Three classes of users
• RWX
• a) owner access 7 ⇒ 111
RWX
• b) group access 6 ⇒ 110
• RWX
• c) public access 1 ⇒ 001
• Ask manager to create a group (unique name), say G, and add some users to the group.
• For a particular file (say game) or subdirectory, define an appropriate access.
5. Device allocation
• Some operating systems provide support for exclusive device access, by enabling a process
to allocate an idle device and to deallocate that device open file handle to such a device.
• Many operating systems provide functions that enable processes to coordinate exclusive
access among them.
• For example, Windows NT provides system calls to wait until a device object becomes
available.
• It has a parameter to the open () system call that declares the types of access to be permitted
to other concurrent thread.
6. Buffering:
A buffer is a memory area that stores data while they are transferred between two devices or
between a device and an application. Buffering is done for three reasons.
The three reasons are given below

1. It is to cope with a speed mismatch between the producer and consumer of a data stream
Example:
A file is being received via modem for storage on the hard disk. The modem is about a thousand
times slower than the hard disk. So a buffer is created in main memory to accumulate the bytes
received form the modem.
When an entire buffer of data has arrived, the buffer can be written to disk in a single operation.
The modem needs the two buffers to store additional incoming data, two buffers are used.
After the modem fills the first buffer, the disk write is requested. When the modem the starts to fill
the second buffer while the first buffer is written to disk. By the time the modem has filled the
second buffer, the disk write from the first one should have completed, so the modem can switch
back to the first buffer while disk writes the second one. This is called double buffering.
2. A second use of buffering is to adapt between devices that have different data transfer sizes.
Buffers are used for fragmentation and reassembly of messages. At the sending side, a large
message is fragmented into small network packets. The packets are sent over the network, and the
receiving side places them in a reassembly buffer to form an image of the source data.
3. A third use of buffering is to support copy semantics for application I/O.
Copy semantics:
• An application has a buffer of data that it wishes to write to disk.
• It calls the write () system call, providing a pointer to the buffer and an integer
specifying the number of bytes to write.
• A write() system call to copy the application data into a kernel buffer before
returning control to the application.
• The disk write is performed from the kernel buffer, so that subsequent changes
to the application buffer have no effect.
6.caching
• A cache us a region of fast memory that holds copies of data.
• Access to the cached copy is more efficient than access to the original.
• The instructions of currently running process are stored on disk, cached in physical memory,
and copied again in the CPU’s secondary and primary caches.
• The difference between a buffer and cache is that buffer may hold the only existing copy of
data item, whereas a cache holds a copy on faster storage of an item that resides elsewhere.
• To enable efficient scheduling of disk I/O, the operating system uses buffers in main
memory to hold disk data.
• These buffers are also used as a cache, to improve the I/O efficiency for files that are shared
by applications or that are being written and reread.
6.spooling:
• A spool is a buffer that holds output for device, such as printer, that cannot accept
interleaved data streams.
• Although a printer can serve only one job at a time, several applications may wish to print
their output concurrently, without having their output mixed together.
• The operating system solves this problem by intercepting all output to the printer.
• Each application’s output is spooled to separate disk file.
• When an application finishes printing, the spooling system queues the corresponding spool
file for output to the printer.
• The spooling system copies the queued spool files to the printer one at a time.
• The operating system provides a control interface that enables user and system administrator
to display the queue to remove unwanted jobs before those jobs print, to suspend printing
while the printer is serviced.
7.I/O scheduling:
• To schedule a set of I/O requests means to determine a good order in which to execute
them.
• Scheduling can improve overall system performance; can share device access fairly
among process.
• It can reduce the average waiting time for I/O to complete.

Example:
Application 2 requests one near the beginning, and application 3 requests one in the middle of the
disk.
The operating system can reduce the distance that the disk arm travels by servicing the applications
in order 2,3,1.
8.Error Handling:
• An operating system protected the memory from the hardware failure and application errors.
• Devices and I/O transfers can fail in many ways, either for transient reasons, such as
network becoming overloaded, or for the permanent reasons, such as disk controller
becoming defective.
• Operating system can compensate for transient failure. For example, a disk read () failure
results in a read () retry (), and a network send () error results in a resend ().
• I/O system call will return 1 bit of information about the status of the call.
In UNIX operating system an additional integer variable named errno is used to return an
error code-one of about 100 values –indicating the general failure of the failure.
• For example a failure of a SCSI device is reported by the SCSI such as hardware error or an
illegal request and additional sense code that states the category of failure such as bad
command parameter or self test failure and additional sense code qualifier that gives even
more details.
UNIX I/O Kernel Structure

• The kernel needs to keep state information about the use of I/O components. It does so
through a variety of in Kernel data structures, such as the Open-file table structure.

• The kernel uses many similar data structures to track network connections, character
communications and other I/O activities.

• UNIX provides file-system to a variety of entities, such as user files raw devices, and the
address spaces of processes.

• Although each of these entities supports a read () operation, the semantics differ.

• For instance, to read a user file, the kernel needs to provide the buffer cache before deciding
whether to perform a disk I/O.

• To read a raw disk, the kernel needs to ensure that the request size is multiple of the disk
sector size, and is aligned on a sector boundary.

• To read a process image, it is merely necessary to copy data from memory.


• UNIX encapsulates these differences within a uniform structure by using an object-oriented
technique. The open-file record contains a dispatch table the holds pointers to the appropriate
routines, depending on the type of file.

• Some operating systems use object oriented methods even more extensively.
• In Windows NT uses a message-passing implementation for I/O.

• An I/O request is converted into a message that is sent through the kernel to the I/O manager
and the to the device driver, each of which may change the message contents.

• For O/P the message contains the data to be written.

• For I/P the message contains, a buffer to receive the data.

• The message passing simplifies the structure and designs the I/O system and adds flexibility.

16 marks questions

1. Expalin the kernel I/O subsystem structures

2. Explain the kernel I/O subsystem services

Mass-Storage Systems

• Disk structure
• Disk scheduling
• Disk management
• Swap-space management

Disk structure

• Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical
block is the smallest unit of transfer.
• The 1-dimensional array of logical blocks is mapped into the sectors of the disk
sequentially.
o Sector 0 is the first sector of the first track on the outermost cylinder.
o Mapping proceeds in order through that track, then the rest of the tracks in that
cylinder, and then through the rest of the cylinders from outermost to innermost.
Disk Scheduling

 The operating system is responsible for using hardware efficiently — for the disk drives, this
means having a fast access time and disk bandwidth.
 Access time has two major components
 Seek time is the time for the disk are to move the heads to the cylinder containing the
desired sector.
 Rotational latency is the additional time waiting for the disk to rotate the desired sector
to the disk head.
 Minimize seek time
 Seek time ≈ seek distance
 Disk bandwidth is the total number of bytes transferred, divided by the total time between the
first request for service and the completion of the last transfer.
 Several algorithms exist to schedule the servicing of disk I/O requests.
 We illustrate them with a request queue (0-199).

98, 183, 37, 122, 14, 124, 65, 67

Head pointer 53

FCFS
Illustration shows total head movement of 640 cylinders.
SSTF
 Selects the request with the minimum seek time from the current head position.
 SSTF scheduling is a form of SJF scheduling; may cause starvation of some requests.
 Illustration shows total head movement of 236 cylinders.

SCAN
 The disk arm starts at one end of the disk, and moves toward the other end, servicing requests
until it gets to the other end of the disk, where the head movement is reversed and servicing
continues.
 Sometimes called the elevator algorithm.
 Illustration shows total head movement of 208 cylinders.
C-SCAN

 Provides a more uniform wait time than SCAN.


 The head moves from one end of the disk to the other. Servicing requests as it goes. When it
reaches the other end, however, it immediately returns to the beginning of the disk, without
servicing any requests on the return trip.
 Treats the cylinders as a circular list that wraps around from the last cylinder to the first one.
C-LOOK
 Version of C-SCAN
 Arm only goes as far as the last request in each direction, then reverses direction immediately,
without first going all the way to the end of the disk.

Selecting a Disk-Scheduling Algorithm


 SSTF is common and has a natural appeal
 SCAN and C-SCAN perform better for systems that place a heavy load on the disk.
 Performance depends on the number and types of requests.
 Requests for disk service can be influenced by the file-allocation method.
 The disk-scheduling algorithm should be written as a separate module of the operating system,
allowing it to be replaced with a different algorithm if necessary.
 Either SSTF or LOOK is a reasonable choice for the default algorithm.

Disk Management

1. Disk initialization
2. Booting from disk
3. Bad –block recovery

Disk formatting:
A new magnetic disk is a blank slate. Before a disk can store data; it must be divided into
sectors that the controller can read and write.
This process is called low-level formatting (or physical formatting)

Low level formatting:

It fills the disk with special data structure for each sector.
The data structure for a sector typically consists of a header, a data area and a trailer (512 bytes)
The header and trailer contain information used by the disk controller, such as a sector number and
an error code (ECC)

When the controller writes a sector of data during normal I/O, The ECC is updated with value
calculated from all the bytes in the data area. When the sector is read, the ECC is recalculated and is
compared with the stored value .If the stored and calculated numbers are different, this mismatch
indicates that the data area of the sector has become corrupted and the disk sector may be bad.
Logical formatting:
To use a disk to hold files, the operating system needs to record its own data structures on
the disk.
It does so in two steps
1. It partitioned the disk into one or more groups of cylinders. The operating
system can treat each partition as though it were a separate disk.
One partition can hold a copy of the operating system executable code.
Another holds user files.
2. The second step is logical formatting the operating system stores the
initial file
BOOT BLOCK
system data
structures onto
FAT
the disk

ROOT DIRECTORY MS-DOS DISK


LAYOUT
DATA BLOCKS
(SUB DIRECTORIES)
Boot Block:
• When the system
is powered up or rebooted, it needs to have an initial program to run.
• This initial bootstrap program tends to be simple. It initializes all aspects of the system
form CPU registers to device controllers and the contents of main memory and then
starts the operating system
• Bootstrap program finds the operating system kernel on disk Loads the kernel into
memory and jumps to an initial address to begin the operating system executing.
• Bootstrap is stored in read-only memory(ROM).This location is convenient, because
ROM needs no initialization and is at a fixed location that the processor can start
executing when powered up or reset.
• The problem is that changing this bootstrap code requires changing the ROM hardware
chips.
• The full bootstrap program can be changed easily.
• The full bootstrap program is stored in a partition called the boot blocks, at a fixed
location on data.
• A disk that has a boot partition is called a boot disk or system disk.

Bad blocks(one or more sectors become define)


• The MS_DOS format command does a logical sometime the failure is completed and the
disk needs to be replaced and its contents restored from backup media to the new disk.
• MS-DOS format command does a logical format and operating system a part of the process,
scan the disk to find bad blocks. If format finds a bad block ,it writes a special value into
the corresponding FAT entry to tell the allocation routines not to use that block.(chkdsk)
must be run manually to search for the bad block is data that resided on the bad block
usually are lost.

• The controller can be told to replace each bad sector logically with one of the spare sectors.
This scheme is known as sector sparing or forwarding.

Example
• A typical bad-sector transaction might be as follows .The Operating system tries to read
logical block 87
• The controlled calculates the ECC and finds that the sector is bad .It reports this finding
the operating system
• The next time that the system is rebooted, a special command is run to tell the SCSI
controller to replace the bad sector with a spare.
• After that whenever the system requests logical block 87, the request is translated into
the replacement sectors address by the controller.
Some controllers can be instructed to replace a bad block by sector slipping.
Logical block 17 becomes defective and the first available spare follows sector 202, then
sector slipping would remap all the sectors form 17 to 202.

Swap-space management:
Low levels task operating system
• How swap space is used
• Where swap space is located on disk
• How swap space is managed
Swap space use:
Implementing swapping may use swap space to hold the entire process image including the
code and data segments.
Swap space location:
Two places
• Out of the normal system
• It can be in separate disk partition
Swap space Management:
Enough space is aside to hold the program known as the text pages or the text segment and the
data segment of the process.
Swap Maps:
Two process swap maps are used by the kernel to track swap space use .The test segment is a fixed
size.

The text segment is a fixed size, so its swap space is allocated in 512 kB chunks, except for the final
chunk, which holds the remainder of the page

The data segment:


Swap map is more complicated because that data segment can grow over time .The map is of fixed
size, but contains swap address for blocks of varying size. Given index i a block pointed to by
swap-map entry I is of size 2*16 KB to maximum of 2MB.

16 marks questions
1. Explain disk scheduling algorithms
2. Suppose that disk drive has 5,000 cylinders, numbers to 0 to 4000.The drive is currently serving a
request at cylinder 143 and the previous request was at cylinders 125.The queue of pending requests
in FIFO order is
86,1470,913,1774,1509,1022,1750,130.
Starting from the current head position what is the total distance that the disk arm moves to satisfy
all the pending requests for each of the following disk-scheduling algorithms?
• FCFS,SSTF
• SCAN
• LOOK
• C-SCAN ,C-LOOK
3. Explain disk structure with diagram
4. Explain swap space management
5. Explain disk management

Das könnte Ihnen auch gefallen