Memory Management
Memory Management
MANAGEMENT
SYSTEM DESIGN OS PART 3
MEMORY MANAGEMENT
Main Memory
Main memory is the place where programs and information are kept
when the processor is effectively utilizing them. Main memory is
associated with the processor, so moving instructions and
information into and out of the processor is extremely fast. Main
memory is also known as RAM (Random Access Memory). This
memory is volatile. RAM loses its data when a power interruption
occurs.
MEMORY MANAGEMENT
Memory Hierarchy
MEMORY MANAGEMENT
Memory Management
In a multiprogramming computer, the Operating System resides in a part of memory, and the
rest is used by multiple processes. The task of subdividing the memory among different
processes is called Memory Management.
Logical Address Space: An address generated by the CPU is known as a “Logical Address”. It is
also known as a Virtual address. Logical address space can be defined as the size of the
process. A logical address can be changed.
Physical Address Space: An address seen by the memory unit (i.e. the one loaded into the
memory address register of the memory) is commonly known as a “Physical Address”. A
Physical address is also known as a Real address. The set of all physical addresses
corresponding to these logical addresses is known as Physical address space. A physical
address is computed by MMU. The run-time mapping from virtual to physical addresses is
done by a hardware device Memory Management Unit(MMU). The physical address always
remains constant.
MEMORY MANAGEMENT
MEMORY MANAGEMENT
Static and Dynamic Loading
Loading a process into the main memory is done by a loader. There are two
different types of loading :
•Static Loading: Static Loading is basically loading the entire program into a
fixed address. It requires more memory space.
•Dynamic Loading: The entire program and all data of a process must be in
physical memory for the process to execute. So, the size of a process is
limited to the size of physical memory. To gain proper memory utilization,
dynamic loading is used. In dynamic loading, a routine is not loaded until it is
called. All routines are residing on disk in a relocatable load format. One of
the advantages of dynamic loading is that the unused routine is never loaded.
This loading is useful when a large amount of code is needed to handle it
efficiently.
MEMORY MANAGEMENT
Static and Dynamic Linking
To perform a linking task a linker is used. A linker is a program that takes one
or more object files generated by a compiler and combines them into a single
executable file.
Static Linking: In static linking, the linker combines all necessary program
modules into a single executable program. So there is no runtime
dependency. Some operating systems support only static linking, in which
system language libraries are treated like any other object module.
Advantages:
• Supports Multiprogramming
• Simple to implement
• Tracking of blocks is easy
Disadvantages:
Disadvantages:
• a variable-size partition scheme is difficult to
implement.
• It is difficult to keep track of processes and the
remaining space in the memory.
• External Fragmentation
First Fit : the first available free hole fulfil the requirement of the process allocated
Best Fit : In the Best Fit, allocate the smallest hole that is big enough to process requirements.
For this, we search the entire list, unless the list is ordered by size.
Worst Fit : In the Worst Fit, allocate the largest available hole to process. This method
produces the largest leftover hole.
MEMORY MANAGEMENT
Strategies Used for Contiguous Memory Allocation Input Queues
Example: Consider six memory holes of size 200 KB, 400 KB, 600 KB, 500 KB, 300
KB and 250 KB. These partitions need to be allocated to four processes of sizes 357
KB, 210 KB, 468 KB and 491 KB in that order. [Variable size partitioning]
LOGICAL ADDRESS SPACE (LAS) is 128KB, PHYSICAL ADDRESS SPACE (PAS) is 512KB and
PAGE SIZE is 16KB [Byte addressable]
CALCULATE FOLLOWING:
GIVEN DATA :
64 MB physical memory
32 bit virtual address space.
page size is 4 KB
GIVEN DATA :
GIVEN DATA :
Calculate the size of memory if its address consists of 22 bits and the memory is 2-
byte addressable.
MEMORY MANAGEMENT
Segmentation
MEMORY MANAGEMENT
Segmentation: User view of Program
MEMORY MANAGEMENT
Segmentation: User view of Program
1
4
1
2
3
2
4
<segment-number, offset>,
Segment table – maps two-dimensional physical addresses; each table entry has:
base – contains the starting physical address where the segments reside in memory
limit – specifies the length of the segment
Segment-table base register (STBR) points to the segment table’s location in memory
Page Fault: A page fault happens when a running program accesses a memory
page that is mapped into the virtual address space but not loaded in physical
memory. Since actual physical memory is much smaller than virtual memory,
page faults happen. In case of a page fault, Operating System might 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.
MEMORY MANAGEMENT
Page Replacement Algorithms
FIFO
LRU