59
Memory Management. Subject: Operating System.

Memory Management. Subject: Operating System.. Memory management. In a multiprogramming system, memory must be subdivided to accommodate multiple processes

Embed Size (px)

Citation preview

Memory Management.

Subject: Operating System.

Memory management.

In a multiprogramming system, memory must be subdivided to accommodate multiple processes.

This task of subdivision is carried out dynamically by the OS and is called MEMORY MANAGEMENT.

REQUIREMENTS.

Memory management should satisfy these five requirements:

1. RELOCATION2. PROTECTION3. SHARING4. LOCAL ORGANIZATION5. PHYSICAL ORGANIZATION

RELOCATION.

The processes are swapped in and swapped out.

It is very limiting to place the swapped out process in its original place.

It is then relocated in a different area in the memory.

PROTECTION.

The relocated process must be protected against the unwanted interference.

Protection should be given by the processor rather than the OS.

SHARING.

Any protection mechanism must allow several processor to access the same portion for main memory.

Keeping protection in mind; Sharing should be restricted.

LOGICAL ORGANISATION

Does not correspond to the way in which programs are constructed.

Programs organized in modules.

PHYSICAL ORGANIZATION.

It is divided into two parts:1. Main Memory2. Secondary Memory Main Memory: fast, costly, volatile. Secondary Memory: cheap, slow

but non volatile. Overlaying.

FIXED PARTITIONING.

Divides main memory into a set of non-overlapping regions called partitions.

Partitions can be of equal or unequal sizes.

EQUAL SIZE PARTITIONS

Partitions are of equal size. Process whose size is less than or

equal to the partition size can be loaded into any available partition.

If all partitions are full, the OS can swap a process out of any partition and load the new process

DIFFICULTIES.

Process may be too big to fit into a partition.

Any program, no matter how small, occupies an entire partition causing INTERNAL FRAGMENTATION

UNEQUAL SIZE PARTITIONS

Partitions are not of equal size In Programs with large bytes,

processes can be accommodated without OVERLAYS.

Smaller partitions allow smaller programs to be accommodated with less internal fragmentation.

PLACEMENT ALGORITHM.

Equal size partitions

Unequal size partitions

EQUAL SIZE PARTITIONS.

Process placement is trivial. Process can be loaded in any

partition available. If no partition is available, then

one of the processes must be swapped out.

UNEQUAL SIZE PARTITIONS.

Two ways to assign processes to partition.

Simplest way is to assign a single queue to each partition.

Each process is assign to the smallest partition in which it will fit.

ADVANTAGES.

Internal fragmentation is minimized.

Unequal size partitions

Another approach would be to employ a single queue for all partitions.

Advantage:

Provides a degree of flexibility.

Advantages of fixed partitioning.

Simple.Requires minimal operating system software.

Disadvantage of fixed partitioning

Limits the number of active processesSmall jobs will not utilize partition space efficiently

Example

IBM mainframe operating system, OS/MFT

(multiprogramming with a fixed number of tasks)

Dynamic Partitioning.

Developed to overcome difficulties of fixed partitioning.

Partitions are of variable length and number.

Allocated exactly as much memory as it requires and no more.

Drawbacks.

Method starts well, but eventually leads to holes.

Memory becomes fragmented. Thus, memory utilization

declines. This is referred to as ‘external

fragmentation’.

Ways to overcome….

Technique known as ‘compaction’.

OS shifts process so that all free memory is together in one block.

Thus, an additional process can be loaded.

Time consuming and waste of processor time.

Placement Algorithm.

OS must decide which free block to allocate.

Three placements algorithms:-1. BEST FIT: Chooses block

closest in size to request.

2. FIRST FIT: First available block i.e. large enough.

3. NEXT FIT: Next available block i.e. large enough.

FIRST FIT.

Simplest but usually best and fast.Litters the front end with small partition.

NEXT FIT.

Frequently fragments a free block at the end.Thus, compaction required.

BEST FIT.

Worst performance.Fragment left as small as possible.

Replacement Algorithm.

When processes are blocked and no memory even after compaction.

Replacement algorithm is used to avoid wasting processor time.

OS will swap are process to make room for new process.

OS must choose which process to replace.

BUDDY SYSTEM.

It is a compromise to overcome the drawbacks of fixed and variable partitioning.

RELOCATION.

A process may occupy different partitions during course of its life.

Different regions in memory are allocated at different occasions.

Thus, locations referred by the process is not fixed.

ADDRESSES.

LOGICAL ADDRES. Reference to a memory location

independent of the assignment of the data to memory.

RELATIVE ADDRESS. Address expressed as a location relative

to some known point. PHYSICAL ADDRESS. Actual location in main memory.

PAGING.

Partition memory into small fixed-size chunks and divide each process into the same size chunks.

The chunks of a process are called pages and chunks of memory are called frames

OS maintains a page table for each process.

Page Tables for Example

ADVANTAGES.

Paging is similar to fixed partitioning, only difference is that the partitions here are smaller and a program might occupy more than one partition and they need not be contiguous.

This approach solves many problems inherent partitioning.

DISADVANTAGES.

Waste of space in memory due to internal fragmentation.

No external fragmentation.

SEGMENTATION.

A User program and associated data can be subdivided into a number of segments.

There is a maximum segment length.

Since, segments are not equal, segmentation is similar to dynamic partitioning.

…contd…

Addressing consists of two parts: a segment number and an offset.

It makes use of segment table, for each process and for the list of free blocks of main memory.

ADVANTAGES.

Segmentation provides a convenient way for organizing programs and data.

Segmentation eliminates internal fragmentation.

DISADVANTAGES.

Limitation of maximum segment size.

Segmentation suffers from external fragmentation.

VIRTUAL MEMORY MANAGEMENT.

Allows execution of processes that are not completely in memory.

Separation of logical memory from physical memory.

VIRTUAL ADDRESS SPACE

Refers to the logical (or virtual) view of how a process is stored in memory.

Include holes known as SPARSE ADDRESS SPACE.

Allows files and memory to be shared through page sharing.

VIRTUAL ADDRESS SPACE

DIAGRAM:

Heap

Stack

Data

Code0

Max

DEMAND PAGING

Virtual memory is implemented through demand paging.

A strategy to load pages only as they are needed.

Here we make use of Lazy Swapper.

BASIC CONCEPT.

The VALID-INVALID bit scheme is used.

Access to a page marked invalid causes a PAGE-FAULT TRAP.

PAGE REPLACEMENT

The operating system, swaps out a process, freeing all its frames and reducing the level of multiprogramming.

Page replacement can be done by:1. BASIC PAGE REPLACEMENT.2. FIFO PAGE REPLACEMENT.3. OPTIMAL PAGE REPLACEMENT.4. LRU PAGE REPLACEMENT

BASIC PAGE REPLACEMENT

Here, if no frame is free, we find one that is not currently being used and free it.

It doubles the page-fault service time and increases the effective access time accordingly

FIFO PAGE REPLACEMENT

First-in, First-out (FIFO) Algorithm. Replace the page at the head of

the queue. A bad replacement choice,

increases the page-fault rate and slows process execution.

OPTIMAL PAGE REPLACEMENT

Replace the page that wil not be used for the longest period of time.

It has the lowest page fault rate.

LRU PAGE REPLACEMENT

Least-Recently-Used (LRU) algorithm.

It replaces the page that has been least recently used for the longest time.