+
Chapter 8 Operating System
Support
William Stallings, Computer Organization and Architecture, 9 th Edition
+ Objectives 2
CLO5: Summarize, at a top level, the key functions
of an operating system (OS).
How can a computer be made more convenient to
use?
How are computer system resources used in an
efficient manner?
+ Objectives 3
After studying this chapter, you should be able to:
Summarize, at a top level, the key functions of an
operating system (OS).
Discuss the evolution of operating systems for early
simple batch systems to modern complex systems.
Explain the differences among long-, medium-, and
short-term scheduling.
Understand the reason for memory partitioning and
explain the various techniques that are used.
Assess the relative advantages of paging and
segmentation.
Define virtual memory.
+ Contents 4
8.1 Operating System Overview
8.2 Scheduling
8.3 Memory Management
+ Questions must be Answered:
10 5
8.1 What is an operating system?
8.2 List and briefly define the key services provided by an OS.
8.3 List and briefly define the major types of OS scheduling.
8.4 What is the difference between a process and a program?
8.5 What is the purpose of swapping?
8.6 If a process may be dynamically assigned to different locations in main memory, what is the
implication for the addressing mechanism?
8.7 Is it necessary for all of the pages of a process to be in main memory while the process is
executing?
8.8 Must the pages of a process in main memory be contiguous?
8.9 Is it necessary for the pages of a process in main memory to be in sequential order?
8.10 What is the purpose of a translation look-aside buffer?
+ 8.1- Operating System Overview 6
What is Operating System?
The most important software which must be
installed in a family of computers
Why OS is needed?
The Operating System as User/Computer Interface,
program/hardware interface
The Operating System as Resource Manager
The Operating System as 7
User/Computer Interface
OS cung cấp các
thành phần cơ
bản (libraries) để
các app cung cấp
giao diện người
dùng
+ Operating System Services 8
(OS Libraries)
The most important system programs or library codes
Masks the details of the hardware from the programmer and provides
the programmer with a convenient interface for using the system
The OS typically provides services in the following areas:
Program/ process creation
Program/ process execution
Access to I/O devices
Controlled access to files
System access
Error detection and response
Accounting
Read note for details
+ Interfaces 9
Key interfaces in a typical computer system:
Application
Instruction Set Application Binary
Programming
Architecture (ISA) Interface (ABI)
Interface (API)
Defines the machine
Defines a standard for Gives a program access
language instructions
binary portability to the hardware
that a computer can
across programs resources and services
follow
available in a system
through the user ISA
supplemented with high-
level language (HLL)
Defines the system call library calls
Boundary between interface to the
hardware and software operating system and
the hardware resources
and services available in
a system through the Using an API enables
user ISA application software to
be ported easily to other
systems that support the
same API
Read note for details
+
10
Operating System
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
The OS as a control mechanism is unusual in two respects:
The OS functions in the same way as ordinary computer
software – it is a program executed by the processor
The OS frequently relinquishes (buông thả) control and
must depend on the processor to allow it to regain control
The OS as Resource Manager 11
+ 12
Types of Operating Systems
Interactive system
The user/programmer interacts directly with the computer to
request the execution of a job or to perform a transaction
User may, depending on the nature of the application, communicate
with the computer during the execution of the job
Batch system
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
Read note for details
+ Early Systems 13
From the late 1940s to the mid-1950s the
programmer interacted directly with the
computer hardware – there was no OS
Problems:
Scheduling based on sign-up sheets– Lập lịch các program đã đăng ký trước
This could result in wasted computer idle time if the user finished early
If problems occurred the user could be forced to stop before resolving the
problem
Setup time
A single program could involve
Loading the compiler plus the source program into memory
Saving the compiled program
Loading and linking together the object program and common functions
+
Simple Batch
System: OS
Memory
Layout
for a
Resident Monitor
+ Batch System 15
From the View of the Processor
Processor executes instructions from the portion of main memory
containing the monitor
These instructions cause the next job to be read in another portion of main
memory
The processor executes the instruction in the user’s program until it
encounters an ending or error condition
Either event causes the processor to fetch its next instruction from the
monitor program
The monitor handles setup and scheduling (Job sequencing)
A batch of jobs is queued up and executed as rapidly as possible with no
idle time
Job control language (JCL) - Interpreter
Special type of programming language used to provide instructions to the
monitor
+ From the View of the Processor 16
Example: User code using the Fortran language
$JOB // khai báo tác vụ
**Each FORTRAN instruction and
$FTN // ngôn ngữ va lệnh
each item of data is on a separate
... Some Fortran instructions punched card or a separate record on
tape. In addition to FORTRAN and
$LOAD // yêu cầu nạp tác vụ
data lines, the job includes job control
$RUN // chạy với data này instructions, which are
denoted by the beginning “$”.
... Some data
$END // kết thúc tác vụ
Monitor, or batch OS, is simply a computer program
It relies on the ability of the processor to fetch instructions from
various portions of main memory in order to seize (nắm lấy) and
relinquish (từ bỏ) control alternately
+ Desirable Hardware Features 17
Memory protection Privileged instructions
User program must not alter the Lệnh đặc biệt, nhạy cảm
memory area containing the monitor
Can only be executed by the monitor
The processor hardware should detect
an error and transfer control to the If the processor encounters such an
monitor instruction while executing a user
program an error interrupt occurs
The monitor aborts the job, prints an
error message, and loads the next job I/O instructions are privileged so the
monitor retains control of all I/O devices
Timer Interrupts
Used to prevent a job from Gives the OS more flexibility in
monopolizing (độc chiếm) the relinquishing control to and regaining
system control from user programs
If the timer expires an interrupt
occurs and control returns to
monitor
18
System Utilization Example
Perhaps CPU is often idle- An example
The processor is often idle Multiple jobs can be
carried out.
+ 19
Multiprogramming
Example
CPU rảnh thì thêm
việc để CPU làm
Đa lập trình
Multiprogramming Example 20
Khéo lập lịch
Hiệu suất cao
+ Time Sharing Systems 21
Hệ phân chia thời gian
It is used in interactive systems.
Processor’s time is shared among multiple users
Multiple users simultaneously access the system through
terminals, with the OS interleaving the execution of each
user program in a short burst or quantum (time slice,
time slot) of computation
Example:
If there are n users actively requesting service at one time, each
user will only see on the average 1/n of the effective computer
speed
Batch 22
Multiprogramming
versus
Time Sharing
+
+ 8.2- Scheduling 23
The key to multiprogramming
Four types are typically involved:
Program: executable file stored in external memory
Process: program in execution
+ Scheduling… 24
Scheduler
Long- Short-term List Medium-
term List term List
P1
- A IO Swap on DISK
- program P2 out (3) -
- must be P3 -
- loaded Interrupt -
P4
Swap in(4)
- (1) P5
-
P6
Choose current process (2)
Long Term Scheduling 25
In some systems a
newly created process
Determines which Once submitted, a job begins in a swapped-
programs are becomes a process for out condition, in
submitted for the short term which case it is added
processing scheduler to a queue for the
medium-term
scheduler
Time-sharing system
Batch system
• A process request is generated when a
• Newly submitted jobs are
user attempts to connect to the system
• OS will accept all authorized comers routed to disk and held in
a batch queue
until the system is saturated
• The long-term scheduler
• At that point a connection request is met
creates processes from the
with a message indicating that the system
queue when it can
is full and to try again later
+ Medium-Term Scheduling 26
Short-Term Scheduling
Medium-Term Short-Term
Part of the swapping function Also known as the dispatcher
Swapping-in decision is based on (trình điều phối)
the need to manage the degree of Executes frequently and makes
multiprogramming
the fine-grained decision of
Swapping-in decision will consider which job to execute next
the memory requirements of the
swapped-out processes
27
Short-Term Scheduling
Five State Process Model
Prog. is Relase all
loaded resource
Interrupt
from IO
IO operation
CPU can be allocated
to another process
Hình này minh họa những trạng thái của một tiến trình sẽ trải
qua khi nó thực thi
+ Index of instruction
which will be
fetched when the
Process Control process re-executes.
Block (PCB)
Values of registers at
the time the process
is blocked
What are metadata of a
process?
Scheduling Example
29
2. Time out
Calls a service
Read note
3 Key Elements of Multiprogramming OS 30
Services
Interrupt Handler
Scheduler
31
Process Scheduling
32
8.3- Memory Management
Memory Manager is a part of OS which bears
responsibility to manage computer memory at the system
level and some of following techniques can be applied.
Techniques used in Memory Management
Swapping – Hoán vị
Partioning – Phân hoạch
Paging – Phân trang
Segmentation – Phân đoạn
Virtual Memory – Bộ nhớ ảo
Translation Lookaside Buffer – Bộ đệm hỗ
trợ chuyển địa chỉ
+Memory
Management:
Swapping
Why?
Memory has larger size
Processes request more and more
memory, more processes need to
run Memory is not enough to
supply A selected process
must be swapped out to disk in
order to load new process
(SWAP) Kỹ thuật này
đã được bàn
đến trong
phần lập lịch
+
Memory Management
Partitioning
Smaller process needs
smaller memory
Unequal-size partition
is better.
Bộ nhớ RAM được
phân chia thành từng
vùng đều nhau (phân
trang) hoặc không đều
nhau (phân đoạn)
Effect of Dynamic Partitioning 35
To enable loading a
process to any position of
memory, program
addresses must be
expressed as logical
addresses.
Physical address
- an actual location in
main memory
Logical address
- expressed as a
location relative to the Data
beginning of the
program (offset) 100
Base address 3000
- current starting
location of the process
Phisical Addr = Base +
Offset
Physical addr = 3000 + 100 = 3100
+
Memory Management
Paging
At a time, only one instruction of
the current process executes
Only necessary part of each
process is loaded Many
processes can be loaded.
Programs are divided into small
fixed chunk (ex. 4KB). At a time,
only some pages of each process
are loaded to memory (frames)
Memory is divided also to frames
Frame size= Page size Loading 4 frames of the process A
+ How to determine physical address
from a logical address?
Paging
Logical and
Physical
Addresses
0
Each program 1
address is expressed 2
as a logical address 3
which is a pair of
(page, offset)
Virtual Memory:
+ 38
Demand Paging – Nạp trang theo yêu cầu
Each page of a process is brought in only when it
is needed
Principle of locality
When working with a large process execution may be confined
(limited) to a small section of a program (subroutine)
It is better use of memory to load in just a few pages
If the program references data or branches to an instruction on a page
not in main memory, a page fault is triggered which tells the OS to
bring in the desired page
Virtual Memory:
+ 39
Demand Paging
Advantages:
More processes can be maintained in memory
Time is saved because unused pages are not swapped in and out of
memory
Disadvantages:
When one page is brought in, another page must be thrown out (page
replacement)
If a page is thrown out just before it is about to be used the OS will have
to go get the page again
Thrashing (đánh bại- hệ thống trì trệ do thay trang liên tục)
When the processor spends most of its time swapping pages rather
than executing instructions
+
Paging:
Inverted
Page
Table
Structure
A large table is used to
store all pages of all
procsses
Hash function allows determine the position of a table in which data is stored.
Example: h(n) = n modulo k ( n%k)
If h(n2) = position storing n1, n2 will be stored in the lower position (overflow area) and
they are marked in the field chain.
+
Paging:
Operation of Paging
TLB
and Translation TLB hit
miss
Lookaside Buffer
(TLB)
TLB is an hardware
including some registers. A
part of page table is copied
to them in order to increase
performance of translating
virtual addresses to physical
addresses.
42
TLB and Cache Operation
+ Segmentation 43
Program is divided in to segments (data, code,
stack, heap segments)
Usually visible to the programmer Advantages:
Provided as a convenience for
Simplifies the handling of growing
data structures
organizing programs and data and as
a means for associating privilege and Allows programs to be altered and
protection attributes with instructions recompiled independently without
and data requiring that an entire set of
programs be re-linked and re-loaded
Allows the programmer to view A segment can be shared among
memory as consisting of multiple processes
address spaces or segments A segment can be added individual
A segment can be divided into some protection
pages.
Windows uses segmentation technique
and paging is applied on each segment.
+ Summary
44
Operating System
Support
Chapter 8
Operating system objectives and Memory management
functions Swapping
Types of operating systems Partitioning
Scheduling Paging
Long-term scheduling Virtual memory
Medium-term scheduling Translation lookaside buffer
Short-term scheduling Segmentation