0% found this document useful (0 votes)
106 views70 pages

UNIT 4 - MEMORY MANAGEMENT Lecture 1 and 2

This document provides information about a course on operating system memory management. It outlines the syllabus, objectives, outcomes and applications of the unit on memory management. Key concepts covered include memory allocation strategies, paging, segmentation, virtual memory and page replacement algorithms.

Uploaded by

devsuraj2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views70 pages

UNIT 4 - MEMORY MANAGEMENT Lecture 1 and 2

This document provides information about a course on operating system memory management. It outlines the syllabus, objectives, outcomes and applications of the unit on memory management. Key concepts covered include memory allocation strategies, paging, segmentation, virtual memory and page replacement algorithms.

Uploaded by

devsuraj2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 70

Noida Institute of Engineering and Technology, Greater

Noida

Memory Management
UNIT 4
ACSE0403A/AMICSE0403A
Unit: 4

Operating System
Ram Kumar Sharma

Course Details Information Technology


(B Tech 4th Sem)

Ram Kumar Sharma ACSE0403A OS Unit 4


May 19, 2024 1
Evaluation Scheme

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 2


Subject Syllabus

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 3


Subject Syllabus

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 4


Syllabus For Unit-4

UNIT-IV Memory Management


Memory Management function, Address Binding, Loading :
Compile Time, Load Time and Execution Time, MMU, Types of
Linking, Types of Loading, Swapping, Multiprogramming with
Fixed Partitions, Multiprogramming with variable partitions,

Memory Allocation: Allocation Strategies First Fit, Best Fit,


and Worst Fit, Paging, Segmentation, Paged Segmentation,
Virtual Memory Concepts, Demand Paging, Performance of
Demand Paging, Page Replacement Algorithms: FIFO,LRU,
Optimal and LFU, Belady’s Anomaly, Thrashing, Cache
Memory Organization, Locality of Reference.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 5


Branch wise Applications

• Airlines reservation system.


• Air traffic control system.
• Systems that provide immediate updating.
• Used in any system that provides up to date and minute
information on stock prices.
• Defense application systems like RADAR.
• Networked Multimedia Systems.
• Command Control Systems.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 6


Course Objectives

• Provide an understanding of the basic modules and


architecture of an operating system and the functions of the
modules to manage, coordinate and control all the parts of the
computer system.
• Processor scheduling, deadlocks, memory management,
process synchronization, system call and file system
management.

Ram Kumar Sharma ACSE0403A OS Unit 4


May 19, 2024 7
Course Outcomes

Course outcome: After completion of this course students will be able to:

CO 1 Understand the fundamentals of an operating systems, K1, K2


functions and their structure and functions.

CO2 Implement concept of process management policies, CPU K5


Scheduling and thread management.

CO3 Understand and implement the requirement of process K2,K5


synchronization and apply deadlock handling algorithms.

CO4 Evaluate the memory management and its allocation policies. K5

CO5 Understand and analyze the I/O management and File K2, K4
systems

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 8


Program Outcomes
1. Engineering knowledge
2. Problem analysis
3. Design/development of solutions
4.Conduct investigations of complex problems
5. Modern tool usage
6. The engineer and society
7. Environment and sustainability
8. Ethics:
9. Individual and team work
10. Communication
11. Project management and finance
12. Life-long learning

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 9


COs and POs Mapping
OPERATING SYSTEM (ACSE0403A )
CODE PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

ACSE0403A .1 3 3 2 2 1 2 - 2 3 2 2 3

ACSE0403A .2 3 3 3 2 2 3 - 2 3 1 1 3

ACSE0403A .3 3 3 2 2 2 2 - 2 2 3 1 3

ACSE0403A .4 3 2 2 3 1 2 - 1 2 1 2 3

ACSE0403A .5 3 1 2 2 2 2 - 1 2 2 2 3

Average 3 2.4 2.2 2.2 1.6 2.2 - 1.8 2.2 1.8 1.6 3

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 10


Program Specific Outcomes(PSOs)
On successful completion of B. Tech. (I.T.) Program, the Information
Technology graduates will be able to:

• PSO1:- Work as a software developer, database administrator, tester or


networking engineer for providing solutions to the real world and
industrial problems.
• PSO2:- Apply core subjects of information technology related to data
structure and algorithm, software engineering, web technology, operating
system, database and networking to solve complex IT problems.
• PSO3:-Practice multi-disciplinary and modern computing techniques by
lifelong learning to establish innovative career.
• PSO4:-Work in a team or individual to manage projects with ethical
concern to be a successful employee or employer in IT industry.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 11


COs and PSOs Mapping

Program Specific Outcomes


Course
Outcomes PSO1 PSO2 PSO3 PSO4

ACSE0403A .1 2 1 2 2
ACSE0403A .2 2 2 1 2
ACSE0403A .3 2 3 3 2
ACSE0403A .4 2 2 1 2
ACSE0403A .5 2 2 2 2
Average 2 2 1.8 2

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 12


Program Educational Objectives (PEOs)

• PEO1:Apply sound knowledge in the field of information technology


to fulfill the needs of IT industry.
• PEO2:Design innovative and interdisciplinary systems through latest
digital technologies.
• PEO3:Inculcate professional – social ethics, team work and
leadership for serving the society.
• PEO4:Inculcate lifelong learning in the field of computing for
successful career in organizations and R&D sectors.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 13


Faculty wise Result Analysis

Semester & Section Subject Code Result

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 14


End Semester Question Paper Templates (Offline
Pattern/Online Pattern

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 15


End Semester Question Paper Templates (Offline
Pattern/Online Pattern

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 16


End Semester Question Paper Templates (Offline
Pattern/Online Pattern

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 17


End Semester Question Paper Templates (Offline
Pattern/Online Pattern

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 18


End Semester Question Paper Templates (Offline
Pattern/Online Pattern

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 19


End Semester Question Paper Templates (Offline
Pattern/Online Pattern

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 20


End Semester Question Paper Templates (Offline
Pattern/Online Pattern

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 21


Prerequisite and Recap
Prerequisite
• First get your computer hardware basics cleared.
• Digital logic and it’s design (Basics will make understand storing memory and page
faults, Difference between ram and rom. etc.,)
• Computer Organization and Architecture( Design of Computer architecture will
help you understand computer peripherals and its storages, accessing them in
operating system )
• Strong programming skills (Knowledge of C).
Recap
 To understood the Processes and process state
 To analyzed the critical section problem with various algorithm
 Illustrate the methods of process management, process synchronization.
 Demonstrate the various classical problem implemented by semaphore
• To understand of deadlocks, which prevent sets of concurrent processes from
completing their tasks.
• To understand different methods for preventing or avoiding deadlocks in a
computer system.
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 22
Unit-4 Memory Management (Objective)
After going through this unit, you should be able to:
• To provide a detailed description of various ways of organizing memory hardware.
• To explores various techniques of allocating memory to processes.

• To understand memory management functions such as allocation of memory to the


processes, de-allocate memory from the processes and implement allocation
strategies such as First Fit, Best Fit and Worst Fit.
• To understand the virtual memory concepts and evaluate the performance of
virtual memory with the help of effective memory access time.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 23


Content

 Course Objective
 Course Outcome
 CO-PO Mapping
 AKTU Syllabus of Unit 4
 Prerequisite and Recap
 Introduction
 Swapping
 Contiguous Memory Allocation
 Paging
 Segmentation
 Structure of the Page Table
 Virtual Memory

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 24


Content

 Demand Paging
 Copy-on-Write
 Page Replacement
 Allocation of Frames
 Thrashing
 Video links/Daily Quiz/Weekly Assignment/MCQ/Old Question
papers/Expected Question for University Exam/Summary/References

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 25


Prerequisite and Topic wise Recap

Prerequisite:-
 Basic knowledge about the digital logic and computer organization.

Recap:-
 To discussed the various approaches to manage the CPU and
deadlock problem in computer system.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 26


Topic Objective

• To provide a detailed description of various ways of organizing


memory hardware.
• To understand the different steps of address binding.
• To learn about physical and logical address spaces.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 27


Lecture No:-1
1. Introduction
2. Functions of Memory Management
3. Requirement of Memory Management
4. Basic Hardware & Hardware Address Protection
5. Address Binding
6. Linker and loader
7. Swapping

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 28


Introduction (CO4)

Memory management is the functionality of an operating


system which handles or manages primary memory(Main
Memory/RAM) and secondary memory .

The main objective of management of main memory comes


from the support the concept of multiprogramming by
different - different operating system.

For Video Lecture:- https://www.youtube.com/watch?v=UDPYpf-nsDY

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 29


Functions of Memory Management

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 30


Requirements of memory management

 Memory management keeps track of the status of each memory


location, whether it is allocated or free.

 It allocates the memory dynamically to the programs at their


request and frees it for reuse when it is no longer needed.
Requirements of memory management are:
1. Relocation
2. Protection
3. Sharing
4. Logical organization
5. Physical Organization

For Video Lecture:- https://www.youtube.com/watch?v=UDPYpf-nsDY


May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 31
Requirements of memory management
1. Relocation:- Changing address in a user program at different types of
binding
2. Protection:- When we have two program at the same time there is a
danger that one program can write to the address space of another
program so in the manner every process should be protected against
unwanted interference by other processes.
3. Sharing:- Protection mechanism must have the flexibility to allow
several processes to access the same portion of the main memory.
4. Logical organization:- Addresses generated by the CPU or processor
are called logical or virtual address. Set of all logical addresses is
referred Virtual address space.
5. Physical Organization:- Addresses generated in the main
memory(RAM) by Operating system physical or actual address actual
address. Set of all physically address is referred physical address
space.
For Video Lecture:- https://www.youtube.com/watch?v=UDPYpf-nsDY
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 32
Basic hardware
Basic Hardware:- Memory Management provide protection for processes by
using two registers. Because each process has a separate memory space.
Types of registers for memory Protection
1 Base register- contains value of smallest physical address
2. Limit register- contains range of logical addresses – each logical
address must be less than the limit register.

Figure :- A base and a limit register define a logical address space


• A pair of base and limit registers define the logical address space.
• CPU must check every memory access generated in user mode to be sure it is
between base and limit for that user.
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 33
Hardware Address Protection (CO4)
Protection of memory space is accomplish by having the CPU hardware
compare every addresses generated in user mode with the registers .

Figure 2:- Hardware address protection with base and limit registers.

Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter
Baer Galvin, and Greg Gagne Page No. -317
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 34
Address Binding
Address binding is the process of mapping from one address space to
another address space.
Or
The Association of program instruction and data to the actual physical
memory locations is called the Address Binding.
An address binding can be done in three different ways :
 Compile time: If memory location known a priori, absolute code can be
generated; must recompile code if starting location changes
 Load time: Must generate relocatable code if memory location is not
known at compile time
 Execution time: Binding delayed until run time if the process can be
moved during its execution from one memory segment to another

Need hardware support for address maps (e.g., base and limit
registers).

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 35


Multistep Processing of a User Program

Figure 3:- Multistep processing of a user program.

Reference Book :- Operating System Concepts (8th Edition) Abraham


Silberschatz, Peter Baer Galvin, and Greg Gagne Page No. -318-319.
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 36
Logical vs. Physical Address Space (CO4)
The concept of a logical address space that is bound to a separate
physical address space is central to proper memory management.
 Logical address – generated by the CPU; also referred to as virtual
address
 Physical address – address seen by the memory unit
Logical and physical addresses are the same in compile-time and load-
time address-binding schemes; but logical (virtual) and physical
addresses differ in execution-time address-binding scheme.
 Logical address space The logical address space is the range of logical
addresses that can be generated by a process running on the CPU.
 Physical address space The physical address space is the range of
physical addresses that can be recognized by the memory.

For Video Lecture:- https://www.youtube.com/watch?v=CmTMr_x3NwY

May 19, 2024 37


Ram Kumar Sharma ACSE0403A OS Unit 4
Memory-Management Unit (MMU)

 It is a computer hardware unit having all memory references


passed through itself, primarily performing the translation of virtual
memory addresses to physical addresses.
 It is maps virtual address to physical address at the run time.

Figure 4:- MMU


 For Video Lecture:-
http://www.infocobuild.com/education/audio-video-courses/computer-
science/IntroToOperatingSystems-IIT-Madras/lecture-07.html
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 38
Linker & Loader (CO4)
Linker and loader are two instruments that play a major role in program
execution.
Linker - Linking intends to generate an executable module of a program by
combining the object codes generated by the assembler.

Loader:- A loader, on the other hand, loads these executable modules to


the main memory for execution. Loading is the process of loading the
program from secondary memory to the main memory for
execution.
Types of Linking :-
1. Static Linker:- Compile-time linking is done when the source code
is translated to machine code.
2. Dynamic Linker:- The load-time linking is done while the program
is loaded into memory by the loader.
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 39
Linking & Loader (CO4)
Types of Loading
1. Static loading:- Loading the entire program into the main memory before
start of the program execution is called as static loading.
2. Dynamic Loading:- Dynamic loading is the technique through which a
computer program at runtime load a library into memory.

Figure 5:- Linking and loading


Reference:- https://www.csc2.ncsu.edu/faculty/xjiang4/csc501/readings/lec10-
linkerloader.pdf
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 40
Swapping (CO4)

Swapping is a memory management scheme in which any process


can be temporarily swapped from main memory to secondary
memory so that the main memory can be made available for other
processes. It is used to improve main memory utilization.

The purpose of the swapping in operating system is to access the


data present in the hard disk and bring it to RAM so that the
application programs can use it.

Note:- The thing to remember is that swapping is used only when


data is not present in RAM.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 41


Schematic View of Swapping (CO4)

Figure6 :- Swapping of two processes using a disk as a backing store.


The concept of swapping has divided into two more concepts: Swap-in
and Swap-out.
1. Swap-out is a method of removing a process from RAM and adding it
to the hard disk.
2. Swap-in is a method of removing a program from a hard disk and
putting it back into the main memory or RAM.
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 42
Daily Quiz-1

1. What are need of memory management.


2. Differentiate between physical and logical address.
3. Write the multiple step of address binding .
4. What is swapping?

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 43


Prerequisite and Topic wise Recap

Prerequisite
 Basic knowledge about the primary and secondary memory in
computer system .
Recap
 To understood of various ways of organizing memory hardware like
allocation, deallocation and protection of memory space of multiple
processes..

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 44


Topics & Course Outcome

Topic Name Course Outcome


Memory Allocation schemes CO4

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 45


Topic Objective

• To explores various techniques of allocating memory to processes.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 46


Lecture No:-2

1. Memory Partitioning in multiprogramming


2. Types of Memory Partition
i. Contiguous Memory Allocation
a) Fixed Partition
b) Variable Partition
3. Internal and External Fragmentation
4. Placement algorithm

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 47


Memory Partition in Multiprogramming System

• Several processes , jobs or programs in multi programming reside in


main memory at a time. So main memory should be partitioned and
allocate to them.

• Basically Main memory (RAM) partition in two types for allocating


the processes:-

1. Contiguous Memory Allocation

2. Non- contiguous memory Allocation

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 48


1.Contiguous Memory Allocation (CO4)

• It allows to store the process only in a contiguous fashion.


• Thus, entire process has to be stored as a single entity at one place
inside the memory.
Note :- Contiguous memory allocation scheme can be implemented
in Operating system with the help of base and limit register.
There are two techniques used for contiguous memory allocation-
1. Static Partitioning or Fixed size Partitioning
2. Dynamic Partitioning or variable size Partitioning

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 49


Static Partitioning or Fixed size Partitioning

1. Static Partitioning or Fixed size Partitioning:- This is the oldest and


simplest technique used to put more than one processes in the main
memory. In this technique, the main memory is divided into partitions
of equal or different sizes.
The operating system always resides in the first partition while the
other partitions can be used to store user processes. The memory is
assigned to the processes in contiguous way.

In the fixed Partitioning:


• There is no overlapping of partitions.
• For the process execution, the process should be present contiguously.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 50


Static Partitioning or Fixed size Partitioning

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 51


Advantages and Disadvantages Static Partitioning or Fixed size Partitioning

Advantages :-
1. Easy to implement
2. Little Operating System overhead.

Disadvantages :-
1. Suffer Internal Fragmentation:- If the size of the process is lesser then the
total size of the partition then some size of the partition get wasted and remain
unused. This is wastage of the memory and called internal fragmentation.

2. Suffer External Fragmentation:- The total unused space of various partitions


cannot be used to load the processes even though there is space available but
not in the contiguous form.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 52


Cont….

3. Limitation on the size of the process:- If the process size is larger


than the size of maximum sized partition then that process cannot be
loaded into the memory. Therefore, a limitation can be imposed on the
process size that is it cannot be larger than the size of the largest
partition.

4. Degree of multiprogramming is less:- By Degree of multi


programming, we simply mean the maximum number of processes that
can be loaded into the memory at the same time. In fixed partitioning,
the degree of multiprogramming is fixed and very less due to the fact
that the size of the partition cannot be varied according to the size of
processes.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 53


2. Dynamic Partitioning or variable size Partitioning

2. Dynamic Partitioning: – Dynamic Partitioning is another technique


for memory management that is invented to remove the problems that
arises in the Fixed Partitioning technique.

In dynamic partitioning, we do not declare the size of the partition in


the starting. Instead, we declare the size of partition at the time of its
loading.
How to memory partition done in Dynamic Memory Allocation?
In this, the operating system, reserves the first partition. The rest of
the other space is divided into different sections.
 Dynamic partitioning is a variable size partitioning scheme.
 It performs the allocation dynamically.
 When a process arrives, a partition of size equal to the size of process
is created.
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 54
Dynamic Partitioning

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 55


Advantages and Disadvantages of Dynamic Partitioning

Advantages:-

1. No Limitation on the size of the process:- In Fixed partitioning, the


process with the size greater than the size of the largest partition
could not be executed due to the lack of sufficient contiguous
memory. Here, In Dynamic partitioning, the process size can't be
restricted since the partition size is decided according to the
process size.
2. The Degree of Multiprogramming is dynamic:- Due to the absence
of internal fragmentation, there will not be any unused space in the
partition hence more processes can be loaded in the memory at the
same time.
3. No Internal Fragmentation:- the partitions in dynamic partitioning
are created according to the need of the process, It is clear that
there will not be any internal fragmentation because there will not
be any unused remaining space in the partition.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 56


Advantages and Disadvantages of Dynamic Partitioning

Disadvantages:-

1. Complex Memory Allocation:- In Fixed partitioning, the list of


partitions is made once and will never change but in dynamic
partitioning, the allocation and deallocation is very complex since
the partition size will be varied every time when it is assigned to a
new process. OS has to keep track of all the partitions.

2. External Fragmentation: – One of the main disadvantages of


dynamic partitioning is external fragmentation.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 57


Example
External fragmentation in Variable Partition:-

 Suppose we have three processes P1 require (1MB), P2 require (3MB),


and P3 require (1MB), and we want to load the processes in the
various partitions of the main memory.

 Now the processes P1 and P3 are completed, and space that is


assigned to the process P1 and P3 is freed.

 Now we have partitions of 1 MB each, which are unused and present in


the main memory, but we cannot use this space to load the process of
2 MB in the memory because space is not contiguous.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 58


Solution of External Fragmentation in Dynamic partition

In dynamic Partitioning, there is a problem of external


fragmentation.

Solution:-
• Compaction is a process in which the free space is collected in a
large memory chunk to make some space available for
processes. Compaction also known as defragmentation .

• In compaction technique , free partitions are merged and then


used. These merged partitions are allocated to other processes
according to their need. This technique is also called
defragmentation.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 59


Dynamic Storage-Allocation Problem

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 60


Difference between Internal fragmentation and External
fragmentation

Note:- 1. The solution of internal fragmentation is variable partition and


placement Algorithm.
2. The Solution of external fragmentation is compaction,
paging and segmentation.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 61


MCQ
1. Which one of the following is the address generated by CPU?
a) physical address
b) absolute address
c) logical address
d) none of the mentioned

2. Run time mapping from virtual to physical address is done by


____________
a) Memory management unit
b) CPU
c) PCI
d) None of the mentioned
3. Program always deals with ____________
a) logical address
b) absolute address
c) physical address
d) relative address
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 62
MCQ
4. What is compaction?
a) a technique for overcoming internal fragmentation
b) a paging technique
c) a technique for overcoming external fragmentation
d) a technique for overcoming fatal error
5. In contiguous memory allocation ____________
a) each process is contained in a single contiguous section of memory
b) all processes are contained in a single contiguous section of memory
c) the memory space is contiguous
d) none of the mentioned
6. When memory is divided into several fixed sized partitions, each partition
may contain ________
a) exactly one process
b) at least one process
c) multiple processes at once
d) none of the mentioned

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 63


Solution of the internal fragmentation
Solution of the “internal fragmentation “ is the Placement Algorithm.
So four different approaches can be given to solve the problem
(internal fragmentation) by placement algorithm.
Placement Algorithm are :-
1. First Fit
2. Best Fit
3. Worst Fit
4. Next Fit
5. First Fit:- . It scans memory from the beginning and chooses the first
available block that is large enough. Thus it allocates the first hole that
is large enough. Stop searching as soon as we find the free block is
large enough
Advantage:- Simple and fastest algorithm.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 64


Conti…
2. Best Fit Allocate the process to the partition which is the first smallest
sufficient partition among the free available partition. It searches the entire list of
holes to find the smallest hole whose size is greater than or equal to the size of
the process.
Advantages:- Minimum internal fragmentation
Disadvantages :- Best fit give worst performance because it consume lot of time
to searching which block is close to requested size.
3. Worst Fit Allocate the process to the partition which is the largest sufficient
among the freely available partitions available in the main memory. It is opposite
to the best-fit algorithm. It searches the entire list of holes to find the largest hole
and allocate it to process.
Advantages:- In this technique less external fragmentation.
Disadvantages:- Big internal fragmentation compare to best fit and first fit.
4. Next Fit: Next fit is similar to the first fit but it will search for the first sufficient
partition from the last allocation point.
Advantages:- Reduced the searching time compare to best fit and worst fit .
Disadvantages:-Searching the list every time the last allocated hole.
May 19, 2024
Ram Kumar Sharma ACSE0403A OS Unit 4 65
Example

Question 1:- Let us consider five memory partition of 100KB, 500KB,200


KB, 300 KB and 600 KB(in a order). If sequence of Process requests for
blocks of size 212 KB, 417 KB, 112 KB and 426 KB in same order come,
then which of the following algorithm makes the efficient use of memory?

Question 2:- Let us consider six memory partitions of size 200 KB, 400 KB,
600 KB, 500 KB, 300 KB and 250 KB. ). If sequence of process requests for
blocks of sizes 357 KB, 210 KB, 468 KB and 491 KB in that order. then
which of the following algorithm makes the efficient use of memory?

May 19, 2024


Ram Kumar Sharma ACSE0403A OS Unit 4 66
Daily Quiz-2

1. Differentiate between contiguous and non contiguous memory


allocation.
2. What is compaction.
3. Give the example for placement algorithm.
4. Differentiate between internal and external fragmentation.

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 67


MCQ-1
1. Which one of the following is the address generated by CPU?
a) physical address
b) absolute address
c) logical address
d) none of the mentioned

2. Run time mapping from virtual to physical address is done by


____________
a) Memory management unit
b) CPU
c) PCI
d) None of the mentioned
3. Program always deals with ____________
a) logical address
b) absolute address
c) physical address
d) relative address
May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 68
MCQ-1
4. What is compaction?
a) a technique for overcoming internal fragmentation
b) a paging technique
c) a technique for overcoming external fragmentation
d) a technique for overcoming fatal error
5. In contiguous memory allocation ____________
a) each process is contained in a single contiguous section of memory
b) all processes are contained in a single contiguous section of memory
c) the memory space is contiguous
d) none of the mentioned
6. When memory is divided into several fixed sized partitions, each partition
may contain ________
a) exactly one process
b) at least one process
c) multiple processes at once
d) none of the mentioned

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 69


Lecture No:-3

1. Non -Contiguous Memory Allocation


a) Paging
b) Segmentation
c) Paging with segmentation

2. Implementation of Page table


a) Register
b) PTBR and PTLR
c) Translation Look a side Buffer
3. Protection of Paging

May 19, 2024 Ram Kumar Sharma ACSE0403A OS Unit 4 70

You might also like