41
Chapter 8 Operating System Support Focus on Architecture

Chapter 8 Operating System Support Focus on Architecture

  • View
    223

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Chapter 8 Operating System Support Focus on Architecture

Chapter 8

Operating System Support

Focus on Architecture

Page 2: Chapter 8 Operating System Support Focus on Architecture

Functions of Operating System

• Managing ResourcesAccess to System UtilitiesAccess to filesAccess to I/O devicesManaging Interrupts & Bus Control (DMA)Error detection and responseAccounting

• Scheduling Processes (or tasks)

Program creationProgram executionI/O Processing

• Managing Memory Utilization Partitioning, Paging, Virtual memory, Segmentation

Page 3: Chapter 8 Operating System Support Focus on Architecture

Types of Operating Systems

What do we want to Optimize in each?

• Interactive

• Batch

• Uni-tasking

• Multi-tasking

• Real-Time

Page 4: Chapter 8 Operating System Support Focus on Architecture

Batch Operating System Resident Monitor

• Jobs are batched in queue

• Monitor handles scheduling

• Monitor controls sequence of events to process batch

•When one job is finished, control returns to Monitor which loads next job

Page 5: Chapter 8 Operating System Support Focus on Architecture

Desirable Hardware Support for OS

• Memory protection— To protect the Monitor & Utilities

• Timer— To prevent a job monopolizing the system

• Privileged instructions— Only executed by Monitor— e.g. I/O, files

• Interrupts— Allows for relinquishing and regaining control

• DMA— Allows for optimizing bus usage

Page 6: Chapter 8 Operating System Support Focus on Architecture

The Case for Multi-programmed Batch Systems

• I/O devices are very slow Waiting is inefficient use of computer

• When one program is waiting for I/O, another can use the CPU

Page 7: Chapter 8 Operating System Support Focus on Architecture

Multi-Programming with Three Programs

Page 8: Chapter 8 Operating System Support Focus on Architecture

Utilization: Uni-programmed vs Multi-programmed

Page 9: Chapter 8 Operating System Support Focus on Architecture

Multiprogramming Resource Utilization

Page 10: Chapter 8 Operating System Support Focus on Architecture

Scheduling

• What are the challenges of scheduling ?

—When do we start a new program ?

—When a program is blocked, what program is executed next?

—When several programs are blocked, which gets first dibs at the resource needed?

—How long can one process monopolize a resource?

Page 11: Chapter 8 Operating System Support Focus on Architecture

How can we model Processing?

A Five State Process Model

Page 12: Chapter 8 Operating System Support Focus on Architecture

Types of Scheduling Needed

Page 13: Chapter 8 Operating System Support Focus on Architecture

Keeping Track of Process Information

If Processes can be interrupted and restarted, what is necessary to be able to stop and restart programs?

Page 14: Chapter 8 Operating System Support Focus on Architecture

Process Control Block Layout

Page 15: Chapter 8 Operating System Support Focus on Architecture

Scheduling Time Sequence Example:

Page 16: Chapter 8 Operating System Support Focus on Architecture

Some Key Elements of O/S

Page 17: Chapter 8 Operating System Support Focus on Architecture

Process Scheduling:

What happened to the Medium-term Queue ?

Page 18: Chapter 8 Operating System Support Focus on Architecture

Memory Management

What are the Memory Management Issues?

• How can we keep the optimum “portions” of programs in memory to optimize the use of the resources ?

• How can we protect one program from corrupting other programs ?

• What do we do when all programs in memory and stalled and memory is full ?

Page 19: Chapter 8 Operating System Support Focus on Architecture

Memory Management• Uni-programming

—Memory split into two—One for Operating System (monitor)—One for currently executing program

• Multi-programming—“User” part is sub-divided and shared among active

processes

• Note: Memory size implications - 16 bits 64K memory addresses - 24 bits 16M memory addresses - 32 bits 4G memory addresses - 64 bits ? memory addresses

Page 20: Chapter 8 Operating System Support Focus on Architecture

Swapping

• Problem: I/O is so slow compared with CPU that even in multi-programming system, CPU can be idle most of the time

• Solutions:— Increase amount of main memory

– Expensive

— Swapping

Page 21: Chapter 8 Operating System Support Focus on Architecture

How Does Swapping Work?

• Long term queue of “processes stored on disk”

• Processes moved in as space becomes available

• As a process completes it is moved out of main memory to make room for other process(es)

• If none of the processes in memory are ready (i.e. all I/O blocked)—Swap out a blocked process (intermediate queue)—Swap in a ready process or a new process

But swapping is an I/O process… Isn’t I/O slow? So why does swapping make sense ?

Page 22: Chapter 8 Operating System Support Focus on Architecture

Implementation of Swapping

Page 23: Chapter 8 Operating System Support Focus on Architecture

Other Structures to help with Memory Management

• Partitioning

• Paging

Page 24: Chapter 8 Operating System Support Focus on Architecture

PartitioningPartitioning: Splitting memory into sections to allocate to processes (including Operating System!)

Fixed Size Partitions:• Equal-sized partitions

—Potentially a lot of wasted memory

• Variable-sized partitions—Process is stored into smallest reasonable “hole”

Dynamic partitions— memory leak— need periodic compaction

Page 25: Chapter 8 Operating System Support Focus on Architecture

Fixed Partitioning

Page 26: Chapter 8 Operating System Support Focus on Architecture

Effect of Dynamic Partitioning – memory leaks

Page 27: Chapter 8 Operating System Support Focus on Architecture

What about Relocation Challenges?

• Can’t expect that process will load into the same place in memory as last time, but

• Instructions contain addresses— For Locations of data— For Addresses for instructions (branching)

• How about having logical address and physical addresses ? — Logical address - relative to beginning of program— Physical address - actual location in memory (this time)

• Mechanisms:— Use Base Address— Automatic (hardware) Conversion

Page 28: Chapter 8 Operating System Support Focus on Architecture

Paging• Split memory into equal sized, “small”

chunks - Page frames

• Operating System maintains list of free frames

• Then:— Allocate the required number page frames to a

process– A process does not require contiguous page frames

— Each process has its own page table

Page 29: Chapter 8 Operating System Support Focus on Architecture

Allocation of Free Frames

Page 30: Chapter 8 Operating System Support Focus on Architecture

Paging Addresses- Logical and Physical

Page 31: Chapter 8 Operating System Support Focus on Architecture

Paging Implementation Issues

• Demand paging—Do not require all pages of a process in

memory—Bring in pages as required

• Page fault—Required page is not in memory—Operating System must swap in required page—May need to swap out a page to make space—Perhaps select page to throw out based on

recent history

Page 32: Chapter 8 Operating System Support Focus on Architecture

Paging has a Potential for “Thrashing”

• Too many processes in too little memory

• Operating System spends all its time swapping

• Little or no real work is done

• Solutions—Good page replacement algorithms—Reduce number of processes running—Add more memory

Page 33: Chapter 8 Operating System Support Focus on Architecture

Virtual Memory• We do not need all pages of a process in memory for

it to run - We can swap in pages only as required

• So - we can now run processes that are bigger than total memory available!

Differentiation “memory models”:• Main memory is called real memory

— physical memory

• User/programmer can see much bigger memory space— virtual memory

Implications:• Page Tables can become huge and can’t fit into

memory —need multiple level tables, or— inverted tables (Why inverted tables ?)

Page 34: Chapter 8 Operating System Support Focus on Architecture

Alternate Inverted Page Table Structure

Page 35: Chapter 8 Operating System Support Focus on Architecture

Problem with Inverted Page Table

• Every virtual memory reference causes two physical memory accesses—Fetch page table entry—Fetch data

• Use Translation Lookaside Buffer— special cache for page table(s)

Page 36: Chapter 8 Operating System Support Focus on Architecture

TLB and Cache Operation (special Cache for tables)

Page 37: Chapter 8 Operating System Support Focus on Architecture

Segmentation

• Segmentation is “partitioning” memory that is visible to the programmer

- Note: Paging is not visible to the programmer

• Usually different segments are allocated to program and data

• There may be a number of program and data segments per process (program)— e.g. to support protection levels, priority

levels, organization, flexibility, etc.

Page 38: Chapter 8 Operating System Support Focus on Architecture

Advantages of Segmentation

• Simplifies handling of growing data structures

• Allows programs to be altered and recompiled independently, without re-linking and re-loading

• Lends itself to sharing among processes

• Lends itself to protection

Can paging and segmentation be combined?

Page 39: Chapter 8 Operating System Support Focus on Architecture

Example: Pentium II Address Translation Mechanism

“Segment” uses 2 bits to provide 4 levels of protection, typically:

0: OS kernel, 1: OS, 2: apps needing special security, 3: general apps

Page 40: Chapter 8 Operating System Support Focus on Architecture

Pentium II (Uses hardware for segmentation & paging)

• Unsegmented, unpaged— virtual address = physical address— Used in Low complexity, High performance systems

• Unsegmented, paged— Memory viewed as paged linear address space— Protection and management via paging (Ex: Berkeley UNIX)

• Segmented, unpaged— Collection of local address spaces— Protection to single byte level, Translation table needed is on chip

when segment is in memory, provide predictable access times

• Segmented, paged— Segmentation used to define logical memory partitions subject to

access control— Paging manages allocation of memory within partitions (Ex: Unix

System V)

Page 41: Chapter 8 Operating System Support Focus on Architecture

Scheduling:

uni-programming

multi-programmingtime-sharing

long-term scheduler (queue of all jobs potentially schedulable)short-term scheduler (queue of processes that are ready to execute)medium-term scheduling (queue of jobs that can reside in memory)blocked monitoring (queue of processes blocked for resources)

new – ready – running – blocked – exit state machine

Memory management:partitioningpaging – frames, pages, page fault, page table, logical/physical addrvirtual memory – inverted page table, Translation Lookaside Buffersegmentation

OS Review