OperatingSystem Unit-4
OperatingSystem Unit-4
Ayushi Gupta
(Assistant Professor)
Department of Computer Science and Engineering
Mangalmay Institute of Engineering and Technology, Greater Noida
Content :
Memory Management: Basic bare machine, Resident monitor,
Multiprogramming with fixed partitions, Multiprogramming with variable
partitions, Protection schemes, Paging, Segmentation, Paged segmentation,
Virtual memory concepts, Demand paging, Performance of demand paging,
Page replacement algorithms, Thrashing, Cache memory organization,
Locality of reference.
Mangalmay Institute of Engineering and Technology, Greater Noida
Basic Bare Machine:
It is the most basic environment in which there is no operating system
and user programs execute directly on the top of the hardware
resources. The program has full control over the computer. Programs
were fed to the computer system directly using machine language by the
user without any Operating system services or system software support.
The use of bare machine was very cumbersome and inefficient because
of absence of operating system all the tasks has to be performed
manually. It is the operating system that makes bare machine work like a
computer system, acts as an interface, provide friendly environment and
ease of work to system users.
Mangalmay Institute of Engineering and Technology, Greater Noida
Resident Monitor :
Resident Monitor is the first elementary OS in which the initial control
is in monitor. Here actually a small system program performs the job
sequencing task and that's why it is also known as job sequencer.
When the computer is switched on, the resident monitor is invoked
and it would loads next program and transfers control to it. When
program is finished, the control is transferred back to monitor. The
resident monitor automatically keep on transferring the control from
one program to another with no time gap between the programs. The
resident monitor consists of three major parts. These are:
• Control Language Interpreter: It responsible for reading and
carrying out instructions punched on the cards at the time of
execution.
• Loader: Control Language Interpreter call upon the loader so as to
loads systems programs and applications programs into memory.
• Device Drivers: Both control language interpreter and the loader
uses device drivers to perform 1/0 operations using system's I/O
devices. Each I/O device has associated device drivers that handle
that I/O device.
Mangalmay Institute of Engineering and Technology, Greater Noida
Memory Management and its basic concepts :
• Memory Management is the process of controlling and
coordinating computer memory, assigning portions known as
blocks to various running programs to optimize the overall
performance of the system.
There is a process queue in which all the processes waiting to come in main
memory for execution are maintained. The operating system uses scheduling
algorithm to dispatch process one by one from the process queue. If there is
partition available large enough to accommodate the process, OS loads the
process into that partition. When a program completes its execution and
terminates, its allocated memory area is free. The various available memory areas
are called holes. As memory is allocated and deallocated holes will appear in the
memory. Holes of various sizes are spread throughout memory. Figure 4.4 shows
'holes' in variable partitions multiprogramming system.
Mangalmay Institute of Engineering and Technology, Greater Noida
Mangalmay Institute of Engineering and Technology, Greater Noida
When a process is dispatched from process queue to store in memory, OS
first searches for the hole large enough to accommodate that process. If
none of the available holes are large enough to accommodate that
process then available adjacent free partitions can be merged together to
form big hole (bigger space) to accommodate that process. This process
of merging adjacent free partitions to form big hole is called coalescing
and is shown in figure
Mangalmay Institute of Engineering and Technology, Greater Noida
Paging
• Basic Paging Method
Paging is one of the memory management scheme used generally in most of the operating
system. Paging is a good solution to problem of fragmentation. In paging both physical and
virtual memory are divided into fixed sized blocks. These fixed sized blocks are called frames
in physical memory and pages in logical memory. Both frame and page are of same size.
Mangalmay Institute of Engineering and Technology, Greater Noida
Below figure shows logical memory, page table and physical memory
implementation in terms of paging.
Mangalmay Institute of Engineering and Technology, Greater Noida
Page size is decided by the paging hardware. Page size is of the form 2*,
means power of 2 like - 16(24), 32(2 etc. If suppose logical address is of
size 2 power m unit (unit can be bits, byte or word) in which page size is 2
power n , then higher order 'm-n' bits of logical address denotes page
number and 'n' lower bits denotes page offset. Thus logical address
division is:
Page number Page offset
m-n n
For example suppose logical address is of size 216 and page size is 25, so
m =16 and n = 6
Thus logical address division is:
15 6 5 0
m-n = 10 n=6
m=16
Mangalmay Institute of Engineering and Technology, Greater Noida
Page size is decided by the paging hardware. Page size is of the form 2*,
m=16
Let us consider an example in which :
• Physical memory is of size 16 bytes.
• Logical memory has pages of size 2 bytes each
• So total pages that can be stored in physical memory
= Physical memory size / Logical memory size
= 16/2 = 8 pages
The logical address generated by CPU is divided into 3 fields- process ID,
page number and page offset. Process id is the unique identification
number of the process that is associated with that logical address. Each
entry in the inverted page table consists of a process ID and page
number. Whenever CPU generates the logical address, the PID and page
number combination is picked from this logical address and searched in
the inverted page table. The index of the inverted page table is the frame
number. When a match is found, the index (frame number) that matches
is combined with the offset field of logical address to obtain a physical
address. If no match is found, a page fault occurs. This translation
procedure is shown in figure.
Mangalmay Institute of Engineering and Technology, Greater Noida
Inverted Page Table figure given below :
Mangalmay Institute of Engineering and Technology, Greater Noida
An Inverted Page Table has one major advantage it is never be larger than
the size of physical memory. By contrast, the size of a page table is
determined by the amount of virtual memory used. Thus using inverted
page table scheme size of page table can be reduced. But inverted page
table has one major disadvantage : it is more complex and expensive to
use (in terms of time) for mapping the virtual address to a physical
address. The search of the inverted page table can be improved by using
a hashed table.
Mangalmay Institute of Engineering and Technology, Greater Noida
Segmentation :
Segmentation is scheme used by memory-management unit for virtual to
physical address translation. Segmentation provides a view that a user
can more easily relate and understand. This is because a user program
has different segments such as: main program, procedure, functions,
local variables, global variables, common block, stack, symbol table,
arrays, other data structures etc. All the segments defined in a user
program have specific purpose and that's why these segments are of
variable length. Also user is not concerned where and how these
elements are stored in memory. Using segmentation the logical address
space (where user program resides), is divided into segments where each
segment is of variable length and different segments can be stored
anywhere in memory. Thus user fined segmentation more easy to relate
with their program without going into details of how these segments are
managed. The logical address space where user program resides from
user outlook is shown in figure below.
Mangalmay Institute of Engineering and Technology, Greater Noida
User Outlook of Logical Address Space where User Programs resides.
Mangalmay Institute of Engineering and Technology, Greater Noida
Segmentation Implementation:
In segmentation, each segment in the logical address space has a specific
number and the length associated with it. Each segment has starting
address (base) and the limit that sets the range of that segment. In
paging the user specifies the logical address which was divides into page
number and page offset by paging hardware, but in segmentation the
user specifies the logical address using two dimensions:
<segment number, segment offset>
Thus in segmentation two-dimensional user defined logical address is to
be mapped into one-dimensional physical address. For this segment
table is used. Each entry in the segment table has:
• base that points the starting address of the segment in physical
memory.
• limit that specifies the length of the segment
Segmentation Disadvantage :
• Segmentation requires more complicated hardware for address
translation than paging.
Mangalmay Institute of Engineering and Technology, Greater Noida
• Segmentation suffers from external fragmentation. Paging only yields
a small internal fragmentation.