OS Final
OS Final
160120733137–Srihitha Voruganti
160120733138-Sunshine Penumaka
160120733142-Yashasvi Chanda
INPUT-OUTPUT SYSTEM IN UNIX
The I/O system defines a common interface to the other parts of the
operating system
An important function for the I/O system is to hide the details in the different
hardware units from the main part of the kernel
All I/O devices in the UNIX are treated as files and considered as objects in
the file system.
The system administrator can create special files within a file system that is
referred to a specific device driver, and a user opening such a file will be able
to read from and write to the device referenced.
The administrator can set access permissions for each device by using the
normal file-protection system.
DEVICE DRIVER SYSTEM
In UNIX, hardware devices are accessed by the user through special device
files.
These files are grouped into the /dev directory, and system calls open, read,
write, close, lseek etc. are redirected by the operating system to the device
driver associated with the physical device.
The device driver is a kernel component (usually a module) that interacts
with a hardware device.
SCSI devices under Linux are often named to help the user identify the
device. For example, the first SCSI CD-ROM is /dev/scd0.
There are three main categories of I/O units in UNIX, block devices and
character devices, Network devices.
OVERALL STRUCTURE OF THE DEVICE
DRIVER SYSTEM
TYPES OF I/O UNITS IN UNIX
BLOCK DEVICES
Block devices are the devices that allow random access to completely
independent, fixed-sized blocks of data.
Hard disks, floppy disks, and CD-ROMs are examples of block devices.
‘Block’ represents the unit with which the kernel performs I/O. When a block
is read into memory, it is stored in a buffer
The request manager manages the reading and writing of buffer contents to
and from a block-device driver.
Block-device system must provide functionality to ensure that disk access is
as fast as possible. This is achieved through the scheduling of I/O operations.
TYPES OF I/O UNITS IN UNIX
BLOCK DEVICES
Disk access has always been considered the slowest method of accessing data.
The reason for this is because traditional spinning disks write data based on
locations on a spinning platter. When reading data from a spinning disk it is
necessary for the physical drive to spin the disk platters to a specific location
to read the data. This process is known as "seeking" and in terms of
computing, this process can take a long time.I/O schedulers exist as a way to
optimize disk access requests.
In traditional scheduling methods, an unidirectional-elevator (C-SCAN)
algorithm where, separate list of requests is kept for each block-device
driver.The request lists are maintained in sorted order of increasing starting-
sector number. When a request is accepted it is removed only after the I/O is
complete. As new I/O requests are made, the request manager attempts to
merge requests in the lists.
TYPES OF I/O UNITS IN UNIX
BLOCK DEVICES
Linux kernel version 2.6 introduced a new I/O scheduling algorithm
The Complete Fairness Queueing (CFQ) I/O scheduler works by creating a
per-process I/O queue. Instead of sorting requests into a list, CFQ maintains a
set of lists—by default, one for each process. The lists are maintained
according to the C-SCAN algorithm
The goal of this I/O scheduler is to provide a fair I/O priority to each process
after ordering the queues to reduce disk seeking, it services these per-process
I/O queues in a round-robin fashion.
TYPES OF I/O UNITS IN UNIX
CHARACTER DEVICES
A character-device driver can be any device driver that offers serial access to
fixed blocks of data.
Character devices include most other devices, such as mice, mouse and
keyboards
For character devices, no need of preprocessing a file read or write request
instead the request is simply passed to the device and lets the device deal
with the request.
The kernel maintains a standard interface to these drivers by means of a set
of tty_struct structures. struct tty_struct is allocated by the TTY layer upon
the first open of the TTY device and released after the last close
TTY (teletypewriter) is an abstract device in UNIX and Linux which allows
users to interact with the system (reference).
TYPES OF I/O UNITS IN UNIX
CHARACTER DEVICES
Each of these structures provides buffering and flow control on the data
stream from the terminal device and feeds those data to a line discipline.
A line discipline is an interpreter for the information from the terminal
device.
tty_line discipline is responsible for attaching and detaching the terminal’s
input and output from the various processes connected to it as those
processes are suspended or awakened by the user.
TYPES OF I/O UNITS IN UNIX
NETWORKING DEVICES
Network devices are dealt with differently from block and character devices.
Users cannot directly transfer data to network devices. Instead, they must
communicate indirectly by opening a connection to the kernel’s networking
subsystem
PPP or Point-to-Point Protocol, It is a protocol used to exchange IP frames (and
others) over a serial link.
SLIP (Serial Line Internet Protocol) is a protocol that allows you to make single,
physical serial line connection between serial ports.
PPP and SLIP networking protocols are implemented as drivers that at one end
appear to the terminal system as line disciplines and at the other end appear to
the networking system as network-device drivers. After one of these line
disciplines has been enabled on a terminal device, any data appearing on that
terminal will be routed directly to the appropriate network-device driver.
MEMORY MANAGEMENT
Memory management keeps track of each and every memory location, regardless of
either it is allocated to some process or it is free.
1. The first deals with allocating and freeing physical memory—pages, groups of pages,
and small blocks of RAM.
2. The second handles virtual memory, which is memory-mapped into the address
space of running processes.
Management of Physical Memory
Twpages: the page cache and the virtual memory system. These systems are
closely related to each other. The page cache is the kernel’s main cache for
files and is the main mechanism through which I/O to block devices is
performed. File systems of all types, including the native Linux disk-based file
systems and the NFS networked file system, perform their I/O through the
page cache. The page cache stores entire pages of file contents and is not
limited to block devices. It can also cache networked data. The virtual
memory system manages the contents of each process’s virtual address space.
These two systems interact closely with each other because reading a page of
data into the page cache requires mapping pages in the page cache using the
virtual memory system. o other main subsystems in Linux do their own
management of physical
VIRTUAL MEMORY
The kernel creates a new virtual address space in two situations: when a
process runs a new program with the exec() system call and when a new
process is created by the fork() system call.
The first case is easy. When a new program is executed, the process is given a
new, completely empty virtual address space.
The second case, creating a new process with fork(), involves creating a
complete copy of the existing process’s virtual address space.
Swapping
Once the program has been loaded and has started running, all the necessary
contents of the binary file have been loaded into the process’s virtual address space.
However, most programs also need to run functions from the system libraries, and
these library functions must also be loaded. In the simplest case, the necessary
library functions are embedded directly in the program’s executable binary file.
Such a program is statically linked to its libraries, and statically linked executables
can commence running as soon as they are loaded.
The main disadvantage of static linking is that every program generated must
contain copies of exactly the same common system library functions.
Linux implements dynamic linking in user mode through a special linker library.
Every dynamically linked program contains a small, statically linked function that is
called when the program starts. This static function just maps the link library into
memory and runs the code that the function contains.