0% found this document useful (0 votes)
64 views116 pages

ITT 05101 - Operating System

Uploaded by

PAul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views116 pages

ITT 05101 - Operating System

Uploaded by

PAul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 116

OPERATING SYSTEMS

Code: ITT 05101


CONCEPT AND
INTRODUCTION OF OS
Operating System Definitions
• What is an Operating System?

•A program that acts as an intermediary between an


application (or a user of a computer) and the computer
hardware.
• Resource allocator / manager- System resources (CPU, RAM,
I/O) , User created resources (Files)

3
Operating System Functions
• Concurrency: Doing many things simultaneously (I/0,
processing, multiple programs, etc.) Several users work at the
same time as if each has a private machine
• I/O devices: let the CPU work while a slow I/O device is
working
• Memory management: OS coordinates allocation of memory
and moving data between disk and main memory.
• Files: OS coordinates how disk space is used to store multiple
files
• Distributed systems & networks: allow a group of workstations
to work together on distributed hardware

4
Operating System Functions
• OS functions have evolved in response to
• Efficient utilization of resources

• New features in computer hardware

• New user requirements

• Primary function of OS is to organize the execution of user


computations in the computer system
• Programs: Classical view of computation

• Process: Execution of a program

• Job: a sequence of programs ( BAT, Shellscripts) 5


Evolution of OS
• Over 40 years of computing : 9 orders of magnitude
change in every computer system component.

• Over 200 years Transportation: horse (10 miles /hr) to


Concorde (1000 miles/hr) 2 order of magnitude.

• Over 200 years of Communication : Telephone, TV, fax,


etc. 7 Orders of magnitude.

6
Memory Layout for a Simple Batch
System
job1 job2 job3 ……. jobn

End of
Start of batch
batch

7
Multi programmed Batch Systems
Several jobs are kept in main memory at the same time,
and the CPU is multiplexed among them.

8
OS Features Needed for
Multiprogramming

• I/O routine supplied by the system.

• Memory management – the system must allocate


the memory to several jobs.

• CPU scheduling – the system must choose among


several jobs ready to run.

• Allocation of devices.

9
Time-Sharing Systems–Interactive
Computing
• The CPU is multiplexed among several jobs that are kept in memory
and on disk (the CPU is allocated to a job only if the job is in memory).

• A job swapped in and out of memory to the disk.

• On-line communication between the user and the system is provided;


when the operating system finishes the execution of one command, it
seeks the next “control statement” from the user’s keyboard.

• On-line system must be available for users to access data and code.

10
Desktop Systems

• Personal computers – computer system dedicated to a single


user.
• I/O devices – keyboards, mice, display screens, small printers.
• User convenience and responsiveness.
• Can adopt technology developed for larger operating system’
often individuals have sole use of computer and do not need
advanced CPU utilization of protection features.
• May run several different types of operating systems (Windows,
MacOS, UNIX, Linux)

11
Parallel Systems

• Multiprocessor systems with more than on CPU in close


communication.

• Tightly coupled system – processors share memory and a clock;


communication usually takes place through the shared memory.

• Advantages of parallel system:


• Increased throughput
• Economical
• Increased reliability
• graceful degradation

• fail-soft systems
12
Parallel Systems (Cont.)

• Symmetric multiprocessing (SMP)


• Each processor runs and identical copy of the operating system.

• Many processes can run at once without performance deterioration.

• Most modern operating systems support SMP

• Asymmetric multiprocessing
• Each processor is assigned a specific task; master processor
schedules and allocated work to slave processors.
• More common in extremely large systems

13
Symmetric Multiprocessing
Architecture

14
Distributed Systems
• Distribute the computation among several physical processors.
• Loosely coupled system – each processor has its own local
memory; processors communicate with one another through
various communications lines, such as high-speed buses or
telephone lines.
• Advantages of distributed systems.
• Resources Sharing
• Computation speed up – load sharing
• Reliability
• Communications

15
Distributed Systems (cont)

• Requires networking infrastructure.

• Local area networks (LAN) or Wide area networks (WAN)

• May be either client-server or peer-to-peer systems.

16
General Structure of Client-Server

17
Clustered Systems
• Clustering allows two or more systems to share storage.

• Provides high reliability, Load balancing, Availability,


performance,

• Asymmetric clustering: one server runs the application


while other servers standby.

• Symmetric clustering: all N hosts are running the


application.

18
Real-Time Systems
• Often used as a control device in a dedicated application such as
controlling scientific experiments, medical imaging systems,
industrial control systems, and some display systems.

• Operational deadlines from event to system response is needed.

• OS used for embedded applications, such as mobile telephones,


industrial robots, or scientific research equipment are said to be
real time OS

• Real-Time systems may be either hard or soft real-time.

19
Real-Time Systems (Cont.)
• Hard real-time:
• Secondary storage limited or absent, data stored in short term
memory, or read-only memory (ROM)
• Conflicts with time-sharing systems, not supported by
general-purpose operating systems.
• Example embedded systems include medical systems such as
heart pacemakers and industrial process controllers.
• Soft real-time:
• Limited utility in industrial control of robotics
• Useful in applications (multimedia, virtual reality) requiring
advanced operating-system features.

20
Handheld Systems

• Personal Digital Assistants (PDAs)

• Cellular telephones

• Issues:

• Limited memory

• Slow processors

• Small display screens.

21
Types of Operating
Systems
Operating systems are there from the
very first computer generation and
they keep evolving with time. In this
chapter, we will discuss some of the
important types of operating systems
which are most commonly used.
Batch operating system
• The users of a batch operating system do not interact with the computer directly. Each
user prepares his job on an off-line device like punch cards and submits it to the
computer operator. To speed up processing, jobs with similar needs are batched
together and run as a group. The programmers leave their programs with the operator
and the operator then sorts the programs with similar requirements into batches.

The problems with Batch Systems are as follows −

• Lack of interaction between the user and the job.

• CPU is often idle, because the speed of the mechanical I/O devices is slower than the
CPU.

• Difficult to provide the desired priority.

24
Time-sharing operating systems
• Time-sharing is a technique which enables many people, located at various terminals, to use a
particular computer system at the same time. Time-sharing or multitasking is a logical extension
of multiprogramming. Processor's time which is shared among multiple users simultaneously is
termed as time-sharing.

• The main difference between Multiprogrammed Batch Systems and Time-Sharing Systems is that
in case of Multiprogrammed batch systems, the objective is to maximize processor use, whereas
in Time-Sharing Systems, the objective is to minimize response time.

• Multiple jobs are executed by the CPU by switching between them, but the switches occur so
frequently. Thus, the user can receive an immediate response. For example, in a transaction
processing, the processor executes each user program in a short burst or quantum of
computation. That is, if n users are present, then each user can get a time quantum. When the
user submits the command, the response time is in few seconds at most.

25
Advantages AND Disadvantages
Advantages of Timesharing operating systems are as follows −

• Provides the advantage of quick response.

• Avoids duplication of software.

• Reduces CPU idle time.

Disadvantages of Time-sharing operating systems are as follows −

• Problem of reliability.

• Question of security and integrity of user programs and data.

• Problem of data communication.

26
Distributed operating System
• Distributed systems use multiple central processors to serve multiple real-time applications and multiple
users. Data processing jobs are distributed among the processors accordingly.

• The processors communicate with one another through various communication lines (such as high-speed
buses or telephone lines). These are referred as loosely coupled systems or distributed systems.
Processors in a distributed system may vary in size and function. These processors are referred as sites,
nodes, computers, and so on.

• The advantages of distributed systems are as follows −

• With resource sharing facility, a user at one site may be able to use the resources available at another.

• Speedup the exchange of data with one another via electronic mail.

• If one site fails in a distributed system, the remaining sites can potentially continue operating.

• Better service to the customers.

• Reduction of the load on the host computer.

• Reduction of delays in data processing


27
Network operating System
• A Network Operating System runs on a server and provides the server the
capability to manage data, users, groups, security, applications, and
other networking functions. The primary purpose of the network
operating system is to allow shared file and printer access among
multiple computers in a network, typically a local area network (LAN), a
private network or to other networks.

• Examples of network operating systems include Microsoft Windows Server


2003, Microsoft Windows Server 2008, UNIX, Linux, Mac OS X, Novell
NetWare, and BSD.

28
Advantages AND
Disadvantages
The advantages of network operating systems are as follows −

• Centralized servers are highly stable.

• Security is server managed.

• Upgrades to new technologies and hardware can be easily integrated into the system.

• Remote access to servers is possible from different locations and types of systems.

The disadvantages of network operating systems are as follows −

• High cost of buying and running a server.

• Dependency on a central location for most operations.

• Regular maintenance and updates are required.

29
Real Time operating System
• A real-time system is defined as a data processing system in which the time interval
required to process and respond to inputs is so small that it controls the environment. The
time taken by the system to respond to an input and display of required updated
information is termed as the response time. So in this method, the response time is very
less as compared to online processing.

• Real-time systems are used when there are rigid time requirements on the operation of a
processor or the flow of data and real-time systems can be used as a control device in a
dedicated application. A real-time operating system must have well-defined, fixed time
constraints, otherwise the system will fail. For example, Scientific experiments, medical
imaging systems, industrial control systems, weapon systems, robots, air traffic control
systems, etc.

30
Process
management
Definition of Concepts
• A process is a program in execution. It is the unit of work in a
modern time-sharing system. The execution of a process must
progress in a sequential fashion.

• A process is more than the program code. It also includes the


state of current activities, as represented by the value of the
program counter and other registers.

• A process generally also includes a stack, containing temporary


data (e.g.. subroutine parameters, return address, local variables),
and a data section containing global variables.
32
Definition (cont’d)

• A program is not a process.

• A program is a passive entity whereas a process is an active


entity, with a program counter specifying the next instruction
to execute and a set of associated resources.

• Several users may be running copies of the mail program, or


the same user may invoke many copies of the MS-word. Each
of these is a separate process although the program text
sections are equivalent, the data sections will vary.

33
PROCESS STATE
• As a process executes, it changes state
according to environmental constraints.

34
PROCESS STATES
• New: The process is being created.

• Running: Instructions are being executed.

• Waiting: The process is waiting for some event to occur (such as


I/O operations).

• Ready: The process is waiting to be assigned to a processor.

• Terminated: The process has finished execution.


• CPU switch from process to process. Only one process can be
running on any processor at any instant. Many processes may be
ready and waiting.

35
Process Control Block
• Each process is represented by a Process
Control Block (PCB).

• Process state: The state may be new,


ready, running, waiting, halted, and so on.

• Program counter: The counter indicates


the address of the next instruction to be
executed for this process.
Process Control Block

• CPU scheduling information: This information includes a


process number, process priority, pointer to scheduling
queues, and any other scheduling parameters.
• Memory-management information: This information may
include the value of the base and limit registers, the page
tables, or the segment tables depending on the memory
system.
• I/O status information: The information includes the list of
I/O devices (such as tape drives, disks) allocated to this
process, a list of open files, and so on.
• Accounting information: The information includes the
amount of CPU and real time used, time limits, account
numbers, job or process numbers, and so on.

37
Process scheduling
• The objective of multiprogramming is to have some process
running at all times, to maximize CPU utilization.

• The objective of time-sharing is to switch the CPU among


processes so frequently that users can interact with each
program while it is running.

• As processes enter the system, they are put into a ready queue
to wait for execution. This queue is generally stored as a linked
list.

38
Process scheduling
• There are also other queues in the system, When a process is
allocated the CPU, it executes for awhile and eventually quits, is
interrupted, or waits for the occurrence of a particular event, such as
the completion of an I/O request.

• Since there are many processes in the system, the disk may be busy
with the I/O request of some other process. The process therefore
may be have to wait for the disk.

• The list of processes waiting for a particular I/O device is called a


device queue. Each device has its own device queue.
39
Process scheduling

40
Process scheduling
• The CPU scheduler selects from among the processes that
are ready to execute, and allocates the CPU to one of them.

• A process may execute for only a few milliseconds (say, 100


ms) in each time quantum (time slice), the scheduler
should be very fast, if it takes 10 ms to decide to execute a
process for each 100 ms, then 9 percent of the CPU is
considered as overhead.

41
I/O-bound and CPU-bound
• The success of CPU scheduling depends on the following
observed property of processes: Process execution
consists of a cycle of CPU execution and I/O wait. There
is a large number of short CPU bursts, and there is
small number of long CPU bursts.
• An I/O-bound process is one that spends more of its time
doing I/O than it spends doing computations. It would
typically have many very short CPU bursts.
• A CPU-bound process, on the other hand, is one that
generates I/O requests infrequently, using more time
doing computation. It might have a few very long CPU
bursts.

42
I/O-bound and CPU-bound
• A good mix of I/O-bound and CPU-bound processes will
increase the overall efficiency, even the scheduler has
wasted some CPU time.

• If all process are I/O-bound, the ready queue will almost


always be empty, and the CPU scheduler will have little to do.

• If all process are CPU-bound, the I/O waiting queue will


almost be empty, devices will go unused, and the scheduler
becomes meaningless.

43
I/O-bound and CPU-bound

• Assume we have one CPU-bound process and many I/O-bound processes.

• If the CPU-bound process get the CPU and hold it, all other processes which
finish their I/O will move into the ready queue to wait.

• While all I/O-bound processes are wait, the I/O devices are idle.
• Eventually, the CPU-bound process finishes its CPU burst and moves to an I/O
devices, all the I/O-bound processes, which have very short CPU bursts, execute
quickly and move back to I/O queues.

• At this point, the CPU sit idle.

• As a result, I/O-bound process should always be given higher priority than


CPU-bound process.
44
Criteria for comparing scheduling
algorithms
• CPU utilization: we want to keep the CPU as busy as possible.
CPU utilization may range from 0 to 100%. In real system, it would
range from 40% to 90%.

• Turnaround time: from the view point of a process, the interval


from the time of submission to the time of completion is the
turnaround time. The shorter the better.

45
Criteria for comparing scheduling
algorithms
• Waiting time: the CPU algorithm does not affect the
amount of time during which a process executes or does
I/O; it affects only the amount of time waiting in the
ready queue. The shorter the better.
• Response time: in an interactive system, turnaround
time may not be the best criteria. Often, a process can
produce some output fairly early, and can continue
computing new results while previous results are being
output to the user. Thus, another measure is the time
from the submission of a request until the first response
is produced. The shorter the better.

46
Scheduling algorithms
First-come-first-serve (FCFS)

• First-come-first-serve (FCFS): the average waiting time is quite long. Consider the following set
of processes that arrive at T0, with the length of the CPU-burst time given as: P1: 24ms, P2: 3ms, P3:
3ms. If the processes arrive in the order P1, P2, P3, we get the result shown in the following Gantt
chart:

P1 P2 P3

0 24 27 30

• The waiting time are: P1: 0ms, P2: 24ms, P3: 27ms, average waiting time is 17ms.

• If the processes arrive in the order of P2, P3, P1, the average waiting time is 3ms only.

47
Scheduling algorithms
First-come-first-serve (FCFS)
• As an example, consider the following four processes and the gantt chart, with the
length of the CPU-burst time given in ms:

Process Arrival Time Burst Time


P1 0 8
P2 1 4
P3 2 9
P4 3 5

P1 P2 P3 P4
0 8 12 21 26

Turnaround Time = ( (8-0) + (12-1) + (21-2) + (26-3) )/4 = 61/4 = 15.25


48
Scheduling algorithms
Shortest-Job-First (SJF)
• Shortest-Job-First (SJF): when the CPU is available, it is assigned
to the process that has the smallest next CPU burst.
• It provides shorter average waiting time. The real difficulty with
the SJF algorithm is knowing the length of the next CPU burst.
One solution is to predict the value as the length of the previous
CPU burst.
• The SJF algorithm may be either preemptive and non-
preemptive. The preemptive SJF will preempt the currently
executing process, whereas a non-preemptive SJF will allow the
currently running process to finish its CPU burst.

49
Scheduling algorithms
Shortest-Job-First (SJF)
• As an example, consider the following four processes and the gantt
chart, with the length of the CPU-burst time given in ms:

Process Arrival Time Burst Time


P1 0 8
P2 1 4
P3 2 9
P4 3 5

P1 P2 P4 P1 P3
0 1 5 10 17 26

• At time 1, P arrives and since 4 < (8-1), P is preempted while P is scheduled.


2 1 2
• The average waiting time is 6.5ms. A nonpreemptive SJF would result in 7.75ms.

50
Scheduling algorithms
Shortest-Job-First (SJF)

• As an example, consider the following four processes and the gantt chart, with the
length of the CPU-burst time given in ms:

Process Arrival Time Burst Time


P1 0 8
P2 1 4
P3 2 9
P4 3 5

P1 P2 P4 P1 P3
0 1 5 10 17 26

Turnaround Time = ( (5-1) + (10-3) + (17-0) + (26-2) )/4 = 52/4 = 13.0

51
Scheduling algorithms: Priority
scheduling

• Priority scheduling: a priority is associated with each process, and


the CPU is allocated to the process with the highest priority.
Equal-priority processes are scheduled in FCFS order. SJF is a
special case of priority scheduling.

• Priorities are generally some fixed range of numbers, 0 to 3, 0 to


7 or 0 to 256. 0 can be either the highest or lowest priority. In
most system, 0 represent highest priority.

52
Scheduling algorithms- Priority
scheduling
• Priorities can be defined either internally (calculated by the CPU
scheduler based on time limits, memory requirements, ratio of
I/O burst, etc.) or externally (assigned by the operating system
when the process is created according to the importance of the
process

• Priority may also be changed during a process is waiting in ready


queue, for example, it decrease 1 for every 15 mins waited.

53
Scheduling algorithms- Round-Robin
Scheduling (RR)
• Round-Robin Scheduling (RR): it is designed especially for time-sharing
systems. It is similar to FCFS, but preemption is added to switch between
processes.

• A small unit of time, called a time quantum, or time slice, is defined


(10ms to 100ms). The ready queue is treated as a circular queue. Notice
that there are 3 cases a process quit the CPU:
• 1) time quantum expire,

• 2) wait for I/O, or

• 3) terminated. 54
Scheduling algorithms
Round-Robin Scheduling (RR)

• As an example, consider the following four processes and the gantt chart, with the
length of the CPU-burst time given in ms:

Process Arrival Time Burst Time


P1 0 8

P2 1 4

P3 2 9
P4 3 5
Round Robin, quantum = 4, no priority-based preemption
P1 P2 P3 P4 P1 P3 P4 P3
0 4 8 12 16 20 24 25 26

Turnaround Time = ( (20-0) + (8-1) + (26-2) + (25-3) )/4 = 74/4 = 18.5

55
Scheduling algorithms: Multilevel
Feedback Queue Scheduling
• Multilevel Feedback Queue Scheduling: this kind of scheduling
allows a process to move between separate queues.

• Each queues has its own priority, quantum size, scheduling


algorithm. Usually, the lower the queue, the lower the priority.

56
Scheduling algorithms
Multilevel Feedback Queue Scheduling

57
Scheduling algorithms - Remark

• The FCFS algorithm is non-preemptive. Once the CPU has been


allocated to a process, that process keeps the CPU until it release
the CPU, either by terminating or by requesting I/O. It is not good
for time-sharing systems, where it is important that each user
get a share of CPU at regular intervals, preemptive scheduling is
better.
• Preemption may occur when the time quantum is up or a higher
priority process arrives, where the running process is put back to
the waiting queue.
• Context switching means saving the state (e.g.. PC, PSW, etc.)
of the old process and loading the saved state for the new
process. Context switch time is pure overhead. Discuss how the
time quantum size affects the number of context switches and
overall efficiency?
58
Scheduling algorithms - Remark

59
Process communication
• The concurrent processes executing in the operating system
may be either independent processes or cooperating
processes.
• Any process that does not share any data with any other
process is independent.
• On the other hand, a process is cooperating if it can affect or
be affected by the other processes executing in the system.
• Reasons for providing an environment that allows process
cooperation:
• Information sharing: since several users may be interested
in the same piece of information in a shared-memory
environment.
• Computation speedup: we break a task into subtasks, each
of which will be executing in parallel with the others can run
the task faster.

60
Process communication
• Besides the shared-memory environment, another way for
cooperating processes to communicate with each other is the
interprocess-communication (IPC) facility.
• IPC provides a message-passing system to allow processes to
communicate and to synchronize their actions.An IPC facility
provides at least two operations:
• send(Q,message) and receive(P,message).
• Messages sent by a process can be of either fixed or variable
size. If process P and Q want to communicate, they must send
messages to and receive messages from each other;
• a communication link must exist between them. The link has
several physical implementation, such as shared memory,
hardware bus, telephone lines & modems, or network cable.

61
Deadlock
• In a multiprogramming environment, several processes may
compete for a finite number of resources (e.g.. files, printers,
memory blocks).

• A process requests resources; if the resources are not available


at that time, the process enters a wait state.

• It may happen that waiting processes will never again change


state, because the resources they have requested are held by
other waiting processes. This situation is called a deadlock.

62
Deadlock

• For example,

• Process P1 requests filea and fileb while process P2 requests filea and
fileb too;
• P1 hold filea and continual requests fileb from OS while P2 hold fileb
and continuely requests filea from OS;
• Both of P1 and P2 wait forever and the deadlock exist.

• Deadlock can be prevented, detected and removed by intelligent


operating system. OS re-gain all resources after a certain time out is a
common deadlock recovering technique.

63
Memory
Management
Management of Real Memory
• Logical vs. Physical Address Space

• Logical address – generated by the CPU; also referred to as


virtual address.
• Physical address – address seen by the memory unit.
Instruction

logical address 1352

12000
Relocation register

13352

Memory unit

65
Management of Real Memory
• Memory Management Unit – Hardware device that maps virtual
address to physical address.
CPU Registers
Accsess time
increases

Cache

capacity increases

Main Memory

cost decreases

Secondary (swap)
storage

66
Management of Real Memory
• Any OS that supports more than one user at a time must provide a
mechanism for dividing central memory among the concurrent
processes.
• Level of multiprogramming is limited only by the number of jobs that
can fit into central memory.
• Many multiprogramming and multiprocessing systems divide
memory into partitions, with each process being assigned to a
different partition.
• Fixed partitions: predefined in size and position
• Variable partitions: allocated dynamically according to the
requirements of the jobs being executed

67
Fixed Partition Example

68
Strategy of Fixed Partition
• Allocation scheme:
• load each incoming job into the smallest free partition in which
it will fit.
• Initial selection of the partition sizes:
• Considerations:
• There must be enough large partitions so that large jobs
can be run without too much delay.
• If there are too many large partitions, a great deal of
memory may be wasted when small jobs are running.
• Scheme:
• Tailor a set of partitions to the expected population of job
sizes

69
Variable Partition Example

70
Strategy of Variable Partition
• Allocation scheme:
• For each job to be loaded, OS allocates, from the free
memory areas, a new partition of exactly the size required.
• OS must keep track of allocated and free areas of
memory, usually by maintaining a linked list of free
memory areas.
• This list is scanned when a new partition is to be
allocated.
• First-fit allocation: the first free area in which it will fit
• Best-fit allocation: the smallest free area in which it will
fit
• When a partition is released, its assigned memory is returned to
the free list and combined with adjacent free areas.

71
Memory Protection
• Memory protection:
• When a job is running in one partition, it must be prevented
from reading and writing memory locations in any other
partition or in the OS.
• Approaches (hardware support is necessary)
• Using a pair of bounds registers that contain the beginning and
ending addresses of a job’s partition
• OS sets the bounds registers (in supervisor mode) when a
partition is assigned to a new job.
• The values in theses registers are automatically saved and
restored during context switching.
• For every memory reference, the hardware automatically
checks the referenced address against the bounds registers.
• Using storage protection key

72
Memory Fragmentation
• Memory fragmentation occurs when the available free memory
is split into several separate blocks, with each block being too
small to be of use.
• External fragmentation – total memory space exists to
satisfy a request, but it is not contiguous.
• Internal fragmentation – allocated memory may be
slightly larger than requested memory; this size difference is
memory internal to a partition, but not being used.

73
Memory Fragmentation
• One possible solution: relocatable partitions

• After each job terminates, the remaining partitions are moved


as far as possible toward one end of memory. ( Compaction )
• Pros:

• More efficient utilization of memory

• Cons:

• Substantial amount of time required to copy jobs

• Problems with program relocation

74
Relocatable Partition Example

75
Relocatable Partitions
• Practical implementation of relocatable partitions requires some hardware
support: a special relocation register containing the beginning address of the
program currently being executed.
• The value of this register is modified when the process is moved to a new
location.
• This register is automatically saved and restored during context switching.

• The value of this register is automatically added to the address for every
memory reference made by the user program.

76
Basic Concept of Virtual
Memory
• A virtual resource is one that appears to a user program to
have characteristics that are different from those of the actual
implementation of the resource.
• User programs are allowed to use a large contiguous virtual
memory, or virtual address space.
• Virtual memory
• is stored on some external device, the backing store.
• may even be larger than the total amount of real memory
available on the computer.
• can increase the level of multiprogramming because only
portions of virtual memory are mapped into real memory as
they are needed.

77
Virtual Memory

• Division
real real Virtual
single user
Real storage multiprogramming
dedicated Virtual storage Multiprogramming systems
systems
system
variable
fixed partition pure combined paging
multiprogramming
multiprogram pure paging segmentation segmentation
ming

absolute Relocatable

78
Virtual Memory
• Characteristics of Programs- Programs have code used only in
unusual situations, e.g., error management.

• Arrays, lists, and tables are allocated more memory than needed.

Benefits of having programs only partially in main memory:


• No constraints on the amount of physical memory available
because of simulation of large memory.
• Less memory required per program

• More programs can execute concurrently

79
Demand Paging
• Demand paging
• One common method for implementing virtual memory.
• Demand Paging refers to a technique where program pages are
loaded from disk into memory as they are referenced.
• Virtual memory of a process is divided into pages of some fixed
length.
• Real memory of the computer is divided into page frames of the
same length as the pages.
• Mapping of pages onto page frames is described by a page map
table (PMT).
• PMT is used by the hardware to convert addresses in a
program’s virtual memory into the corresponding addresses in
real memory.
• This address conversion is known as dynamic address
translation.

80
Demand Paging
Virtual vs. Physical memory

81
Pure Paging
• Pager brings in individual pages into memory

• In the beginning, pager guesses the pages to be used by


the process
• Pages not needed are not brought into memory

• Hardware support for demand paging

• An extra bit attached to each entry in the page table valid-


invalid bit
• This bit indicates whether the page is in memory or not

82
Pure Paging (cont.)
• If there is ever a reference to a page, first reference will trap to
OS) page fault.
• OS looks at another table to decide:

• Invalid reference abort.

• Just not in memory-get empty frame.

• Swap page into frame.

• Reset tables, validation bit = 1.

• Restart instruction: Least Recently Used

83
Pure Paging (cont.)
• What happens if there is no free frame?

• Page replacements – find some page in memory, but not


really in use, swap it out.

• Algorithm ( How)

• Performance – want an algorithm, which will result in


minimum number of page faults.
• Same page may be brought into memory several times.

84
Page Selection for Removal
• Strategies:
• Least recently used (LRU) method
• Keep records of when each page is memory was last referenced
and replace the page that has been unused for the longest time.
• Overhead for this kind of record keeping can be high, simpler
approximations to LRU are often used.
• Working set
• Determine the set of pages that are frequently used by the
process in question.
• The systems attempt to replace pages in such a way that each
process always has its working set in memory. 85
Implementation of Page Tables
• Through dedicated register.
• Good strategy for small page table <256 entries but not
satisfactory for large sizes e.g. million entries.
• Page table is kept in main memory.
• Through page table registers:
• Page-table base register (PTBR) points to the page table in
memory.
• Page-table length register (PTLR) indicates size of the page
table- checked against every logical address to validate the
address- failure results in trap to the OS.
• Through Associative register :
• Parallel Search

86
Demand-Paging Systems
• Advantages:
• Efficient memory utilization
• Avoid most of the wasted memory due to fragmentation associated with
partitioning schemes.
• Parts of a program that are not used during a particular execution need
not be loaded.
• Disadvantages:
• Vulnerable to thrashing problem:
• The computing system spends most of its time swapping pages but not
doing useful work.
• Consider a case:
• Memory reference: 1 sec
• Fetch a page from the backing store: 10000 sec
• Page fault rate: 1%
• Only about 1% of its time is for useful work.

87
Locality of Reference
• To avoid thrashing, page fault rate has to be much lower.

• It is possible because the locality of reference can be


observed in most real programs:
• Memory references are not randomly distributed, but tend to be
clustered together in the address space.
• This clustering is due to common program characteristics:
• Sequential instruction execution
• Compact coding of loops
• Sequential processing of data structures

88
File
management
File-System Interface

• The operating system abstracts from the physical properties of its


storage devices to define a logical storage unit (the file).

• Files are mapped, by the operating system, onto physical devices.

90
File Concept
• A file is a named collection of related information that is
recorded on secondary storage.

• From a user’s perspective, a file is the smallest allotment of


logical secondary storage; that is, data cannot be written to
secondary storage unless they are within a file.

• In general, a file is a sequence of bits, bytes, lines, or records,


the meaning of which is defined by the file’s creator and user.
The concept of a file is thus extremely general.

91
File Concept
• Many different types of information may be stored in a file – source
programs, object programs, executable programs, numeric data, text,
payroll records, graphic images, sound recordings, and so on.
• A text file is a sequence of subroutines and functions, each of
which is further organized as declaration followed by executable
statements.
• An object file is a sequence of bytes organized into blocks
understandable by the system’s linker.
• An executable file is a series of code sections that the loader can
bring into memory and execute.
92
File Attributes
• A file has certain attributes, which vary from one operating system to another,
but typically consist of these:
• Name – only information kept in human- readable form.

• Type – needed for systems that support different types.

• Location – pointer to file location on device.

• Size – current file size.

• Protection – controls who can do reading, writing, executing.

• Time, date, and user identification – data for protection, security, and
usage monitoring.

• Information about all files are kept in the directory structure, which is
maintained on the disk.
93
File Operations
• A file is an Abstract Data Type. To define a file properly, we
need to consider the operations that can be performed on files.

• Create
• Write
• Read
• Reposition within File (or File Seek)
• Delete
• Truncate
• Open(Fi) – search the directory structure on disk for
entry Fi , and move the content of entry to memory.
• Close(Fi) – move the content of entry Fi in memory to
directory structure on disk.

94
Access Methods

• If files had only one "chunk" of data, life would be


simple.

• But for large files, the files themselves may contain


structure, making access faster.

95
SEQUENTIAL ACCESS

• Implemented by the file system.

• Data is accessed one record right after the last.

• Reads cause a pointer to be moved ahead by one.

• Writes allocate space for the record and move the pointer to the
new End Of File.

• Such a method is reasonable for tape.

96
DIRECT ACCESS
• Method useful for disks.

• The file is viewed as a numbered sequence of blocks or records.

• There are no restrictions on which blocks are read / written in any


order.

• User now says "Read N" rather than "Read Next".

• " N " is a number relative to the beginning of file, not relative to an


absolute physical

• disk location.

97
OTHER ACCESS METHODS
• Other access methods can be built on top of direct access
method.

• These methods generally involve the construction of an index for


the file.

• The index, like an index in the back of a book, contains pointers to


the various blocks.

• To find a record in the file, we first search the index, and then use
the pointer to access the file directly and to find the desired
record. 98
OTHER ACCESS METHODS
Example 1:

Index contains the name


appearing as the first record
in each block. There are as
many index entries as there
are blocks.

Unique academy, prepared my Meliki


99
MM
OTHER ACCESS METHODS (cont.)
Example 2:

Index contains the block


number where "A" begins,
where "B" begins, etc. Here
there are only 26 index entries.

Unique academy, prepared my Meliki


100
MM
Directory Structure
• Directories maintain information about files.
• For a large number of files, may want a directory structure -
directories under directories.
• Information maintained in a directory:

Name The user visible name.


Type The file is a directory, a program image, a user file, a link,
etc.
Location Device and location on the device where the file
header is located.
Size Number of bytes/words/blocks in the file.
Position Current next-read/next-write pointers.
Protection Access control on read/write/ execute/delete.
Usage info Open count, time of creation/access, etc.
Mounting a filesystem occurs when the root of one filesystem
is "grafted" into the existing tree of another filesystem.
101
Protection
• When information is kept in a computer system, we want to
keep it safe from physical damage (reliability) and improper
access (protection).

• Reliability is generally provided by duplicate copies of files.


Many computers have system programs that automatically (or
through computer-operator intervention) copy disk files to
tape at regular intervals (once per day or week or month) to
maintain a copy.

• Protection can be provided in many ways. For a small single-


user system, we might provide protection by physically
removing the floppy disks and locking them in a desk drawer
of file cabinet. In a multi-user system, however, other
mechanisms are needed.

102
Protection
• Types of Access

• Protection mechanisms provide controlled access by limiting the types of


file access that can be made. Access is permitted or denied depending on
several factors, one of which is the type of access requested. Several
different types of operations may be controlled.
• Read
• Write
• Execute
• Append
• Delete
• List

103
Protection
• Mode of Access: Read(R), Write(W), Execute(X)
• Ask manager to create a group (unique name), say G,
and add some users to the group.
• For a particular file (say game) or subdirectory, define
an appropriate access.
• Three classes of users

R W X

Owner Access 7 1 1 1

Groups Access 6 1 1 0

Public Access 1 0 0 1

104
File-System Implementation
• To provide an efficient and convenient access to the disk, the
operating system imposes one or more file system to allow the
data to be stored, located and retrieved easily.

• A file system poses two quite different design problems.

• The first problem is defining how the file system should look
to the user. This task involves defining a file and its
attributes, the operations allowed on a file, and the directory
structure for organizing files.
• The second problem is creating algorithms and data
structures to map the logical file system onto the physical
secondary-storage devices.

105
File-System Implementation
• The file system itself is Application Programs
generally composed of many
different levels. Logical File System

• Each level in the design uses File-organization module


the features of lower levels to
create new features for use by Basic File System
higher levels.
I/O Control

Device

106
File-System Implementation
• The lowest level, the I/O control, consists of device drivers
and interrupt handlers to transfer information between the
main memory and the disk system.

• A device driver can be thought of as a translator.


• Its input consists of high level commands such as “retrieve
block 123.”
• Its output consists of low-level, hardware-specific
instructions that are used by the hardware controller, which
interfaces the I/O device to the rest of the system.
• The device driver usually writes specific bit pattern to
special locations in the I/O controller’s memory to tell the
controller on which device location to act and what actions
to take.
107
File-System Implementation (Cont.)

• The basic file system needs only to issue generic commands


to the appropriate device driver to read and write physical
blocks on the disk.

• Each physical block is identified by its number disk address (for


example, drive 1, cylinder 73, track 2, sector 10).

108
File-System Implementation (Cont.)

• The file-organization module knows about files and their


logical blocks, as well as physical blocks. By knowing the type o
file allocation used and the location of the file, the file-
organization module can translate logical block addresses to
physical block addresses for the basic file system to transfer.

• Each file’s logical blocks are numbered from 1 (or 1) through N,


whereas the physical blocks containing the data usually do not
match the logical numbers, so a translation is needed to locate
each block.

• The file-organization module also includes the free-space


manager, which tracks unallocated blocks and provides these
blocks to the file-organization module when requested.

109
File-System Implementation (Cont.)

• Finally, the logical file system manages metadata information.


Metadata includes all of the file-system structure, excluding the
actual data (or contents of the files).

• The logical file system manages the directory structure to


provide the file-organization module with the information the
latter needs, given a symbolic file name. It maintains file
structure via file control blocks.

• A file control block (FCB) contains information about the file,


including ownership, permissions, and location of the file
contents. The logical file system is also responsible for protection
and security.

110
Allocation Methods
• The direct-access nature of disks allows us flexibility in the
implementation of files. In almost every case, many files will be
stored on the same disk.

• The main problem is how to allocate space to these files so that


disk space is utilized effectively and files can be accessed
quickly.

• Three major methods of allocating disk space are in wide use:


contiguous, linked, and indexed.

111
CONTIGUOUS ALLOCATION
• The contiguous-allocation method
requires each file to occupy a set of
contiguous blocks on the disk.

• Define by a pair <first block


location, length >.

Unique academy, prepared my Meliki


112
MM
CONTIGUOUS ALLOCATION
• Accessing the file requires a minimum of head movement.
• Easy to calculate block location: block i of a file, starting at disk
address b, is b + i.
• Difficulty is in finding the contiguous space, especially for a
large file. Problem is
• one of dynamic allocation (first fit, best fit, etc.) which has
external fragmentation.
• If many files are created /deleted, compaction will be necessary.
• It's hard to estimate at create time what the size of the file will
ultimately be. What
• happens when we want to extend the file - we must either
terminate the owner of the file, or try to find a bigger hole.

113
LINKED ALLOCATION

• At file creation time, simply tell the directory about the file.
When writing, get a free block and write to it, enqueueing it
to the file header.

• There's no external fragmentation since each request is for


one block.

• Method can only be effectively used for sequential files.

114
LINKED ALLOCATION
Pointers use up space in each block.

Reliability is not high because any


loss of a pointer loses the rest of the
file.

A File Allocation Table is a variation of


this. It uses a separate disk area to
hold the links.

This method doesn't use space in


data blocks. Many pointers may
remain in memory.

A FAT file system is used


Uniqueby MS-DOS.
academy, prepared my Meliki
115
MM
INDEXED ALLOCATION
• When the i th block is written, the address of a free block is
placed at the i th position in the index block.

• Method suffers from wasted space since, for small files, most of
the index block is wasted. What is the optimum size of an index
block?

• If the index block is too small, we can:

• Link several together

• Use a multilevel index


116

You might also like