Unit 1
Unit 1
Processor File
Handles incoming jobs Manager Manager Manages all files
Allocate CPU (manages CPU) Creation
Keep track of status of Restrictions on files
Process Deletion
Deallocates the CPU
2. Interactive or Time Sharing Systems: The user directly interacts with the
system through an interface. In these systems each process is allocated a
particular time span and the process has to finish its execution within that time
span. After the time span is over the CPU is allocated to the next process for
execution. Here the response time is less as compared to batch systems
3. Real time systems: This type of OS deals with real time appliactions. It is
used in time critical environment where the data needs to be processed very
fast without any buffer delays because some immediate decisions needs to be
taken based on the output. Such OS’s are used in space flights, air traffic
control, field of medicine etc.
Single User Contiguous scheme: Entire Program to be processed is loaded in the memory.
Program is loaded at contiguous locations.
Drawbacks:
1. If the size of the program is more than the available memory, the program cannot get
executed. So either memory is increased or program is modified to be made more compact.
2. It does not support multiprogramming.
Disadvanatage:
• Entire Program needs to be loaded on the memory
• The program uses continuous locations of the memory.
• If the partition sizes are too small : large jobs will rejected.
• If partition sizes are too big : memory space within the partition is wasted as the job does
not occupy the entire partition. This unused memory space within the partition cannot be
given to any other job. So a fragment of the partition goes waste and this unused space
within the partition is known as Internal Fragmentation, which is the major drawback of
Fixed Partition scheme.
Partition size 50 K
Job
Job 12 (35 K)
(25K)
Unused space (15K)
Internal fragmenatation of 15 K
7/25/2024 L J College of Computer Applications
Dynamic Partition Scheme : (supported multiprogramming)
When a job is loaded for processing it is allocated as much memory as it requests for i.e. a
partition is created which is equal to the size of the job and is allocated to the job.
If there are many free partitions on the system but they are not allocated to jobs as the size of
the partition is less than the size of the job then that memory space goes waste. This fragment
or block of memory which cannot be allocated to any job because its size is less than the size
of the job goes waste and this is known as External Fragmentation, which is the major
drawback of Dynamic Partition Scheme.
Back
In case of fixed and dynamic partition the memory manager part of OS needs to keep list of
busy/free memory locations. This list is checked whenever a new job comes into the system.
Empty locations are allocated based on:
First Fit
Best Fit
First Fit: In this allocation scheme the memory manager maintains the list of busy/free
partitions. When a job is to be loaded , the first free partition which fits the requirement is used
for loading this job. Advantage here is that allocation is done fast.
Best Fit: In this allocation scheme the memory manager maintains the list of busy/free
partitions in order of size (eg. Smallest to largest). When a job is to be loaded , the partition
whose size closely matches the size of the job (minimum or no wastage of memory) is used for
loading this job. Advantage here is there is no or minimum wastage of memory space.
First Fit
Best Fit
First Fit:
With four Jobs J1, J2, J3, J4…. Comparison between First Fit and Best Fit
First Fit Best Fit
Total Available 115 K 115 K
Total Used 40K 70K
Number of Jobs in memory
7/25/2024
3 L J College of Computer Applications
4
Internal fragmentation 75K 45K
Practice Examples 1
1. Job List
J1 40K
J2 30K
J3 20K
J4 35K
1. Job List
J1 30K
J2 40K
J3 50K
Practice Example 4
1. Job List
J1 40K
J2 50K
J3 60K
Solve 7/25/2024
using First Fit and Best Fit L J College of Computer Applications
DEALLOCATION OF MEMORY
Deallocation of Memory takes place when the job has finished execution and releases memory.
J2
Free partition
Free partition
3. when the block to be deallocated is isolated
for eg: J3 is releasing memory J2
J4
7/25/2024 J3
L J College of Computer Applications
Assume that the memory locations are numbered lowest to highest in the memory addressing
scheme.
1. Joining Two free blocks: when the block to be dealloacted is near another free block
J2
Free partition
Free Block
Here a block with starting address
Block to be deallocated 7580 and of size 20 has to be
deallocated. It is sandwiched by
Free Block
two free blocks at location 7560
of size 20 and another at location
7600 of size 205. When the block
at 7580 is deallocated the block
above and below it gets
combined to form one big free
block of size 245 (20+20+205).
Busy
Busy Blocks
Blocks The block whose starting address is 8805
is the block which has to be deallocated.
This block is isolated i.e, it does not have
any free block adjacent to it.
usy
7/25/2024 L J CollegeUll
of entry
Computer Applications
usy
RELOCATABLE DYNAMIC PARTITION dp Back Main
The major disadvantage of Dynamic Partition scheme is External Fragmentation. The small
blocks of memory cannot be given to any job as the size of fragment is smaller than the size
of the Job. Such blocks of memory are scattered and go waste.
10K
Job 1 Job 1
15K
External Job 4
Job 4 fragmentation
(unused space)
10K
Job 6
Job 6 Job 5
A job of size 20K cannot be loaded All empty blocks collected to create one large
block of free space which can now accommodate
a Job of size 20
This is known as COMPACTION or GARBAGE COLLECTION or DEFRAGMENTATION . This is
performed
7/25/2024 by the OS to remove small chunks
L J College of waste
of Computer memory.
Applications
COMPACTION or GARBAGE COLLECTION or DEFRAGMENTATION results in shifting the
location of programs in the memory which means they are relocated.
Memory Address Before Compaction Memory Address After Compaction
J1 60 50
J4 115 90
J6 225 190
10K
Job 1 Job 1
15K
Job 4
Job 4
10K Job 6
Job 6 Job 5
J1
J1 90
91
115 190
200
J4
116
J4 215 400 J3
400
401
J3 .
600
Similarly J3 before compaction was from 400 to 600. After compaction it is relocated and is
stored from 200 to 400
The program on Line 400 shifts to 200 (shift by 200 lines)
401 shifts to 201 (shift by 200 lines)
7/25/2024 600 shifts to 400 (shift
L J College by 200Applications
of Computer lines)
So we see that each program moves by a specific number of address locations
For a program J1 all its instructions shift 25 lines up
For a program J3 all its instructions shift 200 lines up
So, The memory manager part of the OS keeps a register for each Job which stores the number
of locations (up or down) it has been shifted or relocated after compaction. This register is
called the RELOCATION REGISTER.
So for a Job J1 value of Relocation Register is -25 (minus because instructions shift up)
for Job J3 value of Relocation Register is -200.
Simmilarly for J3
Old address location+ Value of relocation register = New address location
Eg. First instruction : 400 + (-200) = 200
Second Instruction : 401 + (-200) = 201 and so on
….. Last Instruction : 600 + (-200) = 400
7/25/2024 L J College of Computer Applications
A RELOCATION REGISTER can have a value positive , negative or Zero
If the Job has moved up after relocation (towards lower address i.e., 400 to 350 ) the
relocation register will hold a negative value
If the Job has moved down after relocation (towards higher address i.e., 400 to 750 ) the
relocation register will hold a positive value
If the Job does not move on compaction value of the relocation register will be 0 (Zero).
BOUNDS REGISTER
Another register used by the operating system is the Bounds register. This register contains a
the highest address value that can be accessed by a program during execution. Suppose a
program stores a value 375 in the Bounds register , during execution if the program has any
instruction like GO TO address value ,
For eg: GO TO 296 is a valid instruction as it is less than the value of the bound register 375
GO TO 435 is out of bounds.
7/25/2024 L J College of Computer Applications
MEMORY MANAGEMENT >>>>>>>>>>>>>RECENT SYSTEMS MM
sectors J1 (page 1) PF 1
. J1 (page 2) PF 5
. J2 (page 1) PF 6
7/25/2024 . L J College of Computer Applications PF 7
The Program divided into Pages Page Frames of RAM
are held by sectors of Secondary Memory is loaded onto
THE PAGES AND THE PAGE FRAMES ARE OF THE SAME SIZE
The diagram below shows that Job 1 (J1) is divided into 3 pages, J2 is divided into two
pages and so on. These jobs when loaded on the RAM are entirely stored on the RAM
but not at continuous locations.
sectors J1 (page 1) PF 1
. J1 (page 2) PF 5
. J2 (page 1) PF 6
7/25/2024 . L J College of Computer Applications PF 7
All the pages and page frames are of the same size.
Here the RAM has 11 page
frames for user programs.
Page frame 0 and 1 are
system area.
1. JOB TABLE: It contains two entries, size of Job and address of its Page map table
Every row of the Job table stores the details of the Jobs active on the same. So number of
entries in this table indicate number of active jobs on the system.
The size of the table increases and decreases as and when the Jobs come and leave the system
Number of entries (number of rows) in a MMT depends upon the number of Page Frames in the
system
Displacement or Offset
This is a value which shows
how far a line is from the
beginning of a page.
Page Number
Size of the page Line number to be located
xxxx
xxxx
xxxx
Displacement
Role of the three tables:
When a Job enters the system the following happens in Paged memory allocation
A Page Map table for that job is created
An entry of the Job and address of its PMT is made in the Job Table
The memory map table is searched to find the free page frames and the pages are
loaded onto the free page frames
The entry of on which page frame a page is loaded is made in the PMT (Page Map Table)
The next step is that the Job table is searched to find the address of the PMT.
Now the PMT is checked to see in which Page frame is page number 2
The PMT looks like
Page Number Page Frame number
0 8
1 10
2 5
3 11
From the above PMT it is found that page number 2 is at Page Frame 5
PF 1 J2 Page 0 PF 1
J1 Page 0 PF 2 J1 Page 0 PF 2
J1 Page 2 PF 3 PF 3
PF 4 J5 Page 0 PF 4
J1 Page 1 PF 5 J3Page 0 PF 5
PF 6 J4 Page 0 PF 6
J1 Page 3 PF 7 PF 7
Here only J1 gets loaded All the Jobs get loaded with 1 page
J2, J3 has to wait, 3 page frames are still free
J4, J5 will not ever get loaded
7/25/2024 L J College of Computer Applications
How does Demand Paging work?
Initially no pages of any program are loaded.
When a program is to be executed only 1 page is loaded from secondary memory to RAM
Remaining pages are loaded as and when required. Secondary Memory
Random Access Memory (Hard Disk)
(RAM) Page Frames
PF 0
J3 Page 0 PF 1
PF 2 Pages
J1 Page 0 PF 3
J5 Page 0 PF 4
J1 P0 P1 P2 P3 P4 P5
PF 5
J2 P0 P1 P2
J4 Page 0 PF 6
Jobs J3 P0 P1 P2 P3
PF 7
PF 8
J4 P0 P1 P2 P3 P4
J2 Page 0 PF 9
J5 P0 P1
J6 Page 0 PF 10 J6 P0 P1 P2 P3 P4 P5 P6
PF 11
7/25/2024 L J College of Computer Applications
After some time the Jobs might demand for few more pages. When the demand
comes, more pages are loaded for that Job.
J6 Page 2 PF 0
J3 Page 0 PF 1
PF 2 Pages
J1 Page 0 PF 3
J5 Page 0 PF 4
J1 P0 P1 P2 P3 P4 P5
PF 5
J2 P0 P1 P2
J4 Page 0 PF 6
Jobs J3 P0 P1 P2 P3
J1 Page 4 PF 7
J3 Page 2 PF 8
J4 P0 P1 P2 P3 P4
J2 Page 0 PF 9
J5 P0 P1
J6 Page 0 PF 10 J6 P0 P1 P2 P3 P4 P5 P6
J4 Page 1 PF 11
7/25/2024 L J College of Computer Applications
Suppose the page and page frames are of size 100 lines each
J1 (size 360) has 4 pages,
J3 (size 840) has 8 pages,
J4 (size 1210) has 12 pages
J5 (size 1150) has 10 pages
J2(size 530) has 5 pages
Total number of pages for all jobs is 39 pages , which means 3900 lines of memory required.
Number of page frames are 8 i.e., 800 lines Demand Paging
Still the RAM can accommodate all Jobs. PF 0
And We feel that programs using 3900 lines are working J1 Page 0
PF 2
on the system.
PF 3
2. PAGE MAP TABLE : Every Job has its own Page Map Table, which contains the details of a
page like : Page no., Page Frame No., Presence/Absence bit, Referenced bit, Modified bit
Page Number Page Frame number Presence status Referenced bit Modified bit
0 7 1 1 0
1 4 0 1 1
2 3 1 1 1
Pages
Jobs
There are various criteria to decide which page has to be swapped out to free a page frame.
Suppose it is decided by OS to swap out Page 2 of Job 3 (present in Page frame 11)
The PMT of Job 4 is changed to show that Page 3 is loaded on RAM at page frame 11
The7/25/2024
PMT of Job 3 also changes to show that Page 2 in not present. And the Page frame 11 of
L J College of Computer Applications
RAM shows the that Page 3 of Job 4 has been loaded.
Whenever a page fault occurs, the page fault handler does the following :
The MMT is checked to see which page frame is free to swap in the required page.
If a page free is free the required page is swapped in. If page frame is not free it is checked to
see which page of a job can be removed to free a page frame, and then that page is swapped
out.
The PMT of the table whose page has been swapped in : PMT of Job 4 is changed to show
that Page 3 is loaded on RAM at page frame 11
The PMT of the table whose page has been swapped out: PMT of Job 3 changes to show
that Page 2 in not present.
The MMT is also changed to update whether the page frames are busy or free.
The Page fault handler does this job of swapping : Bringing in a page (Swap In) and Removing a
page (Swap Out) from the RAM.
If Page faults occur very frequently
resulting in very frequent swap in and
swap out of pages, it is known as
THRASHING.
Page
Frame
1
A A A C C B B B A A D
Page
Frame
2
EMPTY
B B B A A D D D C C
Page
Frame
1
A A A C C B B B A A D
Page
Frame
2
EMPTY
B B B A A D D D C C
Interrupt 1st 2nd No 3rd 4th 5th 6th No 7th 8th 9th
7/25/2024 L J College of Computer Applications
LEAST RECENTLY USED: Job with 4 pages and 2 page frames
Total number of page requests = 11 ( A, B, A, C, A, B, D, B, A, C, D)
Total number of interrupts = 9
Failure Rate = Total Interrupts 100 = 8 100 = 73%
(in percent) Total number of requests 11
A A A A A A D D A A D
Page
Frame
2
empty B B C C B B B B C C
Interrupt 1st 2nd NO 3rd NO 4th 5th NO 6th 7th 8th
7/25/2024 L J College of Computer Applications
Consider a Job with 4 pages (Page A, Page B, Page C, Page D) B is removed as it is
There are only 3 page frames on the RAM older than C
The requests or demand for pages come in this order:
A, B, A, C, A, B, D, B, A, C, D A is removed as it is
oldest page
FIFO method
A A A A A A D D D D D
empty
PF 2
B B B B B B B A A A
empty
PF 3 PF 3 PF 3
C C C C C C C C
empty empty empty
A A A A A A A A A A A
empty
PF 2
B B B B B B B B B D
empty
PF 3 PF 3 PF 3
C C C D D D C C
empty empty empty
D D D D D D D D D D D E
PF 2
C C C C C C C C C C C
empty
PF 3 PF 3
B B B B E E E E A A
empty empty
PF 4 PF 4 PF 4
A A A A A A B B B
empty empty empty
The Status bit indicates whether the Page is there on Ram or not. A 1 in this bit
indicates that all the pages are present in the page frames of the memory
The Referenced bit indicates whether the page has been called or referred for either a
read or write operation. The LRU algorithm uses this bit to choose a page to swap out
at time of a page fault. Usually a page where referenced bit is 0 is swapped out as it
has not been called or referred.
The Modified bit indicates whether the contents of the page have been modified
after they were loaded from hard disk to RAM.
7/25/2024 L J College of Computer Applications
If modified bit is 0 , the page need not be written back to the hard disk at the time of swap out
as the copy of it is already there on the hard disk and it is same as the one present on RAM (as it
was not modified). ex
If modified bit is 1, it means that the page has been modified on the RAM after it was swapped
in from the secondary memory. So the contents of the RAM and secondary memory are not
same. In this case if this page is chosen to be swapped from the RAM then it has to be rewritten
on the Secondary memory to update the changes. This is a time taking process.
For all the pages present in the page frames of RAM the status bit will be 1 showing their
presence on the RAM
In FIFO policy the modified bit and status bits are checked
The LRU policy checks all the three bits. It first checks the referenced bit as it swaps the page
which is least recently used and selects pages with Referenced bit 0
The first choice will be Case 1 : A page on RAM which is not modified and not referred.
Second choice will be Case 3 : A page not referenced but modified. (Not logically possible but
(as referenced bit is 0) this case exists)
Third choice will be Case 2 : As this page is referred but not modified , less time will be taken to
swap it out.
Last choice will be Case 4 : As it has been referred and modify, so it is the most active page.
Page no. Status Bit Referenced bit Modified Bit Page Frame No.
0 1 1 1 5
1 1 1 0 3
2 1 1 0 7
3 1 1 0 2
Under this situation the LRU policy will fail as it first picks up those pages where referenced bit is
0.
Page no. Status Bit Referenced bit Modified Bit Page Frame No.
0 1 0 1 5
1 1 0 0 3
2 1 0 0 7
3 1 0 0 2
Page no. Status Bit Referenced bit Modified Bit Page Frame No.
0 1 1 1 5
1 1 0 0 3
2 1 1 0 7
3 1 1 0 2
7/25/2024 L J College of Computer Applications
WORKING SET
A Working set is the set of pages in the RAM which can be executed without any page faults
occurring.
Initially when a program starts execution there are certain number of page faults to bring in
the required pages. After some time the execution stabilizes and the processing goes on
smoothly without any page fault. At this time the instructions present in one or multiple
pages form a working set.
If a set of instructions within this working set are referred to again and again, the reference
becomes localized to a particular area . This is known as LOCALITY OF REFERENCE.
PF 1
PF 2 P2
PF 3
Working set
PF 4 P3
.
.
.
.
. P1
A loop structure here is repeatedly executed many times …
.
. 7/25/2024 this is locality of reference
L J College of Computer Applications
Segmented Memory Allocation
In segmented Memory Allocation depending on the structure of the Job each Job is
divided into many parts called Segments. All these segments are of different size
For example a procedure or a function of a program can be one segment.
When these segments are loaded on the RAM, at that point of time depending on
the size of the segment, a portion of the RAM which is of the same size of the
segment is dynamically allocated to the segment. (As was the case in Dynamic
memory Allocation).
Not all the segments of a program are required to be stored on the RAM and neither
at continuous locations
Job 1 (secondary memory) RAM Other programs
0
Segment 0 Segment 0
(main)
399
0 Segment 1
Function 1 Other programs
99
0
Segment 1
Segment 2
Function 2
7/25/2024 L J College of Computer Applications Other programs
199
Every Job has a segment map table which is same as the page map table in demand paging with
additional fields like size of segment and access rights.
The entries are made in the Segment Map table as:
To locate a particular line the address should contain the segment number and displacement
Address (Segment number, displacement/offset)
For eg : (1, 35)
Now the Segment Map table will be searched
to find the beginning address of Segment 1 on
RAM
We get 7000
Actual address = beginning address + offset
= 7000+35
= 7035
Eg: ( 0, 1, 40)
First the address to the SMT is located for the Job which is in process, then for segment number
0 the address of the PMT is identified, after the PMT is located the page frame number for page
number 1 is located, which is 4 . Then in page frame 4, from the starting address the instruction
7/25/2024 L J College of Computer Applications
40 locations beyond the starting of page frame 4 is read.