chapter 7 operating system support - yonsei...
TRANSCRIPT
YonseiYonsei UniversityUniversity
Chapter 7Chapter 7
Operating SystemOperating SystemSupportSupport
YonseiYonsei UniversityUniversity7-2
• Operating System Overview• Scheduling• Memory Management• Pentium II and PowerPC Memory Management
Contents Contents
YonseiYonsei UniversityUniversity7-3
• OS is a program that– Manages the computer’s resources, provides
services for programmers – Schedules the execution of other programs
• Objective– Convenience
• Makes a computer more convenient– Efficiency
• Allows the computer system resources to be used in a efficiency manner
OS Objectives & FunctionsOS Objectives & Functions Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-4
• To ease a complex task, a set of systems program is provided
• Some of programs are referred to as utilities• These implement use functions that assist
in program creation, the management of files, the control of I/O devices
• Programmers make use of these facilities in developing an application
• OS provides a programmer with a convenient interface for using the system
OS : User/Computer InterfaceOS : User/Computer Interface Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-5
Layers of a Computer SystemLayers of a Computer System Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-6
• Program Creation– Assists the programmer in creating programs
• Program execution– Handles program execution for user
• Access to I/O devices• Controlled access to files• System access
– Access to the system as a whole and to specific system resource
• Error detection and response• Accounting
OS ServicesOS Services Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-7
• OS functions in the same way ordinary computer software; it is a program executed by the processor
• OS frequently relinquishes control and must depend on the processor to allow it to regain control
OS : Resource ManagerOS : Resource Manager Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-8
• The OS is nothing more than a computer program
• The OS directs the processor in the use of the other system resources and in timing of its execution of other programs
• Kernel, nucleus – Contains the most frequently used functions in
operating system and at a given time, other portions of the operating system currently in use
• The OS decides when an I/O device can be used by a program in execution, and controls access to and use of files
OS : Resource ManagerOS : Resource Manager Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-9
OS : Resource ManagerOS : Resource Manager Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-10
• Interactive system– User/programmer interacts directly with the computer,
usually through a keyboard/display terminal, the request the execution of a job or to perform a transaction
• Batch system(opposite of interactive)– User’s program is batched together with programs
from other users and submitted by a computer operator
• Independent dimension specifies whether the system employs multiprogramming or not
• Alternative is a uniprogramming system that work only one program at a time
Types of Operating SystemsTypes of Operating Systems Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-11
• Early computer(late 1940 to the mid-1950)– No operating system– The processor were run from a console– The program in processor code were loaded via input
device
• Two main problems– Scheduling– Setup time
Early SystemsEarly Systems Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-12
• Early processors were very expensive • It was important to maximize processor
utilization• Monitor : Simple batch operating systems• Batch : Job together sequentially• From the point of view of the monitor, it is the
monitor that controls the sequence of events• Resident monitor• When the job is completed, it returns control
to the monitor, which immediately reads in the next job
Simple Batch SystemsSimple Batch Systems Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-13
Memory LayoutMemory Layout Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-14
Simple Batch SystemsSimple Batch Systems• At a certain point in time, the processor is
executing instructions from the portion of main memory containing the monitor
• These instructions cause the next job to be read in to another portion of main memory
• Monitor handles the scheduling problem• How about the job setup time?
– The monitor handles this as well
• Job control language(JCL)– Used to provide instructions to the monitor
Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-15
Overall Format of JobOverall Format of Job
$JOB$FTN...$LOAD$RUN...$END
Operation System OverviewOperation System Overview
InstructionsInstructions
DataData
YonseiYonsei UniversityUniversity7-16
Simple Batch SystemsSimple Batch Systems• Hardware features• Memory protection
– While the user program is executing, it must not alter the memory area containing the monitor
• Timer– Prevent a single job from monopolizing the system
• Privileged instructions– Executed only by the monitor
• Interrupts– Flexibility in relinquishing control to and regaining
control from user programs
Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-17
MultiprogrammedMultiprogrammed Batch SystemBatch System• The processor is often idle• The problem is that I/O devices are slow• Suppose that there is room for the operating
system and two user programs• When one job needs to wait for I/O, the
processor can switch to the other job, which likely is not waiting for I/O
Operation System OverviewOperation System Overview
System Utilization Example
Percent CPU util = 0.0001/0.0031 = 0.032 = 3.2 %
0.0031 secondsTOTAL
0.0015 secondsWrite one record
0.0001 secondsExecute 100 instructions
0.0015 secondsRead one record
YonseiYonsei UniversityUniversity7-18
Multiprogramming ExampleMultiprogramming Example Operation System OverviewOperation System Overview
• Uniprogramming
YonseiYonsei UniversityUniversity7-19
Multiprogramming ExampleMultiprogramming Example Operation System OverviewOperation System Overview
• Multiprogramming with two programs
YonseiYonsei UniversityUniversity7-20
Multiprogramming ExampleMultiprogramming Example Operation System OverviewOperation System Overview
• Multiprogramming with two programs
YonseiYonsei UniversityUniversity7-21
Program Execution AttributesProgram Execution Attributes
YesNo NoNeed printer?
NoYesNo Need terminal?
YesNoNoNeed disk?
80K100K50KMemory required
10 min15 min5 minDuration
Heavy I/OHeavy I/OHeavy computeType of jog
JOB3JOB2JOB1
Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-22
10 min18 min Mean response time
12 jobs/h6 jobs/hThroughput rate
15 min30 minElapsed time
67%33%Printer use
67%33%Disk use
67%30%Memory use
33%17%Processor use
MultiprogrammingUniprogramming
Effects of MultiprogrammingEffects of Multiprogramming Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-23
UniprogrammingUniprogramming UtilizationUtilization Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-24
Multiprogramming UtilizationMultiprogramming Utilization Operation System OverviewOperation System Overview
YonseiYonsei UniversityUniversity7-25
• User interface acts directly with the computer• Such as transaction processing, an interactive
mode is essential• Multiprogramming can be used handle multiple
interactive jobs
TimeTime--Sharing SystemsSharing Systems Operation System OverviewOperation System Overview
Command entered at the terminal
Job control language instructions provided with the job
Source of instructions to operating system
Minimize response timeMaximize processor usePrincipal objective
Time SharingBatch Multiprogramming
YonseiYonsei UniversityUniversity7-26
• Process – A program in execution– The “animated spirit”of a program– That entity to which a processor is assigned
SchedulingScheduling SchedulingScheduling
The decision as to which process’s pending I/O request shall be handled by an available I/O deviceI/O scheduling
The decision as to which available process will be executed by the processor
Short-term scheduling
The decision to add to the number of processes that are partially or fully in main memory
Medium-term scheduling
The decision to add to the pool of processes to be executed
Long-term scheduling
YonseiYonsei UniversityUniversity7-27
• Determines which programs are admitted to the system for processing
• Controls the degree of multiprogramming• Once admitted, a job or user program
becomes a process and is added to the queue for the short-term scheduler
• Newly created process begins in a swapped-out condition, in which case it is added to a queue for the medium-term scheduler
• Decides that the operating system can take on one or more additional processes
• Decides which job or jobs to accept and turn into processes
Long Term SchedulingLong Term Scheduling SchedulingScheduling
YonseiYonsei UniversityUniversity7-28
• Part of the swapping function• Swapping-in decision is based on the need
to manage the degree of multiprogramming• On a system that does not use virtual
memory, memory management is also an issue
MediumMedium--Term SchedulingTerm Scheduling SchedulingScheduling
YonseiYonsei UniversityUniversity7-29
• Dispatcher• Fine-grained decision of which job to execute
next
ShortShort--Term SchedulingTerm Scheduling SchedulingScheduling
YonseiYonsei UniversityUniversity7-30
• State – Status at any point in time– Used because it connotes that certain information
exists that defines the status at that point– New
• Program is admitted by the high-level scheduler but is not yet ready to execute
– Ready• Process is ready to execute
– Running• Process is being executed
– Waiting• Process is suspended
– Halted
Process StatesProcess States SchedulingScheduling
YonseiYonsei UniversityUniversity7-31
FiveFive--State Process ModelState Process Model SchedulingScheduling
YonseiYonsei UniversityUniversity7-32
Process Control BlockProcess Control Block• Identifier• State• Priority• Program Counter• Memory pointers• Context data
– Present in registers in the processor
• I/O status information• Accounting information
SchedulingScheduling
identifieridentifier
StateState
PriorityPriority
Program counterProgram counter
Memory PointerMemory Pointer
Context DataContext Data
I/O StatusI/O StatusInformationInformation
AccountingAccountingInformationInformation
..
..
YonseiYonsei UniversityUniversity7-33
Scheduling TechniquesScheduling Techniques• Begin at a point in time process A is running• The processor is executing instructions from
the program contained in A’s memory• The processor ceases to execute instructions
in A and begins executing instructions• Three reasons
– Process A issues a service call to the OS– Process A causes an interrupt– Some event unrelated to process A that requires
attention causes an interrupt
SchedulingScheduling
YonseiYonsei UniversityUniversity7-34
Scheduling ExampleScheduling Example SchedulingScheduling
YonseiYonsei UniversityUniversity7-35
OS QueueOS Queue• Long-term Queue
– List of jobs waiting to use the system– High-level scheduler will allocate memory and create a
process for one of the waiting items
• Short-term Queue– All processes in the ready state– One of these process could use the processor next– Priority levels may also be used
• I/O Queue– I/O queue for each I/O device– More than one process may request the use of the
same I/O device
SchedulingScheduling
YonseiYonsei UniversityUniversity7-36
OS for MultiprogrammingOS for Multiprogramming SchedulingScheduling
YonseiYonsei UniversityUniversity7-37
Queuing Diagram RepresentationQueuing Diagram Representation SchedulingScheduling
YonseiYonsei UniversityUniversity7-38
Memory ManagementMemory Management• In a uniprogramming system,
– Main memory is divided into two parts: • The operating system(resident monitor)• The program currently being executed
• In a multi programming system,– The “user”part of memory is subdivided to
accommodate multiple processes
• The task of subdivision is carried out dynamically by the OS and is known as memory management
Memory managementMemory management
YonseiYonsei UniversityUniversity7-39
SwappingSwapping• I/O activities are much slower than
computation and therefore the processor in a uniprogramming system is idle most of the time
• Main memory could be expanded and so be able to accommodate more processes
• 2 Flaws– First, main memory is expensive– Second, the appetite of programs for memory has
grown as fast as the cost of memory has dropped
• The solution is swapping
Memory managementMemory management
YonseiYonsei UniversityUniversity7-40
SwappingSwapping• Long-term queue of process requests,
typically stored on disk• These are bought in, one at a time, as space
becomes available• Rather than remain idle, the processor swaps
one of these processes back out to disk into an intermediate queue
• This is a queue of existing processes that have been temporarily kicked out of memory
• OS brings in another process form the interface another process form the intermediate queue
Memory managementMemory management
YonseiYonsei UniversityUniversity7-41
SwappingSwapping
• Swapping is an I/O operation, therefore there is the potential for making the problem worse, not better
• Because disk I/O is generally the fastest I/O on a system(compared with tape or printer I/O), swapping will usually enhance performance
Memory managementMemory management
YonseiYonsei UniversityUniversity7-42
Use of SwappingUse of Swapping Memory managementMemory management
((a)Sample Job Schedulinga)Sample Job Scheduling
YonseiYonsei UniversityUniversity7-43
Use of SwappingUse of Swapping Memory managementMemory management
((b)Swappingb)Swapping
YonseiYonsei UniversityUniversity7-44
PartitioningPartitioning• Simplest scheme for partitioning available
memory is to use fixed-size partitions• Although the partitions are of fixed size, they
need not be of equal size• When a process is brought into memory, it is
placed in the smallest available partition that will hold it
• Even with the use of unequal fixed-size partitions, there will be wasted memory
Memory managementMemory management
YonseiYonsei UniversityUniversity7-45
Fixed PartitioningFixed Partitioning Memory managementMemory management
(a)Equal-size partitions
YonseiYonsei UniversityUniversity7-46
(b)Unequal-size partitions
Fixed PartitioningFixed Partitioning Memory managementMemory management
YonseiYonsei UniversityUniversity7-47
PartitioningPartitioning• More efficient approach is to use variable-size
partitions• Allocated exactly as much memory as it
requires• Memory becomes more and more fragmented,
and memory utilization declines• Compaction
– Operating system shifts the processes in memory to place all the free memory together in one block
– This is a time-consuming procedure, wasteful of processor time
Memory managementMemory management
YonseiYonsei UniversityUniversity7-48
Effect of Dynamic PartitioningEffect of Dynamic Partitioning Memory managementMemory management
YonseiYonsei UniversityUniversity7-49
Effect of Dynamic PartitioningEffect of Dynamic Partitioning Memory managementMemory management
YonseiYonsei UniversityUniversity7-50
• The process is not likely to be loaded into the same place in main memory each time it is swapped in
• If compaction is used, a process may be shifted while in main memory
• The process in memory consists of instruction plus data
• The instructions will contain addresses for memory locations of two types– Addresses of data items– Addresses of instructions used for branching
instruction
PartitioningPartitioning Memory managementMemory management
YonseiYonsei UniversityUniversity7-51
PartitioningPartitioning• Addresses are not fixed• They will change each time a process is
swapped in• To solve this problem, a distinction is made
between logical addresses and physical addresses– Logical address
• A location relative to the beginning of the program– Physical address
• Actual location in memory
• Automatically converts from logical to physical address
Memory managementMemory management
YonseiYonsei UniversityUniversity7-52
PagingPaging• Memory is partitioned into equal fixed-size
chunks• Chunk of a program, known as pages, could
be assigned to available chunks of memory, known as frames, or page frames
• Wasted space in memory for that process is a fraction of the last page
• The list of free frames is maintained by the operating system
Memory managementMemory management
YonseiYonsei UniversityUniversity7-53
Allocation of Free FramesAllocation of Free Frames Memory managementMemory management
YonseiYonsei UniversityUniversity7-54
Paging Paging • The OS maintains a page table for each
process• The page table show the frame location for
each page of the process• Main memory is divided into many small
equal-size frames• Each process is divided into frame-size pages• Smaller processes require fewer pages, larger
processes require more
Memory managementMemory management
YonseiYonsei UniversityUniversity7-55
Logical and Physical AddressesLogical and Physical Addresses Memory managementMemory management
YonseiYonsei UniversityUniversity7-56
Virtual MemoryVirtual Memory Memory managementMemory management
• Demand Paging• Page Table Structure
YonseiYonsei UniversityUniversity7-57
• Each page of a process is brought in only when it is needed(on demand)
• If the program branch to an instruction on a page not in main memory, if the program references data on a page not in memory, a page fault is triggered
• Only a few pages of any given process are in memory
• When it brings one page in, it must throw another page out
• Thrashing– Processor spends most of its time swapping pages
rather than executing instructions
Demand PagingDemand Paging Memory managementMemory management
YonseiYonsei UniversityUniversity7-58
Demand PagingDemand Paging• Operating system tries to guess, based on
recent history, which pages are least likely to be used in the near future
• It is possible for a process to be larger than all of main memory
• Because a process executes only in main memory, that memory is referred to as real memory
• Programmer or user perceives a much larger memory – that which is allocated on the disk
• Virtual memory
Memory managementMemory management
YonseiYonsei UniversityUniversity7-59
Page Table StructurePage Table Structure• The basic mechanism for reading a word from
memory involves the translation of a virtual, or logical, address, consisting of frame number and offset, into a physical address, consisting of frame number and offset, using a page table
• The page number is used to index that table and look up the corresponding frame number
• The page number portion is mapped into a hash table using a simple hashing function
• The hash table contains a pointer to inverted page table, which contains the page table entries
Memory managementMemory management
YonseiYonsei UniversityUniversity7-60
Inverted Page Table StructureInverted Page Table Structure Memory managementMemory management
YonseiYonsei UniversityUniversity7-61
Translation Translation LookasideLookaside Buffer Buffer • Two physical memory accesses
– Fetch the appropriate page table entry– Fetch the desired data
• The straightforward virtual memory scheme would have the effect of doubling the memory access time
• Cache functions as a memory cache and contain page table entries that have been most recently used
Memory managementMemory management
YonseiYonsei UniversityUniversity7-62
Translation Translation LookasideLookaside Buffer Buffer • A virtual address is in the form of a page
number, offset• The memory system consults the TLB to
see if the matching page table entry is present
• If it is, the real address is generated by combining the frame number with the offset
• If not, the entry is accessed from a page table
Memory managementMemory management
YonseiYonsei UniversityUniversity7-63
Operation of Paging and TLBOperation of Paging and TLB Memory managementMemory management
YonseiYonsei UniversityUniversity7-64
LookasideLookaside Buffer and CacheBuffer and Cache•
Memory managementMemory management
YonseiYonsei UniversityUniversity7-65
SegmentationSegmentation• Visible to the programmer • Provided as a convenience for organizing
programs and data• Associating privilege and protection attributes
with instructions and data• Advantages
– Simplify the handling of growing data structure– Allow programs to be altered and recompiled
independently– Lend itself to sharing among processes– Lend itself to protection
Memory managementMemory management
YonseiYonsei UniversityUniversity7-66
PentiumIIPentiumII Memory ManagementMemory Management• Address Spaces
– Unsegmented unpaged memory– Unsegmented paged memory– Segmented unpaged memory– Segmented paged memory
• Segmentation– Table Indicator– Segment number– Request privilege level(RPL)
• Paging
PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-67
PentiumIIPentiumII Memory ManagementMemory Management PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-68
PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
PentiumIIPentiumII Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-69
PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
PentiumIIPentiumII Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-70
PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
PentiumIIPentiumII Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-71
PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
PentiumIIPentiumII Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-72
PentiumIIPentiumII Memory ParameterMemory Parameter PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-73
PentiumIIPentiumII Memory ParameterMemory Parameter PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-74
Memory Address Translation(PII)Memory Address Translation(PII) PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-75
PowerPC MemoryPowerPC Memory--ManagementManagement• Comprehensive set of addressing mechanism• Block address translation• Address one drawback of paging mechanism• Block addressing enable the map four large
blocks of instruction memory and four large block of data memory in a way that bypass the paging mechanism
PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-76
Memory Management(PPC32bit) Memory Management(PPC32bit) PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-77
PowerPC Address TranslationPowerPC Address Translation PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-78
PowerPC Memory ManagementPowerPC Memory Management PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management
YonseiYonsei UniversityUniversity7-79
PowerPC Memory ManagementPowerPC Memory Management PentiumIIPentiumII&PowerPC &PowerPC Memory ManagementMemory Management