Unit 5 Memory Management

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

UNIT – 5

MEMORY MANAGEMENT
This Memory Hierarchy Design is divided into 2 main types:

External Memory or Secondary Memory –


Comprising of Magnetic Disk, Optical Disk, Magnetic Tape i.e. peripheral
storage devices which are accessible by the processor via I/O Module.
Internal Memory or Primary Memory –
Comprising of Main Memory, Cache Memory & CPU registers. This is
directly accessible by the processor.
We can infer the following characteristics of Memory Hierarchy Design from
above figure:
1. Capacity:
It is the global volume of information the memory can store. As we move
from top to bottom in the Hierarchy, the capacity increases.
2. Access Time:
It is the time interval between the read/write request and the availability of
the data. As we move from top to bottom in the Hierarchy, the access time
increases.
3. Performance:
One of the most significant ways to increase system performance is
minimizing how far down the memory hierarchy one has to go to
manipulate data.
4. Cost Per Bit:
As we move from bottom to top in the Hierarchy, the cost per bit increases
i.e. Internal Memory is costlier than External Memory.
Program must be brought (from disk) into memory and placed within a
process for it to be run
Main memory and registers are only storage CPU can access directly
Register access in one CPU clock (or less)
Main memory can take many cycles
Cache sits between main memory and CPU registers

Logical vs Physical Address Space


 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; logical (virtual) and physical addresses differ in
execution-time address-binding scheme
Memory protection
CACHE MEMORY
 Cache Memory is a special very high-speed memory. It is used to speed up
and synchronizing with high-speed CPU. Cache memory is costlier than
main memory or disk memory but economical than CPU registers. Cache
memory is an extremely fast memory type that acts as a buffer between
RAM and the CPU. It holds frequently requested data and instructions so
that they are immediately available to the CPU when needed.
 Cache memory is used to reduce the average time to access data from the
Main memory. The cache is a smaller and faster memory which stores
copies of the data from frequently used main memory locations. There are
various different independent caches in a CPU, which store instructions and
data.
LEVELS OF MEMORY:
 Level 1 or Register –
It is a type of memory in which data is stored and accepted that are
immediately stored in CPU. Most commonly used register is
accumulator, Program counter, address register etc.

 Level 2 or Cache memory –


It is the fastest memory which has faster access time where data is
temporarily stored for faster access.

 Level 3 or Main Memory –


It is memory on which computer works currently. It is small in size
and once power is off data no longer stays in this memory.

 Level 4 or Secondary Memory –


It is external memory which is not as fast as main memory but data
stays permanently in this memory.
Cache Performance
When the processor needs to read or write a location in main
memory, it first checks for a corresponding entry in the cache.
If the processor finds that the memory location is in the cache,
a cache hit has occurred and data is read from cache
If the processor does not find the memory location in the cache,
a cache miss has occurred. For a cache miss, the cache
allocates a new entry and copies in data from main memory,
then the request is fulfilled from the contents of the cache.
The performance of cache memory is frequently measured in
terms of a quantity called Hit ratio.
Hit ratio = hit / (hit + miss) = no. of hits/total accesses
We can improve Cache performance using higher cache block
size, higher associativity, reduce miss rate, reduce miss
penalty, and reduce the time to hit in the cache.
CACHE MAPPING

There are three different types of mapping used for the


purpose of cache memory which are as follows: Direct
mapping, Associative mapping, and Set-Associative mapping.
These are explained below.
Direct Mapping –
The simplest technique, known as direct mapping, maps each
block of main memory into only one possible cache line. or
In Direct mapping, assigne each memory block to a specific
line in the cache. If a line is previously taken up by a memory
block when a new block needs to be loaded, the old block is
trashed. An address space is split into two parts index field
and a tag field. The cache is used to store the tag field whereas
the rest is stored in the main memory. Direct mapping`s
performance is directly proportional to the Hit ratio.
Associative Mapping –
In this type of mapping, the associative memory is used to store content
and addresses of the memory word. Any block can go into any line of the
cache. This means that the word id bits are used to identify which word
in the block is needed, but the tag becomes all of the remaining bits. This
enables the placement of any word at any place in the cache memory. It
is considered to be the fastest and the most flexible mapping form.
Set-associative Mapping –
This form of mapping is an enhanced form of direct mapping where the
drawbacks of direct mapping are removed. Set associative addresses the
problem of possible thrashing in the direct mapping method. It does this
by saying that instead of having exactly one line that a block can map to
in the cache, we will group a few lines together creating a set. Then a
block in memory can map to any one of the lines of a specific set..Set-
associative mapping allows that each word that is present in the cache
can have two or more words in the main memory for the same index
address. Set associative cache mapping combines the best of direct and
associative cache mapping techniques.In this case, the cache consists of a
number of sets, each of which consists of a number of lines. The
relationships are
LOCALITY OF REFERENCE

Since size of cache memory is less as compared to main


memory. So to check which part of main memory should be
given priority and loaded in cache is decided based on locality of
reference.
Types of Locality of reference
Spatial Locality of reference
This says that there is a chance that element will be present in the
close proximity to the reference point and next time if again
searched then more close proximity to the point of reference.
Temporal Locality of reference
In this Least recently used algorithm will be used. Whenever
there is page fault occurs within a word will not only load word
in main memory but complete page fault will be loaded because
spatial locality of reference rule says that if you are referring any
word next word will be referred in its register that’s why we load
complete page table so the complete block will be loaded.
Swapping
Swapping is a mechanism in which a process can be swapped
temporarily out of main memory (or move) to secondary
storage (disk) and make that memory available to other
processes. At some later time, the system swaps back the
process from the secondary storage to main memory.
Though performance is usually affected by swapping process
but it helps in running multiple and big processes in parallel
and that's the reason Swapping is also known as a technique
for memory compaction.
The total time taken by swapping process includes the time it
takes to move the entire process to a secondary disk and then
to copy the process back to memory, as well as the time the
process takes to regain main memory.
A swapping allows more processes to be run and can be fit into memory at
one time. The main part of swapping is transfer time and the total transfer
time is directly proportional to the amount of memory swapped.
Swapping is also known as roll-out, roll in, because if a higher priority
process arrives and wants service, the memory manager can swap out the
lower priority process and then load and execute the higher priority process.
After finishing higher priority work, the lower priority process swapped back
in memory and continued to the execution process.
CONTIGUOUS MEMORY ALLOCATION
The main memory must accommodate both the operating system and the
various user processes. Therefore, the allocation of memory becomes an
important task in the operating system.
The memory is usually divided into two partitions: one for the resident
operating system and one for the user processes. We normally need several
user processes to reside in memory at the same time. Therefore, we need to
consider how to allocate available memory to the processes that are in the
input queue waiting to be brought into memory. In contiguous memory
allocation, each process is contained in a single contiguous section of memory.
A computer that uses contiguous memory allocation’s memory blocks will look
something like this during the process. the memory space allotted for the
process is not scattered. Instead, adjacent blocks were used for it.

NON-CONTIGUOUS MEMORY ALLOCATION


It is the opposite of contiguous memory allocation. In it, a system allocates
memory space in different locations to a process, depending on its
requirements. In diagram terms, it looks like this
Memory allocation:
One of the simplest methods for allocating memory is to divide memory
into several fixed-sized partitions and each partition contains exactly one
process. Thus, the degree of multiprogramming is obtained by the number
of partitions.
Variable partition allocation: A process is selected from the input queue
and loaded into the free partition. When the process terminates, the
partition becomes available for other processes.
Fixed partition allocation: The operating system maintains a table that
indicates which parts of memory are available and which are occupied by
processes. Initially, all memory is available for user processes and is
considered one large block of available memory. This available memory is
known as “Hole”. When the process arrives and needs memory, a hole
that is large enough to store that process is searched. If the requirement
fulfills then memory is allocated to process, otherwise keeping the rest
available to satisfy future requests. While allocating a memory sometimes
dynamic storage allocation problems occur, which concerns how to satisfy
a request of size n from a list of free holes. There are some solutions to
this problem:
1. First fit:-
In the first fit, the first available free hole
fulfills the requirement of the process
allocated. Here, in this diagram 40 KB
memory block is the first available free
hole that can store
process A (size of 25 KB), because the first
two blocks did not have sufficient memory
space.

2. 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. Here in this example,
first, we traverse The complete list and find
the last hole 25KB is the best suitable hole
for Process A(size 25KB). In this method
memory utilization is maximum as
compared to other memory allocation
techniques.
3. Worst fit
In the worst fit, allocate the
largest available hole to process.
This method produces the
largest leftover hole. Here in this
example, Process A (Size 25
KB) is allocated to the largest
available memory block which
is 60KB. Inefficient memory
utilization is a major issue in the
worst fit.

You might also like