Bca 4 Chapter 3 Os
Bca 4 Chapter 3 Os
Bca 4 Chapter 3 Os
Operating System
Multi-partition Allocation:
In a multiprogramming environment several program
reside in primary memory at a time and the CPU passes its
control rapidly between these programs. Here the memory can
be divided into a number of separate fixed areas, each of which
can hold one process. When a program terminates, that
partition is free for another program waiting in a queue. The
main disadvantage of this allocation is an internal
fragmentation. There are two types of memory Partition.
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
3. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
[a]. Fixed/Static Partition
[b]. Variable/Dynamic Partition
Operating System
P1
P2
P3
Free
Operating System
FREE 200K
P1 200K
P2 200K
FREE
200K
P3 200K
Once the partitions are defined, operating system keeps track of the status of each
block (free or allocated) using a data structure called the Partition Description Table (PDT), as
shown below
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
4. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
• Advantage:
o Simple and easy to implement.
o Less additional hardware required.
o Algorithm used is not very complicated.
• Disadvantages:
o Internal fragmentation of memory (memory
wastage inside the blocks).
o Degree of multiprogramming depends on the
number of partition.
0 0 0
SUPERVISOR SUPERVISOR SUPERVISOR
40K 40K 40K Process4 (FREE 50K)
Process1 FREE (200K)
240K 240K 240K
490K Process2 490K Process2 Process2
490K
590K Process3 590K Process3 Process3
590K
640K FREE (50K) 640K FREE (50K) 640K FREE (50K)
0 0
SUPERVISOR SUPERVISOR
40K 40K
Process4 Process4
FREE (300K) Process5
Process3
FREE (150K)
640K FREE (50K) 640K
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
5. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
Assume that we have 640K main memory available in which 40K is occupied by operating system
program. There are three jobs waiting for memory allocation in a job queue. Applying FCFS scheduling
policy, Process1, Process2 and Process3 can be immediately allocated in memory. Process 4 cannot be
allocated in memory because there is only 600-500 = 50K left for it. Let's assume that after some time
Process1 is terminated, now releasing 200K memory space. After than the control is returned to the process
queue and next Process4 is swapped - in the memory. After than Process2 going to terminated and release
250K free memory areas. 250K included with 50K internal fragmentation. Process5 be put up in released
300K external fragmentations. After the swapping out of Process3 due to termination, at last 100K of
external fragmentation merged and it will be distributed for next processes....
Memory Fragmentation :-
Fragmentation means an unusual space in memory areas or in
another word, presence of unusable memory areas in a
computer system. There two types of fragmentation arise in
system memory area...
Internal Fragmentation:
Internal fragmentation means unused internal area of program
in memory. It arises when memory allocated to a program is
not fully utilized by it.
SUPERVISOR
Program1
Internal Fragmentation
Free
Program2
Program3
Internal Fragmentation:
After sharing memory for programs, if some part of memory
can go free, called it External fragmentation. It arises when free
memory areas existing in a system are too small to be allocated
to programs. Example of external fragmentation like...
SUPERVISOR
Program1
Program2
External Fragmentation
Free
Program3
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
6. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
Merging Free Areas OR Memory / Storage Compaction
In this approach memory allocation are changed such that all
free areas can be combined into a single free area called the
merged free area. This is done by combined into a single free
area called the merged free area. This is done by allocating
alternative memory areas to programs and data existing in the
allocated areas of memory. All fresh allocations are made from
the merged free area. In another word, an Operating system
may attempt to combine all free areas into a single free area, or
to combine some adjoining free areas into a free area of larger
size.
0K 0K
SUPERVISOR SUPERVISOR
40K 40K
Process1 Process1
(200K) (200K)
240K 240K
FREE 30K Process2
270K
Process2 (100K)
340K
(100K)
370K After Compaction Process3
FREE 20K (70K)
390K
Process3 410K FREE 50K
(70K)
460K 460K
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
7. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
SUPERVISOR
Program1
Program2
Program6
FREE 100K
Program3 First-Fit
........ 150K
FREE 300K
Best-Fit
READY QUEUE Program4
FREE 200K
Worst-Fit
FREE 400K
INTRODUCTION:
At any given time, we have a list of available block sizes and the ready
queue. Operating system can order the ready queue according to some
scheduling algorithm. Generally, a set of free partition areas of various
sizes is scattered throughout the memory at any given time. When a
process terminates, it releases its block of memory, which is that
placed back in the set of free partition area. If the new free partition
area to other merged from one larger free partition area. The system
can used dynamic storage allocation method, First Fit, Best Fit, Worst
Fit for allocating memory but this algorithm suffer from external
fragmentation. As process from memory the free memory space is
broken into little pieces.
Page
0
Frame
Page 0 Page 0
0 1 1
Page 1 1 1
2
2 1 Page 2
Page 2 3
3 1
Page 1
Page 3
Page Table 4
5
Logical memory
Page 3
6
Physical memory
P1 P2 d
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
9. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
Page
0 a 0 0
Frame
1 b
0 i
2 c 4 j 1
3 d
0 5 k
4 e l
1 6
5 f
1 2 1 m
6 g 8
3 2 n
7 h
o 2
8 i Page Table 12
p
9 j 16
2
10 k 3
11 l
20 4
12 m
a
13 n
3 b
14 o
24 c
15 p 5
d
Logical memory e
f
g 6
h
Physical memory
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
10. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
0
1
1 .
.
.
.
100
500
.
.
100
. 500
.
.
.
. 708 .
929 708
.
Outer Page Table .
.
.
900 900
.
.
929
.
.
Page of Page Table
Memory
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
11. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
Stack 1400
Subroutine Segment 0
Segment 3 2400
Segment 0
Program 1 3200 Segment 3
SQRT 4300
Segment 4 4700 Segment 2
Segment 1 Segment 4
Main Program 5700
Segment 2 6300
Segment 1
6700
SEGMENT TABLE
Limit Base
0
1000 1400
1 400 6300
2 400 4300
3 1100 3200
4 1000 4700
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
12. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
When a memory reference occurs following algorithm is carry
out.
- The segment number is used to find the segment description
- A check is made to see if the segment page table is in
memory. If the page table is in memory, it is located. If is
not, a segment fault occurs. If there is a protection
violation, a trap occurs.
- The page table entry for the requested virtual page is used.
If it is in memory, the main memory address of the start of
the page is extracted from page table entry.
- The offset is added to page origin to give the main memory
address where the word is located.
- The read or store finally takes place.
Page Fault :
A field in the PMT (Page Map Table) entry of page Pi indicates
whether the page currently exits in memory. If Pi does not exit in
memory when reference ALU declares a missing page interrupt
also called a PAGE FAULT.
Pi Wi
15 479
MR BLOCK OTHER
NO INFO
Add 15 479 # ??
Physical Memory
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli
13. Operating Systems Concepts With Unix / Linux UNIT NO - 3
________________________________________________________________________________________________________
Operating System
Page Fault
Memory Reference to a Page
Secondary
CPU PMT Memory
Load Pi Physical Memory
Missing
Restart Instruction
Page is
FREE
Update brought
PMT Free memory location
Demand Paging :
All pages of program can be loaded in memory before the program
is initiated. This is called Pre- Loading of Paging. In demand
paging, pages are loaded only on demand not in advanced. It is
similar to paging system with swapping futures. Rather than
swapping the entire program in memory, only those pages are
swapped which are required currently by the system.
` Operating System
Page Fault
Memory Reference to a Page
Secondary
CPU PMT Memory
Load Pi Physical Memory
________________________________________________________________________________________________________
Kamani Science College (Computer Department), Amreli