Chapter - 5 - Memory Management and IO Management
Chapter - 5 - Memory Management and IO Management
Concepts
CS284
Chapter 4
Memory Management and IO
Management
• Memory Management
• Memory management is the functionality of an operating system which
handles or manages primary memory. Memory management keeps track of
each and every memory location either it is allocated to some process or it is
free. It checks how much memory is to be allocated to processes. It decides
which process will get memory at what time. It tracks whenever some
memory gets freed or unallocated and correspondingly it updates the status.
• Memory management provides protection by using two registers, a base
register and a limit register. The base register holds the smallest legal
physical memory address and the limit register specifies the size of the
range.
• Instructions and data to memory addresses can be done in following ways
• Compile time -- When it is known at compile time where the process will
reside, compile time binding is used to generate the absolute code.
• Load time -- When it is not known at compile time where the process will
reside in memory, then the compiler generates re-locatable code.
• Execution time -- If the process can be moved during its execution from
one memory segment to another, then binding must be delayed to be done
at run time
• Dynamic Loading
• In dynamic loading, a routine of a program is not loaded until it is called by
the program. All routines are kept on disk in a re-locatable load format. The
main program is loaded into memory and is executed. Other routines
methods or modules are loaded on request. Dynamic loading makes better
memory space utilization and unused routines are never loaded.
• Dynamic Linking
• Linking is the process of collecting and combining various modules of code
and data into a executable file that can be loaded into memory and
executed. Operating system can link system level libraries to a program.
When it combines the libraries at load time, the linking is called static
linking and when this linking is done at the time of execution, it is called as
dynamic linking.
• In static linking, libraries linked at compile time, so program code size
becomes bigger whereas in dynamic linking libraries linked at execution
time so program code size remains smaller.
• Logical versus Physical Address Space
• An address generated by the CPU is a logical address whereas address
actually available on memory unit is a physical address. Logical address is
also known a Virtual address.
• Virtual and physical addresses are the same in compile-time and load-time.
Virtual and physical addresses differ in execution-time.
• The set of all logical addresses generated by a program is referred to as a
logical address space. The set of all physical addresses corresponding to
these logical addresses is referred to as a physical address space.
• The run-time mapping from virtual to physical address is done by the
memory management unit (MMU) which is a hardware device.
• Swapping
• Swapping is a mechanism in which a process can be swapped temporarily
out of main memory to a backing store, and then brought back into memory
for continued execution. Backing store is a usually a hard disk drive or any other
secondary storage which fast in access and large enough to accommodate copies of all
memory images for all users
• Memory Allocation
• Main memory usually has two partitions
• Low Memory -- Operating system resides in this memory.
• High Memory -- User processes then held in high memory.
• Segmentation
• Segmentation is a technique to break memory into logical pieces where each
piece represents a group of related information. For example, data segments
or code segment for each process, data segment for operating system and so
on. Segmentation can be implemented using or without using paging.
• Unlike paging, segment is having varying sizes and thus eliminates internal
fragmentation. External fragmentation still exists but to lesser extent
• Virtual Memory
• Virtual memory is a technique that allows the execution of processes which
are not completely available in memory. The main visible advantage of this
scheme is that programs can be larger than physical memory. Virtual
memory is the separation of user logical memory from physical memory.
• This separation allows an extremely large virtual memory to be provided for
programmers when only a smaller physical memory is available. Following
are the situations, when entire program is not required to be loaded fully in
main memory.
• Virtual memory is commonly implemented by demand paging. It can also be
implemented in a segmentation system. Demand segmentation can also be
used to provide virtual memory.
Demand Paging
• A demand paging system is quite similar to a paging system with swapping.
When we want to execute a process, we swap it into memory. Rather than
swapping the entire process into memory, however, we use a lazy swapper
called pager.
• In virtual memory systems, demand paging is a type of swapping in
which pages of data are not copied from disk to Memory until they are
needed.
Page Replacement Algorithm
Page replacement algorithms are the techniques using which Operating
System decides which memory pages to swap out, write to disk when a page
of memory needs to be allocated. Paging happens whenever a page fault
occurs and a free page cannot be used for allocation purpose accounting to
reason that pages are not available or the number of free pages is lower than
required pages.
• Reference String
The string of memory references is called reference string. Reference strings
are generated artificially or by tracing a given system and recording the
address of each memory reference.
• First In First Out (FIFO) algorithm
Oldest page in main memory is the one which will be selected for
replacement. Easy to implement, keep a list, replace pages from the tail and
add new pages at the head.
• Optimal Page algorithm
An optimal page-replacement algorithm has the lowest page-fault rate of all
algorithms. An optimal page-replacement algorithm exists, and has been
called OPT or MIN. Replace the page that will not be used for the longest
period of time . Use the time when a page is to be used.
• Least Recently Used (LRU) algorithm
Page which has not been used for the longest time in main memory is the one
which will be selected for replacement. Easy to implement, keep a list, replace
pages by looking back into time.
• Page Buffering algorithm
To get process start quickly, keep a pool of free frames. On page fault, select a
page to be replaced. Write new page in the frame of free pool, mark the page
table and restart the process. Now write the dirty page out of disk and place
the frame holding replaced page in free pool.
• Least frequently Used (LFU) algorithm
Page with the smallest count is the one which will be selected for
replacement. This algorithm suffers from the situation in which a page is
used heavily during the initial phase of a process, but then is never used
again.
• Most frequently Used (MFU) algorithm
Page with the largest count is the one which will be selected for replacement.
• I/O Management
• Computers operate on many kinds of devices. General types
include storage devices (disks, tapes), transmission devices
(network cards, modems), and human-interface devices (screen,
keyboard, mouse). Other devices are more specialized. A device
communicates with a computer system by sending signals over
a cable or even through the air. The device communicates with
the machine via a connection point termed a port (for example,
a serial port). If one or more devices use a common set of wires,
the connection is called a bus. In other terms, a bus is a set of
wires and a rigidly defined protocol that specifies a set of
messages that can be sent on the wires.
• Controller
• A controller is a collection of electronics that can operate a
port, a bus, or a device. A serial-port controller is an example of
a simple device controller. This is a single chip in the computer
that controls the signals on the wires of a serial port.
• The bus controller is often implemented as a separate circuit
board (a host adapter) that plugs into the computer. It contains
a processor, microcode, and some private memory to enable it
to process the SCSI protocol messages. Some devices have their
own built-in controllers.
I/O port
An I/O port typically consists of four registers, called the status, control,
data-in, and data-out registers