Nothing Special   »   [go: up one dir, main page]

Memory Management of Operating System

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 37

CHAPTER 2.

1
MEMORY MANAGEMENT OF
OPERATING SYSTEM

1

LEARNING OUTCOME
Explain Memory management Operating system
Function of memory manager
Characteristics of the different levels in the hierarchy of
memory organization.
Memory management strategies
Resident and transient routines.
Memory Swapping technique
Fixed-partition memory management
Segmentation and Paging
2

INTRODUCTION
Memory management is the act of managing computer
memory.
This involves providing ways to allocate part of
memory to programs at their request, and freeing it for
reuse when no longer needed.
The management of main memory is critical to the
computer system.
3

THE PURPOSE
WHY MEMORY MANAGEMENT?
4

Process isolation (separation)
Automatic allocation and
management
Support for modular
programming
Protection and access control
Long term storage
There are four major storage levels.
[1]

Internal Processor registers and cache.
Main the system RAM and controller cards.
On-line mass storage Secondary storage.
Off-line bulk storage Tertiary and Off-line storage
5

6

7

8

MEMORY MANAGEMENT
STRATEGIES
Fetch Policy
when to fetch a page

Placement Policy
where to put the page
Are some physical pages preferable to others?

Replacement Policy
what page to evict to make room?

9

A. RESIDENTS ROUTINES
B. TRANSIENT ROUTINES
1
0

Resident and Transient
Resident
A routine that stays in memory.
Transient
A routine that is loaded as needed.
Transient area
Memory for application programs
and transient routines.
1
1

Most MS-DOS applications are transient.
They load into memory execute terminate
and DOS uses the memory allocated to
the application for the next program the
user executes.
Resident programs follow these same
rules except for the last (not terminate)
A resident program upon termination
does not return all memory back to DOS.
1
2

Instead a part of the program remains resident ready to be
reactivated by some other program at a future time.
Resident programs also known as terminate and stay
resident programs
1
3

When you first boot DOS the memory layout will look
something like the following:
1
4

DOS maintains a free memory pointer that points the
beginning of the block of free memory.
When the user runs an application program DOS loads this
application starting at the address the free memory pointer
contains.
Since DOS generally runs only a single application at a time all
the memory from the free memory pointer to the end of RAM
(0BFFFFh) is available for the application's use:
1
5

When the program terminates normally via DOS function,
MS-DOS reclaims the memory in use by the application and
resets the free memory pointer to just above DOS in low
memory.
1
6

When the user executes a new application DOS loads it into
memory at the new free memory pointer address protecting
the resident program in memory:
1
7

The resident part of the program is the code that remains in
memory and provides whatever functions are necessary
1
8

Instruction execution cycle
Fetch an instruction from memory
Decode instruction
Fetch operands from memory, if needed
Execute instruction
Store results into memory, if necessary
1
9

FETCH DECODE EXECUTE STORE
RELATED MEMORY
MANAGEMENT
TERMINOLOGIES
2
0

SWAPPING
TECHNIQUE
Swapping is a simple memory/process management
technique used by the operating system(os) to increase the
utilization of the processor by moving some blocked process
from the main memory to the secondary memory(hard
disk);thus forming a queue of temporarily suspended process
and the execution continues with the newly arrived process.
After performing the swapping process, the operating system
has two options in selecting a process for execution :
*Operating System can admit newly created process (OR)
*operating system can activate suspended process from the
swap memory.

2
1

FIXED-PARTITION
MEMORY MANAGEMENT
Simplest memory management scheme for
multiprogrammed systems
Divide memory into fixed size partitions,
possibly of different size
Partitions fixed at system initialization time
and may not be changed during system
operation
Single-Partition Allocation
User is provided with an uncovered machine
User has full control of entire memory space

2
2

Advantages
Maximum flexibility to the user.
User controls the use of memory as per his
own desire
Maximum possible simplicity
Minimum cost
No need for special hardware
No need for operating system software

2
3

Disadvantages
No services
OS has no control over interrupts
No mechanism to process system calls and
errors
No space to provide multiprogramming
2
4

DYNAMIC MEMORY
MANAGEMENT
In computer science, dynamic memory
allocation (also known as heap-based memory
allocation) is the allocation of memory storage
for use in a computer program during the
runtime of that program.
It can be seen also as a way of distributing
ownership of limited memory resources among
many pieces of data and code.
2
5

DYNAMIC MEMORY
MANAGEMENT
Dynamically allocated memory exists until it is
released either explicitly by the programmer.
This is in contrast to static memory allocation,
which has a fixed duration.
It is said that an object so allocated has a
dynamic lifetime.
2
6

RUNTIME
The qualifier run time, run-time, runtime, or
execution time refers to the period while a
computer program is actually executed
("run") in a computer, from beginning to
termination.
It may also mean the program's running
time, the duration of that period.
2
7

First-fit strategy
Allocate first hole that is big enough
Stop searching as soon as first hole large enough
to hold the process is found
Example:
Best-fit strategy
Allocate the smallest hole that is big enough
Entire list of holes is to be searched
Search of entire list can be avoided by keeping the
list of holes sorted by size
Worst-fit strategy
Allocate the largest available hole
Similar problems as the best-fit approach
2
8

EXAMPLE
Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how
would each of the First-fit, Best-fit, and Worst-fit algorithms place processes of
212K, 417K, 112K, and 426K (in order)? Which algorithm makes the most
efficient use of memory?
Answer:
First-fit:
a. 212K is put in 500K partition
b. 417K is put in 600K partition
c. 112K is put in 288K partition (new partition 288K = 500K - 212K)
d. 426K must wait

Best-fit:
a. 212K is put in 300K partition
b. 417K is put in 500K partition
c. 112K is put in 200K partition
d. 426K is put in 600K partition

2
9

Worst-fit:
a. 212K is put in 600K partition
b. 417K is put in 500K partition
c. 112K is put in 388K partition
d. 426K must wait

SEGMENTATION
In computing, memory segmentation is one of
the most common ways to achieve memory
protection; another common one is paging.
In a computer system using segmentation, an
instruction operand that refers to a memory
location includes a value that identifies a
segment and an equalize within that segment.
A segment has a set of permissions, and a
length, associated with it.
3
0

In addition to the set of permissions and
length, a segment also has associated with it
information indicating where the segment is
located in memory.
It may also have a standard indicating
whether the segment is present in main
memory or not; if the segment is not present
in main memory, an exception is raised, and
the operating system will read the segment
into memory from secondary storage.
3
1

PAGING
In computer operating systems there are
various ways in which the operating system
can store and retrieve data from secondary
storage for use in main memory.
One such memory management scheme is
referred to as paging.
In the paging memory-management scheme,
the operating system retrieves data from
secondary storage in same-size blocks
called pages.
3
2

The main advantage of paging is that it allows the physical
address space of a process to be non contiguous.
Prior to paging, systems had to fit whole programs into storage
closely which caused various storage and fragmentation
problems.

3
3

Paging is an important part of virtual
memory implementation in most
contemporary general-purpose
operating systems, allowing them to
use disk storage for data that does
not fit into physical RAM.
Paging is usually implemented as
architecture-specific code built into
the kernel of the operating system.
3
4

The main functions of paging are performed when a program
tries to access pages that are not currently mapped to
physical memory (RAM).
This situation is known as a page fault.
The operating system must then take control and handle the
page fault, in a manner invisible to the program.
3
5

Therefore, the operating system must:
Determine the location of the data in auxiliary
storage.
Obtain an empty page frame in RAM to use
as a container for the data.
Load the requested data into the available
page frame.
Update the page table to show the new data.
Return control to the program, transparently
retrying the instruction that caused the page
fault.


3
6

END
3
7

You might also like