OS Unit4 Goswami
OS Unit4 Goswami
Dynamic Loading
Dynamic Linking
Virtual and physical addresses are the same in compile-time and load-time
address-binding schemes. Virtual and physical addresses differ in
execution-time address-binding scheme.
Swapping
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. It must be capable of providing direct access
to these memory images.
Major time consuming part of swapping is transfer time. Total transfer time
is directly proportional to the amount of memory swapped. Let us assume
that the user process is of size 100KB and the backing store is a standard
hard disk with transfer rate of 1 MB per second. The actual transfer of the
100K process to or from memory will take
= 1/10 second
= 100 milliseconds
The main memory is a combination of two main portions- one for the
reserved for operating system (Kernel) and other for the user program.
The partition of the second portion i.e. user space is performed to
implement/achieve contiguous or non-contiguous memory allocation by
dividing the memory partitions into fixed size partitions or variable size
partitions for multiprogramming.
1. Uniprogramming – no partition of user space (single partition)
2. Multiprogramming
a. Contiguous
i. Fixed size partition
ii. Variable or dynamic partition
b. Non – Contiguous
i. Paging (fixed size)
ii. Segmenting (variable size)
This is the oldest and simplest technique that allows more than one
processes to be loaded into main memory. In this partitioning method
the number of partitions (non-overlapping) in RAM are all a fixed size, but
they may or may not be same size. This method of partitioning provides
for contiguous allocation. The partition sizes are made before execution or
during system configuration.
As illustrated in the given figure, let all the fixed size partitions are 4MB.
The first process is only consuming 1MB out of 4MB in the main memory.
Hence, Internal Fragmentation in first block is (4-1) = 3MB. The sum of
Internal Fragmentation in every block = (4-1)+(8-7)+(8-7)+(16-14)=
3+1+1+2 = 7MB. Suppose process P5 of size 7MB comes. But this process
cannot be accommodated inspite of available free space because of
contiguous allocation (as spanning is not allowed). Hence, 7MB becomes
part of External Fragmentation.
Advantages
Disadvantages
Advantages–
No Internal Fragmentation- In variable Partitioning, space in main
memory is allocated strictly according to the need of process.
Disadvantages–
Difficult Implementation- Implementing variable Partitioning is difficult
as it involves allocation of memory during run-time rather than during
system configure.
External Fragmentation- There will be external fragmentation. For
example, suppose in above example- process P1(2MB) and process
P3(1MB) completed their execution. Hence two spaces are left i.e. 2MB
and 1MB. Let’s suppose process P5 of size 3MB comes. The empty
space in memory cannot be allocated as no spanning is allowed in
contiguous allocation. The rule says that process must be contiguously
present in main memory to get executed. Hence it results in External
Fragmentation. Now P5 of size 3 MB cannot be accommodated in spite
of required available space because in contiguous no spanning is
allowed.
As processes are loaded and removed from memory, the free memory
space is broken into little pieces. It happens after sometimes that
processes can not be allocated to memory blocks considering their small
size and memory blocks remains unused. This problem is known as
Fragmentation. Fragmentation is of two types
Placement Algorithms
First fit - First Fit algorithm scans the linked list and whenever it finds the
first big enough hole to store a process, it stops scanning and load the
process into that hole. This procedure produces two partitions. Out of them,
one partition will be a hole while the other partition will store the process.
Advantage
Fastest algorithm, because it searches as little as possible.
The Best Fit algorithm tries to find out the smallest hole possible in the list
that can accommodate the size requirement of the process.
Advantage
Memory utilization is much better than first fit as it searches the smallest
free partition first available.
Disadvantage
Although best fit minimizes the wastage space, it consumes a lot of
processor time for searching the block which is closer to the required size.
Also, Best-fit may perform poorer than other algorithms in some cases.
Worst fit - The worst fit algorithm scans the entire list every time and tries
to find out the biggest hole in the list which can fulfill the requirement of the
process.
Advantage
It reduces, the rate of production of small gaps.
Disadvantage
If a process requiring larger memory arrives at a later stage then it cannot
be accommodated as the largest hole is already split and occupied.
Next fit – Next fit is a modified version of first fit. It begins as first fit to find
a free partition. When called next time it starts searching from where it left
off, not from the beginning.
Next fit doesn't scan the whole list, it starts scanning the list from the next
node. The idea behind the next fit is the fact that the list has been scanned
once therefore the probability of finding the hole is larger in the remaining
part of the list.
12 UNIT-4 (MEMORY MANAGEMENT) BY Sanjay Goswmami, UCER
Experiments over the algorithm have shown that the next fit is not better
then the first fit. So it is not being used these days in most of the cases.
Example: Given memory partitions of 100k, 500k, 200k, 300k, and 600k
(in order). How would each of first fit, best fit, worst fit algorithms place
processes of 212k, 417k, 112k, and 426k (in order)? Which algorithm
makes the most efficient use of memory?
First Fit
212k is put in 500k partition.
417k is put in 600k partition.
112k is put in 288k partition. (new partition 500k – 212k = 288k)
426 must wait.
Best Fit
212k is put in 300k partition.
417k is put in 500k partition.
112k is put in 200k partition.
426k is put in 600k partition.
Worst Fit
212k is put in 600k partition.
417k is put in 500k partition.
112k is put in 388k partition. (new partition 600k – 212k = 388k)
426 must wait.
In this example, best fit is most efficient to utilized space than other, so it
is best.
Paging
= (1-p)*200+p*8000000
= 200+p*7999800
Segmentation
Virtual memory
Virtual memory provides a illusion to the user that they have large main
memory available instead of actually small main memory. It is a technique
that allows the execution of processes which are not completely available
in memory. The main 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.
Advantages
Disadvantages
p = 256pages (28) = 8
d=210 =10
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.
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.
If No. of frames=4
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Logical address: 0, 99
= 330 + 99 = 429
= 111 + 78 = 189
Pure segmentation is not very popular and not being used in many of the
operating systems. However, Segmentation can be combined with
Paging to get the best features out of both the techniques.
Each Page table contains the various information about every page of the
segment. The Segment Table contains the information about every
segment. Each segment table entry points to a page table entry and every
page table entry is mapped to one of the page within a segment.
In virtual address? 32 (3 + 21 + 8)
The CPU generates a logical address which is divided into two parts:
Segment Number and Segment Offset. The Segment Offset must be less
than the segment limit. Offset is further divided into Page number and Page
Offset. To map the exact page number in the page table, the page number
is added into the page table base.
The actual frame number with the page offset is mapped to the main
memory to get the desired word in the page of the certain segment of the
process.
Disadvantages
There might be a case where the page table is too big to fit in a
contiguous space, so we may have a hierarchy with several levels.
In this type of Paging the logical address space is broke up into
Multiple page tables.
Consider a system having 32-bit logical address space and a page size of
1 KB and it is further divided into:
As we page the Page table, the page number is further divided into:
30 UNIT-4 (MEMORY MANAGEMENT) BY Sanjay Goswmami, UCER
Page Number consisting of 12 bits.
Page Offset consisting of 10 bits.
P2 indicates the displacement within the page of the Inner page Table.
Below given figure below shows the Address Translation scheme for a two-
level page table
For a system with 64-bit logical address space, a two-level paging scheme
is not appropriate. Let us suppose that the page size, in this case, is 4KB.If
in this case, we will use the two-page level scheme then the addresses will
look like this:
This approach is used to handle address spaces that are larger than 32
bits.
Given below figure shows the address translation scheme of the Hashed
Page Table:
The Virtual Page numbers are compared in this chain searching for a
match; if the match is found then the corresponding physical frame is
extracted.
These are similar to hashed tables but here each entry refers to
several pages (that is 16) rather than 1.
Mainly used for sparse address spaces where memory references
are non-contiguous and scattered
The Inverted Page table basically combines A page table and A frame table
into a single data structure.
There is one entry for each virtual page number and a real page of
memory
Given below figure shows the address translation scheme of the Inverted
Page Table: