CS Presentation template - WordPress.com · Department of Computer Science Memory Management...
Transcript of CS Presentation template - WordPress.com · Department of Computer Science Memory Management...
Department of Computer Science
DCS
COMSATS Institute of Information Technology
Memory Management
Rab Nawaz Khan JadoonAssistant Professor
COMSATS Lahore
Pakistan
Operating System Concepts
Department of Computer Science
Objectives
Primary memory (real memory, physical memory) of computer system has been a major influence on OS design.
Main memory is still expansive compared to secondary storage.
Department of Computer Science
Memory ManagementOperating System Release date Minimum
memory reqRecomm.Memory
Windows 1.0 Nov 1985 256 KB
Windows 2.03 Nov 1987 320 KB
Windows 3.0 Mar 1990 896 KB I MB
Windows 3.1 Apr 1992 2.6 MB 4 MB
Windows 95 Aug 1995 8 MB 16 MB
Windows NT 4.0 Aug 1996 32 MB 96 MB
Windows 98 Jun 1998 24 MB 64 MB
Windows ME Sep 2000 32 MB 128 MB
Windows 2000Professional
Feb 2000 64 MB 128 MB
Windows XP Home
Oct 2001 64 MB 128 MB
Windows XP prof Oct 2001 128 MB 256 MB
Windows Vista Jan 2007 512 MB 1 GB
Windows 7 Oct 2009 1 GB 2 GB
3
Department of Computer Science
Memory Hierarchy
4
Department of Computer Science
Memory Manager
It is the component of the OS concerned with the system’s memory organization scheme and memory management strategies.
It determines, how available memory space is allocated to processes and how to respond to changes in a memory process’s memory usage.
It also interact with special purpose memory management Hardware to improve performance.
5
Department of Computer Science
Memory management strategies
Memory Management
Strategies
Fetch strategies
Demand fetch
Anticipatory fetch
Placement strategies
First fit
Best fit
Worst fit
Replacement strategies
6
Department of Computer Science
Memory Management Strategies cont…
Fetch Strategy
It determines when to move the next piece of a program or data to main memory from the secondary memory.
Demand Fetch
In the conventional methods, the system places the next piece of the code or data in main memory when a running program references it.
That is, programs are loaded into the RAM area when they are needed.
7
Department of Computer Science
Memory Management Strategies cont…
Anticipatory strategy
The program or data which is loaded on the basis of prediction that it will be reference in the near future.
This will increase the performance but if the loaded pages are not used, then there is an inefficient memory utilization.
8
Department of Computer Science
Memory Management Strategies cont…
Placement strategy
It determines where in main memory the system should place incoming program or data pieces.
First Fit Strategy
Place the incoming page into the first available hole in the memory
It is faster but leads to memory waste.
It allows the system to make a placement decision quickly.
Best Fit Strategy
Place the incoming page into the hole in which it fits tight.
Best use of memory space.
It is slower in making allocation.
9
Department of Computer Science
Memory Management Strategies cont…
Worst Fit Strategy
Worst-fit memory allocation is opposite to best-fit.
It allocates free available block to the new job and it is not the best choice for an actual system.
Place the incoming job in the largest available whole
Problem Memory fragmentation Memory
waste.
10
Department of Computer Science
Memory Management Strategies cont…
Replacement strategy
When memory is too full to accommodate a new program, the system must remove some of program or data currently resides in memory.
The system’s replacement strategy determines which piece to remove for making room for incoming jobs.
11
Department of Computer Science
Contiguous vs non contiguous Memory Allocations
To execute a program in the early systems, the OS had to find enough contiguous main memory to accommodate the entire program.
If the program size is larger than the available memory, the program could not execute it.
This is done in contiguous memory allocation, in which all the program pages are loaded into the adjacent memory allocations.
12
Department of Computer Science
Contiguous vs non contiguous Memory Allocations
Non Contiguous Memory Allocation
In noncontiguous memory allocation, a program is divided into blocks or segments, that the system may place in non adjacent slots in main memory
This allows making use of holes (unused gaps) in memory that would be too small to hold whole programs.
The OS thereby incurs more overhead as for as using these unused holes for incoming pages.
13
Department of Computer Science
Quiz
When is noncontiguous preferable to contiguous memory allocation???
14
ANSWER!When the available memory contain no area large enough to hold the incoming programs in one Contiguous space, but sufficient smaller pieces of memory are available, that in total are large enough.
Department of Computer Science
Overlays
Contiguous memory allocation limited the size of programs that could execute on the system
One way in which software designer could overcome the memory limitation was to create overlays, which allowed the system to execute programs larger than main memory.
Programmer divides the program into logical sections.
When the program does not need the memory for one section, the system can replace some or all of its with the memory for a needed section.
Overlays enables a programmer to extend main memory.
15
Department of Computer Science
Overlay structure
16
A
B
C
Operating System
Portion of user code and data than must remain in main memory for duration of execution
User portion with memory requirements larger than available portion of main memory
Initializationphase
Processingphase
Outputphase
Overlay Area
0
a
b
c
b b b
A Load initialization phase at b and run
B Load Processing phase at b and run
C Load Output phase at b and run
Department of Computer Science
Overlay
Managed overlay requires careful and time consuming planning and the programmer often must have detailed knowledge of the system memory organization.
Later on virtual memory system obviate the need for programmer controlled overlays.
17
Department of Computer Science
Protection in single user system
Protection in single user contiguous memory allocation systems can be implemented with a single boundary register built into the processor.
The boundary register contains the memory address at which the user’s program begins.
Each time a process reference a memory address the system determines if the request is for an address greater than or equal to that stored in the boundary register.
If yes, system service the memory request.
Else program is trying to access OS, request is terminated with an error message.
18
Department of Computer Science
Protection in single user system
19
Operating System
User Area
Unused Area
a
Boundary register
Processor
0
a
b
c
Note:Operating System prevents the user from accessing the addresses less than a.
Memory protection with single user contiguous memory allocation
Department of Computer Science
Fixed Partition Multiprogramming
Even with batch processing OSs, a single user systems still wasted a considerable amount of the computing resource.
A processor wait until IO finished. Because IO speeds were extremely slow compared with processor speed, the CPU was severely underutilized.
Designer saw that they could further increase CPU utilization by implementing multiprogramming systems, in which several users simultaneously compete for the system resources.
The process currently waiting for IO yields the processor if another process is ready to do calculation.
20
Department of Computer Science
Fixed Partition Multiprogramming
Thus IO and processing operation done simultaneously.
Greatly increases CPU utilization and system throughput.
To take advantage of Multiprogramming several processes must reside in the computer’s main memory at the same time.
When one process requests IO, the CPU may switch to another process and continue without any delay associated with loading programs from secondary storage.
21
Department of Computer Science
Fixed Partition Multiprogramming
The earlier multiprogramming systems used fixed partition multiprogramming.
In which, system divides main memory into a number of fixed size partitions.
Each partition holds a single job, and the system switches the processor rapidly between jobs to create the illusion of simultaneously.
22
Department of Computer Science
Fixed Partition Multiprogramming
In the early multiprogramming systems, the programmer translated a job using an absolute assembler or compiler (comp. , linking, and loading),
A job had its precise location in memory determined before it was launched and could run only in a specific partition.
This restriction led to wasted memory because the job had to wait for its designated partition (if occupied), even if other partitions were available.
23
Department of Computer Science
Fixed Partition Multiprogramming
24
Operating system
Partition 1
Partition 2
Partition 3
Job Queue for partition 1
Job Queue for partition 2
Job Queue for partition 3
These Jobs run only in partition 1
These Jobs run only in partition 2
These Jobs run only in partition 3
0
a
b
c
d
Fixed partition multiprogramming with absolute translation and loading
Department of Computer Science
Fixed Partition Multiprogramming
25
Operating system
Partition 1
Partition 2
Partition 3(in use)
Job Queue for partition 1
Job Queue for partition 2
Job Queue for partition 3
No jobs waiting for partition 1
0
a
b
c
d
Memory waste under Fixed partition multiprogramming with absolute translation and loading
No jobs waiting for partition 2
Department of Computer Science
Fixed Partition Multiprogramming
26
Operating system
Partition 1
Partition 2
Partition 3
0
a
b
c
d
Job Queue
…..
Fixed partition multiprogramming with relocateable translation and loading
jobs
Department of Computer Science
Memory protection in Multiprogramming
The system can delimit each partition with two boundary registers,
Low and
High
Also called the base and limit register
If a process issues a request for memory, the system checks whether the requested is greater than or equal to the process low boundary register value and less then the high register value.
If so, the system honors the request. Else terminate the request with error.
27
Department of Computer Science
Protection in Multiprogramming
28
Operating system
Partition 1
Partition 2
Partition 3
0
a
b
c
d
2
Low Boundary
Processor
b
c
Currently activepartition
High Boundary
Memory protection in contiguous allocation multiprogramming systems
Department of Computer Science
Fragmentation
One problem prevalent in all memory organizations is that of fragmentation (loss of memory).
This states that certain area of the available RAM that system cannot use.
Fixed partition multiprogramming suffers from internal fragmentation, which occurs when the size of the process’s memory and data is smaller than that of the partition in which the process execute.
29
Department of Computer Science
Fragmentation
30
Operating system
Partition 1
Partition 2
Partition 3
0
a
b
c
d
Used Memory
Unused Memory
Internal Fragmentation in a Fixed Partition Multiprogramming System
Department of Computer Science
Quiz 1
Explain the need for relocating compilers, assemblers and loaders???
31
AnswerBefore such tools, programmer manually specified the partition into whichTheir program had to be loaded, which potentially wasted memory andProcessor utilization and reduce application portability.
Department of Computer Science
Quiz 2
Explain the benefits and drawbacks of large and small partition sizes???
32
AnswerLarger partition allows large program to run, but result in internal fragmentation For small programs. Small partition reduce the amount of internal fragmentation And increase the level of multiprogramming by allowing more programs to reside In memory at once, but limit program size.
Department of Computer Science
Variable Partition Multiprogramming
This scheme allows a process to occupy only as much space as needed (up to the amount of available main memory).
This scheme is called variable partition multiprogramming.
The figure on next slide shows the contiguous allocation schemes where a process must occupy adjacent memory allocations.
The queue at the top contains available jobs and information about their memory requirements.
33
Department of Computer Science
Variable partitioning
34
Department of Computer Science
Holes in variable partitioning
Variable partitioning does not suffer from internal fragmentation, because the process’s partition is exactly the size of the process.
Holes can be created upon process execution / completion.
These holes cannot accommodate the incoming processes which are larger than these available holes.
These holes are called external fragmentation.
35
Department of Computer Science
Memory holes in variable partition multiprogramming
36
Department of Computer Science
Defragmentation Techniques
There are two techniques to overcome the problems of external fragmentation created in variable partitioning system.
The techniques are,
Coalescing (Merging adjacent locations)
Compaction
37
Department of Computer Science
Coalescing Memory Holes
38
Department of Computer Science
Memory compaction Technique
39
Department of Computer Science 40