Module4 Os
Module4 Os
NOTE:
1. All the pages of process must be loaded in Main memory. pages can be placed in any frames, It is not necessary to
be inorder
2.The last page of process may leads small internal fragmentation
Contiguous memory Vs Non Contiguous
memory
1.We cant store the starting
address of each page in relocation
register. Since it is costly
2. We need to maintain one table
which contains page details.
Where each pages stored
• If the page number is found, then its frame number is immediately available and is used in order to access
the memory. The above whole task may take less than 10 percent longer than would if an unmapped memory
reference were used.
• In case if the page number is not in the TLB (which is known as TLB miss), then a memory reference to the
Page table must be made.
• When the frame number is obtained it can be used to access the memory. Additionally, page number and
frame number is added to the TLB so that they will be found quickly on the next reference.
• In case if the TLB is already full of entries then the Operating system must select one for replacement.
Advantages of Paging
• Paging mainly allows to storage of parts of a single process in a non-
contiguous fashion.
• With the help of Paging, the problem of external fragmentation is
solved.
• Paging is one of the simplest algorithms for memory management.
Disadvantages of Paging
• In Paging, sometimes the page table consumes more memory.
• Internal fragmentation is caused by this technique.
• There is an increase in time taken to fetch the instruction since now
two memory accesses are required.
Segmentation
• A process is divided into Segments. The chunks that a program is
divided into which are not necessarily all of the exact sizes are called
segments.
• Segmentation gives the user’s view of the process which paging does
not provide. Here the user’s view is mapped to physical memory.
• Segmentation divides processes into smaller subparts known
as modules. The divided segments need not be placed in contiguous
memory. Since there is no contiguous memory allocation, internal
fragmentation does not take place.
• The length of the segments of the program and memory is decided by
the purpose of the segment in the user program.
• Types of Segmentation
Segmentation can be divided into two types:
• Virtual Memory Segmentation: Virtual Memory Segmentation
divides the processes into n number of segments. All the segments
are not divided at a time. Virtual Memory Segmentation may or may
not take place at the run time of a program.
• Simple Segmentation: Simple Segmentation also divides the
processes into n number of segments but the segmentation is done
all together at once. Simple segmentation takes place at the run time
of a program. Simple segmentation may scatter the segments into the
memory such that one segment of the process can be at a different
location than the other(in a noncontinuous manner).
Why Segmentation is required?
• Segmentation came into existence because of the problems in the
paging technique.
• In the case of the paging technique, a function or piece of code is
divided into pages without considering that the relative parts of code
can also get divided.
• Hence, for the process in execution, the CPU must load more than
one page into the frames so that the complete related code is there
for execution.
• Paging took more pages for a process to be loaded into the main
memory. Hence, segmentation was introduced in which the code is
divided into modules so that related code can be combined in one
single block.
Example of Segmentation
• Let us assume we have five segments namely: Segment-0, Segment-1,
Segment-2, Segment-3, and Segment-4. Initially, before the execution
of the process, all the segments of the process are stored in the
physical memory space. We have a segment table as well. The
segment table contains the beginning entry address of each segment
(denoted by base). The segment table also contains the length of
each of the segments (denoted by limit).
• As shown in the image , the base address of Segment-0 is 1400 and
its length is 1000, the base address of Segment-1 is 6300 and its
length is 400, the base address of Segment-2 is 4300 and its length
is 400, and so on.
Advantages of Segmentation
• No internal fragmentation
• Average Segment Size is larger than the actual page size.
• Less overhead
• It is easier to relocate segments than entire address space.
• The segment table is of lesser size as compared to the page table in
paging
Disadvantages
• It can have external fragmentation.
• it is difficult to allocate contiguous memory to variable sized partition.
• Costly memory management algorithms.
Virtual Memory: Demand Paging
The demand paging system is somehow similar to the paging system with swapping where processes
mainly reside in the main memory(usually in the hard disk). Thus demand paging is the process that
solves the paging problems only by swapping the pages on Demand. This is also known as lazy
swapper( It never swaps the page into the memory unless it is needed).
Valid-Invalid Bit
• Some form of hardware support is used to distinguish between the
pages that are in the memory and the pages that are on the disk.
• With each page table entry, a valid-invalid bit is associated
where 1 indicates in the memory and 0 indicates not in the memory)
• Initially, the valid-invalid bit is set to 0 for all table entries.
For instance, in a system with 62 frames, if there is a process of 10KB and another process of
127KB, then the first process will be allocated (10/137)*62 = 4 frames and the other process will get
(127/137)*62 = 57 frames.
Global vs Local Allocation
Thrashing
• A process that is spending more time paging than executing is said to
be thrashing.
• In other words, it means, that the process doesn't have enough
frames to hold all the pages for its execution, so it is swapping pages
in and out very frequently to keep executing. Sometimes, the pages
which will be required in the near future have to be swapped out.
• Initially, when the CPU utilization is low, the process scheduling
mechanism, to increase the level of multiprogramming loads multiple
processes into the memory at the same time, allocating a limited
amount of frames to each process.
• As the memory fills up, the process starts to spend a lot of time for
the required pages to be swapped in, again leading to low CPU
utilization because most of the processes are waiting for pages.
Hence the scheduler loads more processes to increase CPU utilization,
as this continues at a point of time the complete system comes to a
stop.
• This phenomenon is illustrated in
figure in which CPU utilization is
plotted against degree of
multiprogramming.
• As degree of multiprogramming
increases, CPU utilization goes on
increasing although more slowly
until a maximum is reached.
• After this point of degree of
multiprogramming is increased then
thrashing is occurred and CPU
utilization drops sharply after this
point.
• At this point, to increase CPU
utilization and stop thrashing degree
of multiprogramming should be
reduced.
• To prevent from thrashing a strategy called as page-fault frequency
(PFF) is used. Since thrashing has a high rate of page fault. So we can
control the page-fault rate. When it is too high, we know that the
process needs more frames. Similarly if the page fault rate is too low,
then the process has too many frames.
• We can establish upper and lower bounds on the desired page fault
rate (Figure 6). If the actual page fault rate exceeds the upper limit,
we allocate that process to another frame.
• If the page fault rate falls below the lower limit, we remove a frame
from that process. Thus we can directly measure and control the page
fault rate to prevent thrashing