Operating System MCA BPUT Unit-5
Operating System MCA BPUT Unit-5
1|Page
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Partitioned Allocation
It divides primary memory into various memory partitions,
which is mostly contiguous areas of memory. Every partition
store all the information for a specific task or job. This method
consists of allotting a partition to a job when it starts &
unallocated when it ends.
2|Page
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Dis-advantages :
1) A single job is assigned to all the memory so
large amount of memory may be wasted.
2) CPU time is wasted.
3) In this scheme the resources are not utilized in efficient
manner at the same time there is not enough
hardware flexibility to allow effective allocation of memory.
In the first two cases the job can be removed from the
memory. In the last two, the job is only temporarily
suspended, it is to be resumed. In each case the CPU is then
assign to the job with next highest priority.
Advantages :
3|Page
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Disadvantages :
4|Page
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
5|Page
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
while executing a
process.
5. Internal fragmentation External fragmentation
occurs in Contiguous occurs in Non-Contiguous
memory allocation memory allocation
method. method.
6. It includes single partition It includes paging and
allocation and multi- segmentation.
partition allocation.
7. Wastage of memory is No memory wastage is
there. there.
8. In contiguous memory In non-contiguous
allocation, swapped-in memory allocation,
processes are arranged in swapped-in processes can
the originally allocated be arranged in any place
space. in the memory.
6|Page
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
9|Page
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
What is Paging?
Paging is a storage mechanism that allows OS to retrieve
processes from the secondary storage into the main memory in
the form of pages. In the Paging method, the main memory is
divided into small fixed-size blocks of physical memory, which
is called frames. The size of a frame should be kept the same
as that of a page to have maximum utilization of the main
memory and to avoid external fragmentation. Paging is used
for faster access to data, and it is a logical concept.
Example
For example, if the main memory size is 16 KB and Frame size
is 1 KB. Here, the main memory will be divided into the
collection of 16 frames of 1 KB each.
10 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
In this example you can see that A2 and A4 are moved to the
waiting state after some time. Therefore, eight frames become
empty, and so other pages can be loaded in that empty blocks.
The process A5 of size 8 pages (8 KB) are waiting in the ready
queue.
11 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
In this example, you can see that there are eight non-contiguous
frames which is available in the memory, and paging offers the
flexibility of storing the process at the different places. This allows
us to load the pages of process A5 instead of A2 and A4.
Advantages of Paging
Here, are advantages of using Paging method:
Disadvantages of Paging
Here, are drawback/ cons of Paging:
12 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
13 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
14 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
15 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
What is Segmentation?
In Operating Systems, Segmentation is a memory
management technique in which, the memory is divided into
the variable size parts. Each part is known as segment which
can be allocated to a process.
16 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
1. Segment Number
2. Offset
Advantages of Segmentation
1. No internal fragmentation
2. Average Segment Size is larger than the actual page size.
3. Less overhead
17 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Disadvantages
1. It can have external fragmentation.
2. it is difficult to allocate contiguous memory to variable
sized partition.
3. Costly memory management algorithms.
Segmented Paging
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.
18 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
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.
19 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
21 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Paging VS Segmentation
Sr Paging Segmentation
No.
1 Non-Contiguous memory Non-contiguous memory
allocation allocation
2 Paging divides program Segmentation divides program
into fixed size pages. into variable size segments.
3 OS is responsible Compiler is responsible.
4 Paging is faster than Segmentation is slower than
segmentation paging
5 Paging is closer to Segmentation is closer to User
Operating System
6 It suffers from internal It suffers from external
fragmentation fragmentation
7 There is no external There is no external
fragmentation fragmentation
8 Logical address is divided Logical address is divided into
into page number and segment number and segment
page offset offset
9 Page table is used to Segment Table maintains the
maintain the page segment information
information.
10 Page table entry has the Segment table entry has the
frame number and some base address of the segment
flag bits to represent and some protection bits for
details about pages. the segments.
22 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Virtual Memory
A computer can address more memory than the amount physically
installed on the system. This extra memory is actually called virtual
memory and it is a section of a hard disk that's set up to emulate the
computer's RAM.
The main visible advantage of this scheme is that programs can be larger
than physical memory. Virtual memory serves two purposes. First, it
allows us to extend the use of physical memory by using disk. Second, it
allows us to have memory protection, because each virtual address is
translated to a physical address.
Following are the situations, when entire program is not required to be
loaded fully in main memory.
• User written error handling routines are used only when an error
occurred in the data or computation.
• Certain options and features of a program may be used rarely.
• Many tables are assigned a fixed amount of address space even
though only a small amount of the table is actually used.
• The ability to execute a program that is only partially in memory
would counter many benefits.
• Less number of I/O would be needed to load or swap each user
program into memory.
• A program would no longer be constrained by the amount of
physical memory that is available.
• Each user program could take less physical memory, more
programs could be run the same time, with a corresponding
increase in CPU utilization and throughput.
Modern microprocessors intended for general-purpose use, a memory
management unit, or MMU, is built into the hardware. The MMU's job is
to translate virtual addresses into physical addresses. A basic example
is given below −
23 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Demand Paging
A demand paging system is quite similar to a paging system with
swapping where processes reside in secondary memory and pages are
loaded only on demand, not in advance. When a context switch occurs,
the operating system does not copy any of the old program’s pages out
to the disk or any of the new program’s pages into the main memory
Instead, it just begins executing the new program after loading the first
page and fetches that program’s pages as they are referenced.
24 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Swapping:
Swapping a process out means removing all of its pages from memory,
or marking them so that they will be removed by the normal page
replacement process. Suspending a process ensures that it is not
runnable while it is swapped out. At some later time, the system swaps
back the process from the secondary storage to main memory. When a
process is busy swapping pages in and out then this situation is called
thrashing.
26 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Thrashing :
At any given time, only few pages of any process are in main memory
and therefore more processes can be maintained in memory.
Furthermore time is saved because unused pages are not swapped in
and out of memory. However, the OS must be clever about how it
manages this scheme. In the steady state practically, all of main
memory will be occupied with process’s pages, so that the processor
and OS has direct access to as many processes as possible. Thus
when the OS brings one page in, it must throw another out. If it throws
out a page just before it is used, then it will just have to get that page
again almost immediately. Too much of this leads to a condition called
Thrashing. The system spends most of its time swapping pages rather
than executing instructions. So a good page replacement algorithm is
required.
27 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
Causes of Thrashing :
1. High degree of multiprogramming : If the number of
processes keeps on increasing in the memory than number of
frames allocated to each process will be decreased. So, less
number of frames will be available to each process. Due to
this, page fault will occur more frequently and more CPU time
will be wasted in just swapping in and out of pages and the
utilization will keep on decreasing.
For example:
Let free frames = 400
Case 1: Number of process = 100
Then, each process will get 4 frames.
Case 2: Number of process = 400
Each process will get 1 frame.
Case 2 is a condition of thrashing, as the number of processes
are increased,frames per process are decreased. Hence CPU
time will be consumed in just swapping pages.
2. Lacks of Frames:If a process has less number of frames then
less pages of that process will be able to reside in memory and
hence more frequent swapping in and out will be required. This
may lead to thrashing. Hence sufficient amount of frames must
be allocated to each process in order to prevent thrashing.
Recovery of Thrashing :
• Do not allow the system to go into thrashing by instructing the
long term scheduler not to bring the processes into memory
after the threshold.
• If the system is already in thrashing then instruct the mid term
schedular to suspend some of the processes so that we can
recover the system from thrashing.
have to replace one of the existing pages with the newly needed page.
Different page replacement algorithms suggest different ways to decide
which page to replace. The target for all algorithms is to reduce the
number of page faults.
Page Replacement Algorithms :
Initially all slots are empty, so when 1, 3, 0 came they are allocated to the
empty slots —> 3 Page Faults.
when 3 comes, it is already in memory so —> 0 Page Faults.
Then 5 comes, it is not available in memory so it replaces the oldest page
slot i.e 1. —>1 Page Fault.
6 comes, it is also not available in memory so it replaces the oldest page slot
i.e 3 —>1 Page Fault.
Finally when 3 come it is not avilable so it replaces 0 1 page fault
29 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
30 | P a g e
Contact: 7008443534, 9090042626
Subject: Operating System
Created By: Asst. Prof. SK ABDUL ISRAR College: ABA, BLS
31 | P a g e
Contact: 7008443534, 9090042626