5
5
CHAPTER-5
Memory Management
Topics
1. Memory Management: Basic Concept.
2. Logical and Physical address map.
3. Memory Allocation: Contiguous Memory Allocation.
4. Fixed and Variable Partition.
5. Internal and External Fragmentation and Compaction.
6. Paging: Principle of Operation.
7. Page Allocation.
8. Hardware support for paging
What is Memory Management?
• Memory Management is an important characteristic of the
Operating System. This comes beneath one of
the two main capabilities of an Operating System, useful
resource management. Main memory (RAM) is
where maximum of the programs run. It is one of the most
important matters people search for whilst buying a
new cellphone or a new laptop.
What is Memory hierarchy ?
• In computer system architecture memory Hierarchy is part to arrange
the memory in a such a way it can minimize access time.
• Register < Cache < Main Memory
< Secondary Memory.
Figure - 1 Memory
Logical and physical address
• The concept of a logical address space that is bound to a separate physical
address
• Static
• Dynamic
Static Loading and Linking
• Loading the entire program into memory before startup execution
Figure – 3 Diagram of
Address Binding
• Address binding is the binding of instructions and data to memory addresses
– Execution time: Binding delayed until run time if the process can be moved
during its execution from one memory segment to another.
o Need hardware support for address maps (e.g., base and limit registers)
Swapping
• For temporarily any process can be swapped out of memory to
backing store and take back into memory for further execution.
• Roll out roll in: for priority based scheduling algorithm swapping
variant used; to load high-priority process and to get execute lower
priority process need to swapped out.
Figure – 6 Schematic
view Swapping [6]
Memory Management
Action to manage the memory of computer
system using various methods like partitions,
paging, segmentation and virtual memory is
called memory management.
Contiguous Non-contiguous
• Program must exist as a • Prog divided into chunks
single block of contiguous called segment
add. • Each segment can be placed
• Sometimes it is impossible different parts by memory.
to find large enough lock. • Easier to find “holes” in
• Low overhead which segment it will fit.
Memory Management Techniques (MMT)
500 500
600 650
700 750
800 800
900
1000 1000
Figure - 9
Multiprogramming with Fixed Partition (MFT)
•Advantage :
-- simple to implement
Disadvantages of Fixed Partition:
1.Internal Fragmentation
2.External Fragmentation
3.Limit process size
4.Limitation on Degree of Multiprogramming
Problems with Fixed Partitioning
• Main problem with this arrangement is fragmentation.
• Fragmentation is the presence of unusable areas in the computer memory
• There are two types of Fragmentation
1. Internal Fragmentation
Difference between total space of partition and space occupied by process is
called internal fragmentation
2. External fragmentation
This kind of memory un-utilization is called External fragmentation
Internal fragmentation
0
Here p1, p2,p3,p4 is loaded into memory
0
p1 30
P2 100
P3 150
P4 270
P5 520
P6 820
P7
990
p8
1000
Multiprogramming with Variable Partition(MVT)
•To avoid the difficulties of fixed partitions, partitions are created
dynamically.
•In Dynamic partitions , no partition is fixed into memory but the partition
are created only when process is loaded into memory
Figure - 10
• There are 6 processes p1, p2,p3,p4,p5, p6 and size of user process area
is 500MB which is currently free and no any partition in main memory.
p1 – 110 MB
500 p2 – 80MB
p3 – 40MB
p4 – 120MB
p5 – 100MB
p6=150MB
1000
• When process will load than the partition will be created as per size of
process.
0 0 0
500 500
610 610
690 690
730 730
850
850
950
1000 1000
External
[ Loading of p4 ] [ Loading of p5 ] fragmentation
Multiprogramming with Variable Partition(MVT)
• In our example, size of process P1 is 110 MB, so partition of 110 MB will be
created for process P1. Same procedure will repeat for all processes.
• Here every process will be loaded into memory dynamically and partition will be
created exactly as size of process.
• Here 5 processes can be loaded dynamically. And at last process p6 cannot be
loaded because there is not enough space in memory to load process P6, so
space of 50MB will be wasted in memory. This is called external fragmentation.
• Here the not problem of internal fragmentation. But here the problem of
external fragmentation.
Multiprogramming with Variable Partition(MVT)
Advantages of Variable Partition:
1.No internal fragmentation.
2.Efficient use of memory.
Disadvantages of Variable Partition:
1.Problem of external fragmentation.
2.Not easy to implement.
Compaction
• Compaction is one of the technique to avoid External
Fragmentation.
Figure - 14 Example of
Compaction
• Compaction is undesirable to implement because it interrupts all
the running processes in the main Memory.
Advantages: Remove EF
Non-contiguous memory allocation
• In Operating Systems, Paging is a storage mechanism used to retrieve
processes from the secondary storage into the main memory in the form of
pages.
• The main idea behind the paging is to divide each process in the form of
pages.
• The main memory will also be divided in the form of frames.
Paging:
•Paging is a memory management technique that permits the physical
address space of a process to be noncontiguous
then PA = 28 bits
•If LA = 37 bits
Page no.
Frame
no.
Process A
Example of paging
•Here process A is divided into pages page1, page2, page3, page4 and
•Here size of each page is 100MB, and size of each frame in memory is
100mB.
Paging Concepts
•Pages are loaded into frames.
•Page size and frame size are equal, which is defined by the system
hardware.
•Process will be divided into pages according to size of process.
•All pages of process will be loaded into the frames of MM.
Logical address
Logical address is divided into two parts
<-------------m--------------
Page no. Page offset
P d
Page number: used as an index
m-ninto page table
n
• In other words memory can be used efficiently and each job runs on
its own address space. Frames, pages and the mapping between the
two is shown in the .
Example of Page Allocation
• From figure, the size of each page is
100 memory locations.
Figure - 21 Example of
Advantages of Paging
• Memory allocation and de-allocation is very fast.
• It is noncontiguous memory allocation so we do not require
contiguous memory space for one process.
• No external fragmentation problem.
• Swap-in and Swap-out operations are performed fast.
Disadvantages of Paging
• This technique is suffering with internal fragmentation.
• For Example:-
If pages are 120 bytes, a process of 400 bytes requires 3
pages + for 40 bytes it requires again 1 page. So total 4
pages will be allocated.
Figure – 23 Valid(v) or
Inverted Page Table
Global page table P 0 Fo
A 1 No
G
Page Process 2 f2
Frame E
no ID
No. No. 3 No
Page table of P1
0 P0 P1
P1 P2 0 no
CPU P|d 1 F | d 1 f1
2 P2 P1 2 No
M/M 3 f4
Page table of P2
3 P1 P3
0 no
P3 P2
4 1 f3
2 f5
3 No
Page table of P3
Inverted Page Table Architecture
Cont.…
Paging Vs Segmantation
• Add()
Add()
Main()
F3
Mul()
F4
Sub()
Stack()
paging Segmentation
Segmentation
• Segmentation is a memory-management scheme that supports
user view of memory and contains segment.
Figure – 24 Memory
Segmentation
• Users or programmers specify each address by 2 quantities:
1) a segment name
2) an offset. (contrast to the paging)
Figure – 25 Memory
S | D
0 OS
Segment size
BA
S no Size 1500 S5
3 2300 400
2700 S2
4 2200 100
3300 S0
trap
1500 300
5 3500
M/M
d<=Size
Segmentation table
Example of Segmentation
Figure – 26 Memory
Hardware Implementation of Segmentation
Figure – 27 Address
Difference between Segmentation and Paging
Segmentation Paging
1 Program is divided into variable size Program is divided into fix size of pages.
segments.
2 Segmentation is slower than paging. Paging is faster than segmentation.
• Costly algorithm.