Download Virtual memory

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

RSTS/E wikipedia , lookup

Distributed operating system wikipedia , lookup

VS/9 wikipedia , lookup

Burroughs MCP wikipedia , lookup

CP/M wikipedia , lookup

Memory management unit wikipedia , lookup

Process management (computing) wikipedia , lookup

Paging wikipedia , lookup

Transcript
Computer Architecture
Operating System Objectives and Functions
“An OS is a program that controls the execution of application
programs and acts as an interface between applications and the
computer hardware”
It can be thought of as having two objectives:
• Convenience: Makes a computer
more convenient to use.
• Efficiency: Allows the computer
system resources to be used in an
efficient manner.
OS Services Areas
The OS typically provides services in the following areas:
- Program creation.
- Program execution.
- Access to I/O devices.
- Controlled access to files.
- Error detection and response.
- System access.
- Instruction set architecture (ISA).
- Accounting.
- Application binary interface (ABI).
- Application programming interface (API).
OS as Resource Manager:
• A computer is a set of resources for the movement, storage,
and processing of data and for the control of these functions.
• The OS is responsible for managing these resources.
OS as Resource Manager
Hints: 1. The OS is a program executed by the processor.
2. The OS frequently leave control and must depend on
the processor to allow it to regain control.
Types of Operating System
1. Interactive / Batch.
2. Uni-programming / Multi-programming.
• In an interactive system, the user/programmer interacts
directly with the computer (through a keyboard/display) to
request the execution of a job or to perform a transaction.
• A batch system is the opposite of interactive. The user’s
program is batched together with programs from other users
and submitted by a computer operator. After the program is
completed, results are printed out for the user.
• Pure batch systems are rare today. However, it will be useful
to examine batch systems briefly.
Cont.
• With multiprogramming, the attempt is made to keep the
processor as busy as possible, by having it work on more
than one program at a time.
• In a uni-programming system, only one program is worked
at a time.
Early Systems:
• No Operating System.
• Programs interact directly with hardware.
• Two main problems:
- Scheduling: installations used a sign-up sheet to reserve
processor time.
- Setup time: A single program, called a job, involve loading
the compiler + the high-level language program.
Simple Batch Systems
• Simple batch operating systems were called a monitor.
• Resident Monitor program always still in the main memory.
• Users submit jobs to operator.
• Operator batches jobs.
• Monitor controls sequence of
events to process batch.
• When one job is finished,
control returns to Monitor which
reads next job.
• Monitor handles scheduling.
Desirable Hardware Features
• Memory protection.
– To protect the Monitor.
• Timer.
– To prevent a job from monopolizing the system.
• Privileged instructions.
– Only executed by Monitor.
– e.g. I/O.
• Interrupts.
– Allows for relinquishing and regaining control from the
user program.
Processor time alternates between execution of user programs
and execution of the monitor.
Multi-programmed Batch Systems
• I/O devices very slow.
• When one program is waiting for I/O, another can use the CPU.
Example:
Example
A time-sharing system: multiple users simultaneously access the
system through terminals, with the OS interleaving the execution.
Cont.
Scheduling
• The key to multiprogramming is scheduling.
• The concept of process is more general than job.
• Many definitions have been given for the term process:
 A program in execution.
 The “animated spirit” of a program.
 That entity to which a processor is assigned.
Types of Scheduling:
•
•
•
•
Long term.
Medium term.
Short term.
I/O.
1. Long Term Scheduling
• Determines which programs are submitted for processing.
• It controls the degree of multi-programming.
• Once submitted, a job becomes a process for the short term
scheduler.
• Or it becomes a swapped out job for the medium term
scheduler.
2. Medium Term Scheduling
• Part of the swapping function.
• Usually based on the need to manage multi-programming.
• If no virtual memory, memory management is also an issue.
3. Short Term Scheduler
• Dispatcher.
• Fine grained decisions of which job to execute next.
• i.e. which job actually gets to use the processor in the next time
slot.
Process State:
Process Control Block.
• For each process in the system, the OS must maintain
information indicating the state of the process and other
information necessary for process execution.
• For this purpose, each process is represented
in the OS by a process control block.
• When the scheduler accepts a new job or user
request for execution, it creates a blank
process control block.
Example
Elements of O/S
The major elements of the OS involved in the multiprogramming
and scheduling of processes.
Process Scheduling
• The long-term queue is a list of jobs waiting to use the system.
• The short-term queue consists of all processes in the ready state
• An I/O queue means that all processes waiting to use each
device are lined up in that device’s queue.
Memory Management
• Uni-program.
– Memory split into two.
– One for operating System (monitor) and the other for
currently executing program.
• Multi-program.
– “User” part is sub-divided and shared among active
processes.
“The task of subdivision is carried out dynamically by the OS”.
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 main memory.
• Expensive.
• Leads to larger programs.
– Swapping.
• Long term queue of processes stored on disk.
• Processes “swapped” in as space becomes available.
• As a process completes it is moved out of main memory.
Cont.
• If none of processes in memory are ready ( all I/O blocked).
 Swap out a blocked process to intermediate queue.
 Swap in a ready process or a new process.
 Swapping is an I/O process.
Partitioning
“Splitting memory into sections to allocate to processes
(including Operating System)”.
• Fixed-sized partitions.
– May not be equal size.
– Process is fitted into smallest
hole that will take it (best fit).
– Some wasted memory.
– Leads to variable sized
partitions.
Variable-Size Partitions
• When a process is brought into memory, it is allocated exactly
as much memory as it requires and no more.
• This leads to a hole at the end of memory, too small to use.
- Only one small hole - less waste.
• When all processes are blocked, swap out a process and bring in
another.
• New process may be smaller than swapped out process. (hole)
• Eventually have lots of holes (fragmentation).
Solutions:
Compaction: From time to time go through memory and move
all hole into one free block (disk de-fragmentation).
Effect of Dynamic Partitioning
Loaded in
M.M empty
Hole
Relocation
• When compaction is used, a process may be shifted while in
main memory.
• Instructions contain addresses of two types:
- Locations of data.
- Addresses for instructions
• To solve this problem, a distinction is made between logical
addresses and physical addresses.
• Logical address: relative to beginning of program.
• Physical address: actual location in main memory.
• When the processor executes a process, automatic conversion
is done by adding the current starting location of the process,
(base address), to each logical address.
Paging
• Split memory into equal sized, small chunks (page frames).
• Split programs (processes) into equal sized small chunks
(pages).
• Allocate the required number page frames to a process.
• Operating System maintains list of free frames.
• A process does not require contiguous page frames.
• Use page table to keep track.
• The page table shows the frame location for each page of the
process.
Allocation of Free Frames
Logical and Physical Addresses - Paging
Virtual Memory
• Demand paging.
– Do not require all pages of a process in memory, so bring in
pages as required.
• Page fault happens when the required page is not in memory.
– Operating System must swap in required page.
– May need to swap out a page to make space (page replacement).
• Thrashing: the processor spends most of its time swapping
pages rather than executing instructions.
• A programmer or user perceives a much larger memory which is
allocated on the disk (Virtual memory).
• Virtual memory allows for very effective multiprogramming and
relieves the user of unnecessarily tight constraint of M.M.
Translation Lookaside Buffer
• Every virtual memory reference causes two physical memory
access.
– Fetch page table entry.
– Fetch data.
• Virtual memory scheme would have the effect of doubling the
memory access time.
• To overcome this problem, most virtual memory schemes make
use of a special cache for page table entries, usually called a
translation lookaside buffer (TLB).
• This cache functions in the same way as a memory cache and
contains those page table entries that have been most recently
used.
Segmentation
• Paging is not (usually) visible to the programmer and provide
the programmer with a larger address space.
• Segmentation is visible to the programmer and is provided as
a convenience for organizing programs and data.
• Usually different segments allocated to program.
Advantages of Segmentation
• Simplifies handling of growing data structures.
• Allows programs to be altered and recompiled independently,
without relinking and reloading.
• Lends itself to sharing among processes.
• Lends itself to protection.