6 memory management and processor management management of resources measure of effectiveness – on...

60

Upload: ruby-wilcox

Post on 16-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves
Page 2: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

66Memory Management

and

Processor Management

Page 3: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Management ofManagement ofResourcesResources

Measure of Effectiveness– On most modern computers, the operating

system serves as the primary resource manager allocating and managing:

Processor Time Memory Space Peripheral Devices Secondary Storage Space Data Program Libraries

Page 4: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Management ofManagement ofResourcesResources

Measure of Effectiveness– A well-designed operating system attempts to

optimize the utilization pf all the system resources.

– Resource management is a key operating system function.

– The operating system’s job is to manage the computer system’s resources as efficiently as possible.

Page 5: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Processor ManagementProcessor Management

Processor Management– Concerned with managing the processor’s time.

Page 6: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory Management

Memory Management– Concerned with managing the computer’s

available pool of memory: Allocating space to application routines and making

sure that they do not interfere with each other.

Page 7: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Operating System Operating System Management RoutinesManagement Routines

Resident– A routine that stays in memory because it directly

supports application programs as they run.

Transient– A routine that is loaded as needed.

Transient area– Memory for application programs and transient

routines.

Page 8: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.2: Fig. 6.2: The The operating operating system system (Resident & (Resident & Transient Transient Routines) Routines) occupies low occupies low memory. The memory. The remaining remaining memory is the memory is the transient area.transient area.

System control information

Resident Operating System

And

Transient Routines

Transient area

Page 9: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementPartitions and RegionsPartitions and Regions

Page 10: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Overlay StructuresOverlay Structures

Developed when the amount of available memory was limited.

Divide the program into logically independent modules.– Module 1 holds the main control logic and key data

common to the entire program.– Module 2 processes valid input data.– Module 3 processes errors.– Module 4 generates end-of-program statistics.

Page 11: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.9a: Fig. 6.9a: Overlay structures. The Overlay structures. The complete program consists of four complete program consists of four modules. modules.

M o d u le 1 : M a in co n tro l a n d k ey d a ta

M o d u le 2 : N o rm a l d a ta p ro cess in g lo g ic

M o d u le 3 : E rro r p ro cess in g

M o d u le 4 : E n d -o f-jo b su m m a ry co m p u ta tio n s

Page 12: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.9b: Fig. 6.9b: Normally, only Normally, only modules 1 and 2 are in modules 1 and 2 are in memory.memory.

M o d u le 1 : M a in co n tro l a n d k ey d a ta

M o d u le 2 : N o rm a l d a ta p ro cess in g lo g ic

Page 13: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.9c: Fig. 6.9c: When an error When an error occurs, module 3 overlays occurs, module 3 overlays module 2.module 2.

M o d u le 1 : M a in co n tro l a n d k ey d a ta

M o d u le 3 : E rro r p ro cess in g

Page 14: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.9d: Fig. 6.9d: At end-of-job, only At end-of-job, only modules 1 and 4 are needed.modules 1 and 4 are needed.

M o d u le 1 : M a in co n tro l a n d k ey d a ta

M o d u le 4 : E n d -o f-jo b su m m a ry co m p u ta tio n s

Page 15: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory Management Memory Management ConcurrencyConcurrency

A program cannot process data it does not have.

A program spends more time waiting for I/O than processing data.

Page 16: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory Management Memory Management ConcurrencyConcurrency

Resolution – – Put a additional programs into memory.– Where ?– How ?

Page 17: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.3: Fig. 6.3: Multiple Multiple programs are programs are loaded and loaded and executed executed concurrently.concurrently.

Where?????Where?????

How?????How?????

Run Wait Run Wait Run

Wait RunWait Run Wait

Wait Run Wait

Program A

Program B

Program C

Page 18: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementPartitions and RegionsPartitions and Regions

Fixed-Partition Memory ManagementRegions – Dynamic Memory Management.

Page 19: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementPartitions Partitions

Fixed-Partition Memory Management– Divides the available space into fixed-length

partitions– Each partition can execute a program– Partition size is set when the operating system

is generated.

Page 20: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.4: Fig. 6.4: Fixed-Fixed-partition partition memory memory management management divides the divides the available space available space into fixed-into fixed-length length partitions. partitions.

O p era tin g sy stem

P a rtitio n A

P a rtitio n B

P a rtitio n C

P a rtitio n D

Page 21: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementPartitionsPartitions

Fragmentation occurs because– With Fixed-Partition Memory Management

It is assumed that a given program must be loaded into contiguous memory.

Not all the space assigned to a partition may be used

Page 22: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementRegionsRegions

Regions - Dynamic Memory Management – The transient area is treated as a pool of free

space– When a program needs to be executed

A region of memory just sufficient to hold the program is allocated from the transient pool

The program is loaded into this region

Page 23: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.5:Fig. 6.5:Under Under dynamic dynamic memory memory management, a management, a region of region of memory just memory just sufficient to sufficient to hold the hold the program is program is allocated when allocated when the program is the program is loaded. loaded.

O p era tin g sy stem

O th er reg io n s

2 5 0 K reg io n

3 0 0 K reg io n

U n u sed 9 0 K fra g m en t

O th er reg io n s

Page 24: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementRegionsRegions

Fragmentation occurs because– With Dynamic Memory Management

It is assumed that a given program must be loaded into contiguous memory.

With dynamic allocation, bits of unused space is spread throughout memory.

Page 25: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementRegionsRegions

Regions - Dynamic Memory Management – Utilizes:

Segmentation Paging

Page 26: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementRegionsRegions

Segmentation:– Programs are divided into independently

addressed segments and stored in non-contiguous memory.

Page 27: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementSegmentationSegmentation

When a program is loaded into memory:– the operating system builds a segment table for

the program listing the absolute entry point address of each of the program’s segments.

– As the program executes, addresses must be translated from relative to absolute form.

Base + Displacement Segment + Displacement

Page 28: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.6: Fig. 6.6: With With segmentation, segmentation, programs are programs are divided into divided into independently independently addressed addressed segments and segments and stored in stored in noncontiguous noncontiguous memory.memory.

O p era tin g sy stem

O th er p ro g ra m s

P ro g ra m A , seg m en t 0

O th er p ro g ra m s

P ro g ra m A , seg m en t 1

P ro g ra m A , seg m en t 2

O th er p ro g ra m s

O th er p ro g ra m s

Page 29: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.7: Fig. 6.7: Dynamically Dynamically translating a segment translating a segment address to an absolute address to an absolute address.address.

Segment Start address

0 aaa1 bbb2 ccc

Base Displacement

Segment Displacement

Segment 0

Segment 1

Segment 2

Expand

Segment start addressplus displacement equalsabsolute segment address

Page 30: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementPagingPaging

A program is broken into fixed-length pages (2k – 4K)

The pages are loaded into noncontiguous memory. As the pages are loaded into memory, a page table

is created. Page Addresses:

– Page Number – Page Displacement

Page 31: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.7: Fig. 6.7: Dynamically Dynamically translating a page translating a page address to an absolute address to an absolute address.address.

Page Start address

0 aaa1 bbb2 ccc

Base Displacement

Page Displacement

Page 0

Page 1

Page 2

Expand

Page start addressplus displacement equalsabsolute page address

Page 32: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementSegmentation and PagingSegmentation and Paging

Addresses are divided into:– A segment number– A page number within that segment– A displacement within that page

After the ICU expands the relative address:– The program’s segment table is searched for the segment

number which yields the address of the segment’s page table

– The page table is searched for the page’s base address which is added to the displacement to get an absolute address.

Page 33: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.8: Fig. 6.8: Segmentation Segmentation andand paging. paging.

Segment Page tableaddress

0 aaa1 bbb2 ccc

Base Displacement

Segment Page Displacement

Expand

Segment 0 page table

Page Real address0 xxx1 yyy2 zzz

Segment 1 page table

Page Real address0 nnn1 mmm

Segment 2 page table

Page Real address0 rrr1 sss2 ttt

Absolute address equalsreal page address plusdisplacement

1

2

3

4

Page 34: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Virtual MemoryVirtual Memory

Page 35: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementVirtual MemoryVirtual Memory

Three Levels of Storage– Real Memory

Main memory, directly addressable by the processor

External Paging Device– Disk– Virtual Memory

Acts just like real memory, but isn’t real memory.

Page 36: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.10: Fig. 6.10: Virtual Virtual memory.memory.

Available directaccess storage

Virtual programpartitions or

regions

Available directaccess storage

Resident operatingsystem

Page pool

Resident operatingsystem

Page pool

Virtual programpartitions or

regions

Virtual memory Real memory External paging device

Page 37: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementVirtual MemoryVirtual Memory

Divides main storage into 2K sections called page frames. Divides all programs into 2K sections called pages. When the operating system loads a program for execution,

it first divides the program into pages and stores the pages on a disk file called the PAGE DATA SET.

The operating system then loads the pages of the program that are initially active into main (real) storage.

When a part of the program which is not in real storage is needed, a PAGE FAULT occurs. The operating system loads the page containing that code into real storage.

Page 38: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementVirtual MemoryVirtual Memory

When real storage is completely filled with active pages and another page is needed in real storage:

The operating system selects a page that has been in real storage the longest without being referenced;

Writes it back on the Page Data Set (page-out) if the contents of the page have been changed since it was first brought into realstorage;

Brings in the new page into real storage (page-in).

Page 39: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Memory ManagementMemory ManagementVirtual MemoryVirtual Memory

Virtual address dynamically translatedThrashing

– excessive paging– Seriously degrades system performance

Page 40: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

MultiprogrammingMultiprogramming

Interrupt– An electronic signal– A program surrenders control of the processor

when it requests an I/O operation and is eligible to continue when the I/O operation is completed.

Page 41: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

MultiprogrammingMultiprogramming

Interrupts can originate with:– Software

A program issues an interrupt to request the operating system’s support Hardware for an I/O operation

– Hardware Hardware issues an interrupt to notify the processor

that an asynchronous event has occurred.

– Illegal operations

Page 42: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

MultiprogrammingMultiprogramming

Control Block– Created to hold a partition’s key control flags,

constants, and variables.– Linked to form a linked list– The Dispatcher determines which program is to

start by following the chain of pointers from control block to control block.

Page 43: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Scheduling and QueuingScheduling and Queuing

As programs enter the system, they are placed on a queue by the queuing routine.

When space becomes available, the scheduler selects a program from the queue and loads it into memory.

Page 44: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.16: Fig. 6.16: Queuing and Queuing and scheduling.scheduling.

O p era tin g sy stem

Q u eu in g ro u tin e

S ch ed u ler

P ro g ra m p a r titio n

P ro g ra m p a r titio n

P ro g ra mq u eu e

1

2

Page 45: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.13: Fig. 6.13: The The dispatcher dispatcher decides which decides which program to start program to start by following a by following a linked list of linked list of control blocks.control blocks.

O p era tin g sy stem

P a rtitio n A

P a rtitio n Aco n tro l b lo ck

P a rtitio n B

P a rtitio n Bco n tro l b lo ck

P a rtitio n C

P a rtitio n Cco n tro l b lo ck

Page 46: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.12: Fig. 6.12: The operating system’s The operating system’s dispatcher decides which ready program dispatcher decides which ready program executes first.executes first.

Run Wait Ready

Wait Run Ready

Program A

Program B

I/O operation

Page 47: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.14a: Fig. 6.14a: The program The program issues an issues an interrupt, interrupt, requesting the requesting the operating operating system’s system’s support.support.

O p era tin g sy stem

P ro g ra m A

P ro g ra m B

D isp a tch er

In terru p th a n d ler ro u tin e

L in k ed lis t o fco n tro l b lo ck s

P rog ram S ta teA R e a d yB R e a d y

C h a n n e l

D isk

In terru p t

Page 48: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.14b: Fig. 6.14b: TThe interrupt he interrupt handler sets handler sets the program the program to a wait to a wait state.state.

O p era tin g sy stem

P ro g ra m A

P ro g ra m B

D isp a tch er

In terru p th a n d ler ro u tin e

L in k ed lis t o fco n tro l b lo ck s

P rog ram S ta teA W a itB R e a d y

C h a n n e l

D isk

Page 49: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.14c: Fig. 6.14c: After the After the Interrupt Interrupt Handler Handler Routine starts Routine starts the requested the requested I/O operation, I/O operation, the dispatcher the dispatcher starts another starts another application application program.program.

O p era tin g sy stem

P ro g ra m A

P ro g ra m B

D isp a tch er

In terru p th a n d ler ro u tin e

L in k ed lis t o fco n tro l b lo ck s

P rog ram S ta teA W a itB R e a d y

C h a n n e l

D isk

Page 50: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.14d: Fig. 6.14d: The channel The channel signals the signals the end of the end of the I/O operation I/O operation by sending by sending the the processor an processor an interrupt.interrupt.

O p era tin g sy stem

P ro g ra m A

P ro g ra m B

D isp a tch er

In terru p th a n d ler ro u tin e

L in k ed lis t o fco n tro l b lo ck s

P rog ram S ta teA W a itB R e a d y

C h a n n e lIn terru p t

D isk

Page 51: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.14e: Fig. 6.14e: Following the Following the interrupt, the interrupt, the interrupt interrupt handler handler routine routine resets resets program A to program A to a ready a ready state.state.

O p era tin g sy stem

P ro g ra m A

P ro g ra m B

D isp a tch er

In terru p th a n d ler ro u tin e

L in k ed lis t o fco n tro l b lo ck s

P rog ram S ta teA R ea d yB R e a d y

C h a n n e l

D isk

Page 52: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.14f: Fig. 6.14f: After the After the interrupt is interrupt is processed, processed, the the dispatcher dispatcher selects an selects an application application program and program and starts it.starts it.

O p era tin g sy stem

P ro g ra m A

P ro g ra m B

D isp a tch er

In terru p th a n d ler ro u tin e

L in k ed lis t o fco n tro l b lo ck s

P rog ram S ta teA R ea d yB R e a d y

C h a n n e l

D isk

Page 53: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.11: Fig. 6.11: Pages are Pages are swapped between the swapped between the external paging device external paging device and the real-memory and the real-memory page pool.page pool.

Available directaccess storage

Virtual programpartitions or

regions

Available directaccess storage

Resident operatingsystem

Page pool

Real memory External paging device

Paging

Page 54: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Time-SharingTime-Sharing

Managing multiple concurrent users designed with interactive processing in mind.

Roll-in/roll-out memory managementDispatching

– Time-slicing– Polling

Page 55: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Time-SharingTime-Sharing

Roll-in/roll-out memory management– Executing a series of brief transactions– As a given transaction is processed, the system knows

that considerable time will pass before that next user’s transaction arrives.

– The workspace is rolled out to secondary storage, making room for another application in memory.

– When the first user’s next transaction arrives, his/her workspace is rolled back in.

Page 56: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Time-SharingTime-Sharing

Time-Slicing– Each program is restricted to a maximum slice

of time– Once a program begins executing, it runs until

The program requires input or output before exhausting its time slice.

– Sends an I/O interrupt to the operating system

– Drops into a wait state.

Page 57: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Time-SharingTime-Sharing

Time-Slicing– Once a program begins executing, it runs until

The program requires input or output before exhausting its time slice.

The program uses up its entire time slice– Sends an I/O interrupt to the operating system

– Drops into a wait state.

– The dispatcher starts the next program.

Page 58: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

Fig. 6.15: Fig. 6.15: Polling.Polling.

D isp a tch er

P ro g ra m S ta tu s

1 W a it2 R e a d y3 W a it4 W a it5 R e a d y6 W a it7 R e a d y8 R e a d y

Page 59: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

SpoolingSpooling

Copying data from a slow input device to disk for subsequent processing.

Copying data to disk for subsequent output to a slow device such as a printer.

Page 60: 6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves

DeadlockDeadlock

Two (or more) programs each control a resource needed by the other.

Neither program can continue without the needed resource.

Neither program will surrender its control.