Operating System - Memory Management - Notes, Study notes for Operating System. Indian Institute of Information Technology (IIIT)

Operating System

Description: Detailed informtion about MEMORY MANAGEMENT, Protection Hardware, Swapping, Memory Partition, Paging, Segmentation.
Showing pages  1  -  2  of  51
The preview of this document ends here! Please or to read the full document or to download it.
Document information
Uploaded by: visir66
Views: 1000+
Downloads : 34
University: Indian Institute of Information Technology (IIIT)
Upload date: 01/09/2011
Embed this document:
Module 7: Process Synchronization

MEMORY MANAGEMENT

OUTLINE

• Basic memory management • Protection Hardware • Swapping • Memory Partition • Paging • Segmentation

Basics of memory

• Memory is required for every operation. • Memory is large array of words or bytes having its

own address. • All instructions are stored in the memory. • As per value of the PC, CPU fetches instructions

from memory.

Memory Management issues

• Basic Hardware issue. • Binding of symbolic memory address to actual

physical address. • Difference between logical address and physical

address • Memory allocation & Deallocation

A typical instruction execution cycle

• First instruction is fetched from memory. • Then it is decoded and as per requirement

operands are also fetched from memory. • Operation is performed on the operands. • Results are stored back to the memory.

Memory Management Task

Problem 1: • Two programs sharing memory simultaneously Problem 2: • One program shouldn’t be allowed to

access/change the memory of another program Problem 3: • Machine may have only 256MB of main memory,

while running a program which needs 600 MB.

Memory Management Task

• Operating system must manage sharing of physical memory between many processes

Basic Memory Hardware.

• Main Memory and registers are directly accessible to the processor.

• There are memory instruction that takes memory addresses as an argument, none of them take disk address.

So every Data and instructions are required to loaded in to these direct access storage devices.

Need of Memory Protection

• Memory Protection is important at the time of memory allocation and deallocation.

MEMORY PROTECTION

• Each Process needs separate memory space. • The overlapping is not allowed. • For separation we need to have

– Base Register – Limit Register For any access to the main memory.

A base and a limit register define a logical address space

Address Binding

• Program must be brought into memory and placed within a process for it to be run

Input queue – collection of processes on the disk that are waiting to be brought into memory to run the program

• User programs go through several steps before being run

Address Binding

• Two type of Addresses – Symbolic Address (Generated by the program for

example requirements like 5 memory blocks etc) – Relocatable address (actual physical position of the

memory block) • Address Binding is required for any execution.

Address Binding

Compile time: • Load time: • Execution time

• 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 vs. Physical Address Space

Memory-Management Unit (MMU)

• Hardware device that maps virtual to physical address In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory The user program deals with logical addresses; it never sees the real physical addresses

Dynamic relocation using a relocation register

18

Modeling Multiprogramming

CPU utilization as a function of number of processes in memory

Degree of multiprogramming

How to get good performance.

• With High Degree of Multi programmability. • More program should be there into main memory. • So memory Swapping is required.

How to get good performance.

• Programs spend much of their time accessing memory, so performance is important!

• Programmers want unlimited fast memory, but – Memory (hardware) has a cost – Faster memory is more expensive

• The solution is to put a fast memory (Cache) Between Processor and main memory.

Memory Hierarchy

• Memory hierarchy – small amount of fast, expensive memory – cache – some medium-speed, medium price main memory – gigabytes of slow, cheap disk storage

• Memory manager handles the memory hierarchy

Memory Hierarchy

CPU Registers

Cache Memory

Primary Memory

Rotating Magnetic Memory

Optical Memory

Sequential Accessed Memory

Executable Memory

Secondary Storage

~500 Bytes

< 10MB

< 1GB

< 100GB (per device)

< 15GB (per device)

< 5GB (per tape)

Primary Memory • Primary Memory Design Requirements

– Minimize access time: hardware and software requirement

– Maximize available memory: using physical and virtual memory techniques

– Cost-effective: limited to a small percentage total

• Memory Manager Functions – Allocate memory to processes – Map process address space to allocated memory – Minimize access times while limiting memory

requirements

Transferring Process from secondary storage to main memory. • Program must be brought into memory and placed

within a process for it to be run • Input queue – collection of processes on the disk

that are waiting to be brought into memory to run the program

• User programs go through several steps before being run

Types of Memory Partition

• Partition memory into regions with fixed boundaries – Equal-size partitions

• program size <= partition • program size > partition size, then must use overlays • Use swapping when no available partitions

– Unequal-size partitions • Main memory use is inefficient, suffers from

Internal Fragmentation

Memory Partition

process 1

Operating System 8 M

12 M

8 M

8 M

6 M

4 M

2 M

Unequal Sized Partitions

8 M

8 M

8 M

8 M

8 M

Operating System

process 1

Unused

Equal Sized Partitions

Placement Algorithm with Partitions

• Equal-size partitions: – any partition may be used since all are equal in size – balance partition size with expected allocation

needs • Unequal-size partitions

– assign each process to the smallest partition within which it will fit. Use per partition process queues.

– processes are assigned in such a way as to minimize wasted memory within a partition (internal fragmentation)

Variable Partitioning

• External Fragmentation - small holes in memory between allocated partitions.

• Partitions are of variable length and number • Process is allocated exactly as much memory as

required • Must use compaction to shift processes so they

are contiguous and all free memory is in one block

Dynamic Loading of Processes

• Processes are not loaded until it is called • Better memory-space utilization; unused routine is

never loaded. • Efficient Swapping is required.

Swapping

• A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution

Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images

Swapping

Roll out, roll in – swapping variant used for priority- based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed

• Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped

• Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows)

Structure of main memory

• Main memory usually into two partitions: – Resident operating system, usually held in low memory

with interrupt vector – User processes then held in high memory

Schematic View of Swapping

Safe memory Allocation

– Relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data

– Relocation register contains value of smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register

A base and a limit register define a logical address space

Contiguous Allocation (Cont.)

• Multiple-partition allocation – Hole – block of available memory; holes of various size

are scattered throughout memory – When a process arrives, it is allocated memory from a

hole large enough to accommodate it – Operating system maintains information about:

a) allocated partitions b) free partitions (hole) OS

process 5

process 8

process 2

OS

process 5

process 2

OS

process 5

process 2

OS

process 5

process 9

process 2

process 9

process 10

Dynamic Storage-Allocation Problem

• How to satisfy a request of size n from a list of free holes

First-fit: Allocate the first hole that is big enough • Best-fit: Allocate the smallest hole that is big

enough; must search entire list, unless ordered by size. Produces the smallest leftover hole.

Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole.

Dynamic Storage-Allocation Problem

• First-fit and best-fit better than worst-fit in terms of speed and storage utilization

Types of Fragmentation

External Fragmentation – total memory space exists to satisfy a request, but it is not in sequence.

Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used

Compaction

Reduce external fragmentation by Compaction – Shuffle memory contents to place all free memory

together in one large block – Compaction is possible only if relocation is dynamic,

and is done at execution time – I/O problem

• Latch job in memory while it is involved in I/O • Do I/O only into OS buffers

Paging

• Paging is a memory management scheme that allows the physical address space to be noncontiguous.

• Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter is available

• Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8192 bytes)

Paging

• Divide logical memory into blocks of same size called pages.

• Keep track of all free frames • To run a program of size n pages, need to find n

free frames and load program • Set up a page table to translate logical to physical

addresses • Internal fragmentation

Paging Example

Paging Example

Paging  Exampl e for a  32 Byte  Memor y with  4 byte  pages.

Free Frames

Before allocation After allocation

Segmentation

• Memory-management scheme that supports user view of memory

• A program is a collection of segments. A segment is a logical unit such as: main program, procedure, function, method, object, local variables, global variables, common block, stack, symbol table, arrays

User’s View of a Program

Logical View of Segmentation

1

3

2

4

1

4

2

3

user space  physical memory space

Segmentation Architecture (Cont.)

Relocation. – dynamic – by segment table

Sharing. – shared segments – same segment number

Allocation. – first fit/best fit – external fragmentation

Example of Segmentation

TYPES OF MEMORY PARTITION

Docsity is not optimized for the browser you're using. In order to have a better experience please switch to Google Chrome, Firefox, Internet Explorer 9+ or Safari! Download Google Chrome