0% found this document useful (0 votes)
25 views

Memory Management

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

Memory Management

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

Memory

Management:
Virtual Memory

LEADER: MARCOJOS, KRISTINA MELQUERY


MEMBERS: LAYNO, JUNAICA G.
FLORES, HANNAHLEE
SALIPOT, KARYLL MAE

1|Page
What is virtual memory?

It is a technique that allows programs to be executed even


though they are not stored entirely in memory.
 Requires cooperation between the Memory Manager
and the processor hardware
Needed Entire
Program Program

Architecture of the Computer with Virtual


Memory

 Advantages of virtual memory


management:
 Job size is not restricted to the size of main
memory
 Memory is used more efficiently
 Allows an unlimited amount of multiprogramming

2|Page
 Eliminates external fragmentation and minimizes
internal fragmentation
 Allows the sharing of code and data
 Facilitates dynamic linking of program segments
 Disadvantages:
 Increased processor hardware costs
 Increased overhead for handling paging
interrupts
 Increased software complexity to prevent
thrashing

3|Page
WHAT ARE THE REASONS OF
DEVELOPING THE VIRTUAL
MEMORY?

Disadvantages of early schemes:


o Required storing entire program in
memory
o Fragmentation
o Overhead due to relocation

Evolution of virtual memory helps to:


o Remove the restriction of storing
programs contiguously
o Eliminate the need for entire program to
reside in memory during execution

4|Page
MEMORY ALLOCATION

Page Memory Allocation


 The process of storing a portion of an executing process on disk or
secondary memory.
 Divides each incoming job into pages of equal size
 Before executing a program, Memory Manager:
o Determines number of pages in program
o Locates enough empty page frames in main memory
o Loads all of the program’s pages into them

 Memory manager requires three tables to keep track of the job


pages:
o Job Table (JT)
o Page Map Table (PMT)
o Memory Map Table (MMT)

5|Page
Demand Page Memory Allocation
 it is a memory allocation schemes that load the pages into
memory only as they are needed, allowing jobs to be run
with less main memory
 Uses the virtual memory (hard disk) as a temporary storage
of the jobs to be processed

Mutually exclusive modules

 void rectangleType::GetInput()
 {
 cout<<"Enter length:";
 cin>>length;
 cout<<"Enter width:";
 cin>>width;
 }
 double rectangleType::ComputeResult()
 {
 return length*width;
 }

6|Page
 double rectangleType::DisplayResult() const
{
 cout<<"The area of the rectangle is " << ComputeResult();
}

Page Replacement Policies


and Concepts

o First-in first-out (FIFO) policy


o Least-recently-used (LRU) policy
o Most recently used (MRU) policy
o Least frequently used (LFU) policy

7|Page
The OS depends on following tables:
 Job table
 Page map table
 Memory map table
 Swapping Process
 Page fault handler
 Thrashing
 Page fault

The Mechanics of Paging

 Status bit
 Referenced bit
 Modified bit

8|Page
The Working Set

Working set
 Set pages residing in memory that can be accessed
directly without incurring a page fault
System must decide

9|Page
Segmented Memory Allocation
 Each job is divided into several segments of different
sizes, one for each module that contains pieces to
perform related functions
 Main memory is no longer divided into page frames,
rather allocated in a dynamic manner
 Segments are set up according to the program’s
structural modules when a program is compiled or
assembled
#include <stdio.h>
main(){
double area;
area=GetInput();
10 | P a DisplayResult(ComputeArea(area));
ge
}
int GetInput(){
Segmented memory allocation. Job 1
includes a main program, Subroutine A, and

11 | P a g e
Subroutine B. It’s one job divided into three
segments.

The Segment Map Table tracks each


segment for Job 1

WHAT IS THE PROBLEM OF THE


DEMAND PAGE MEMORY
ALLOCATION THAT GIVES BIRTH
THE CONCEPT OF SEGMENTED
MEMORY ALLOCATION?
Trashing
- An excessive amount of page swapping between
main memory and secondary storage
- Caused when a page is removed from memory but is
called back shortly thereafter
- Can happen within a job (e.g., in loops that cross
page boundaries)
12 | P a g e
for(j=1; j<100; j++)
{
k=j*j;

M=a*j;
printf(“\n%d %d %d”, j,k,m)
}
printf(“\n”);

An example of demand paging that causes a page


swap each time the loop is executed and results in
thrashing. If only a single page frame is available,
this program will have one page fault each time the
loop is executed

 Memory Manager tracks segments in memory


using following three tables:
 Job Table lists every job in process (one for
whole system)

13 | P a g e
 Segment Map Table lists details about each
segment (one for each job)
 Memory Map Table monitors allocation of
main memory (one for whole system)
 Segments don’t need to be stored contiguously
 The addressing scheme requires segment
number and displacement

Segmented/Demand Page Memory


Allocation
 What is the problem of the segmented memory
allocation that gives birth the idea of
segmented/demand page memory allocation?
 Dynamic allocation
 Subdivides segments into pages of equal size,
smaller than most segments, and more easily
manipulated than whole segments. It offers:
 Logical benefits of segmentation
14 | P a g e
 Physical benefits of paging
 Removes the problems of compaction, external
fragmentation, and secondary storage handling
 The addressing scheme requires segment
number, page number within that segment, and
displacement within that page
 What is segmented/demand paged memory
allocation?
 Subdivides segments into pages of equal
size, smaller than most segments, and more
easily manipulated than whole segments. It
offers:
 Logical benefits of segmentation
 Physical benefits of paging
 Removes the problems of compaction, external
fragmentation, and secondary storage handling
 Removes the problem of thrashing
 This scheme requires following four tables:
 Job Table lists every job in process (one for
the whole system)
 Segment Map Table lists details about each
segment (one for each job)

15 | P a g e
 Page Map Table lists details about every
page (one for each segment)
 Memory Map Table monitors the allocation
of the page frames in main memory (one for
the whole system)

Interaction of JT, SMT, PMT, and main memory


in a segment/paging scheme

 How does the computer determine the exact


address of the line of code in the memory?
 Compute the page and displacement of the
line of code
 Determine what segments the line belong

16 | P a g e
 Determine the frame number of the line
using the SMT and PMT
 Frame number + displacement

Cache Memory

 A small high-speed memory unit that a processor can


access more rapidly than main memory
 Used to store frequently used data, or instructions
 Movement of data, or instructions, from main memory
to cache memory uses a method similar to that used in
paging algorithms

Comparison of (a) traditional path used by


early computers and (b) path used by modern

17 | P a g e
computers to connect main memory and
CPU via cache memory

Types of cache memory


L1 cache – built directly to the CPU
L2 cache – integral part of the CPU

 Efficiency Calculation
 Hit Ratio
 h = (number of request found in the
cache/total number of requests) * 100
 Average Access time
 ta=tc + (1-h)*tm
 Where:
 ta=access time
 tc=cache access time
 h=hit ratio
 tm=main memory access time

18 | P a g e
SUMMARY
 Paged memory allocations allow efficient use of
memory by allocating jobs in noncontiguous memory
locations
 Increased overhead and internal fragmentation are
problems in paged memory allocations
 Job no longer constrained by the size of physical
memory in demand paging scheme
 LRU scheme results in slightly better efficiency as
compared to FIFO scheme
 Segmented memory allocation scheme solves
internal fragmentation problem
 Segmented/demand paged memory allocation
removes the problems of compaction, external
fragmentation, and secondary storage handling
 Associative memory can be used to speed up the
process
 Virtual memory allows programs to be executed even
19 | P a g e
though they are not stored entirely in memory
 Job’s size is no longer restricted to the size of main
memory by using the concept of virtual memory

20 | P a g e
21 | P a g e
22 | P a g e

You might also like