Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
■ System Model
■ Deadlock Characterization
■ Methods for Handling Deadlocks
■ Deadlock Prevention
■ Deadlock Avoidance
■ Deadlock Detection
■ Recovery from Deadlock
■ Combined Approach to Deadlock Handling
P0 P1
wait (A); wait(B)
wait (B); wait(A)
Deadlock Characterization
Resource-Allocation Graph
* Pi requests instance of Rj
Pi
* Pi is holding an instance of Rj
Pi
Deadlock Prevention
■ Mutual Exclusion – not required for sharable resources; must hold for
nonsharable resources.
■ Hold and Wait – must guarantee that whenever a process requests a resource, it
does not hold any other resources.
✦ Require process to request and be allocated all its resources before it
begins execution, or allow process to request resources only when the
process has none.
✦ Low resource utilization; starvation possible.
■ No Preemption –
✦ If a process that is holding some resources requests another resource that
cannot be immediately allocated to it, then all resources currently being
held are released.
✦ Preempted resources are added to the list of resources for which the
process is waiting.
✦ Process will be restarted only when it can regain its old resources, as well
as the new ones that it is requesting.
■ Circular Wait – impose a total ordering of all resource types, and require that
each process requests resources in an increasing order of enumeration.
Deadlock Avoidance
■ Simplest and most useful model requires that each process declare the maximum
number of resources of each type that it may need.
■ The deadlock-avoidance algorithm dynamically examines the resource-allocation
state to ensure that there can never be a circular-wait condition.
■ Resource-allocation state is defined by the number of available and allocated
resources, and the maximum demands of the processes.
Safe State
Basic Facts
■ Claim edge Pi → Rj indicated that process Pj may request resource Rj; represented
by a dashed line.
■ Claim edge converts to request edge when a process requests a resource.
■ When a resource is released by a process, assignment edge reconverts to a claim
edge.
■ Resources must be claimed a priori in the system.
Safe, Unsafe , Deadlock State
■ Multiple instances.
■ Each process must a priori claim maximum use.
■ When a process requests a resource it may have to wait.
■ When a process gets all its resources it must return them in a finite amount of
time.
Safety Algorithm
1. Let Work and Finish be vectors of length m and n, respectively. Initialize:
Work = Available
Finish [i] = false for i - 1,3, …, n.
2.Find and i such that both:
(a) Finish [i] = false
(b) Needi ≤ Work
If no such i exists, go to step 4.
3.Work = Work + Allocationi
Finish[i] = true
go to step 2.
4.If Finish [i] == true for all i, then the system is in a safe state.
Request = request vector for process Pi. If Requesti [j] = k then process Pi wants k
instances of resource type Rj.
Deadlock Detection
Detection Algorithm
Detection-Algorithm Usage
Background
■ Program must be brought into memory and placed within a process for it to be
run.
■ Input queue – collection of processes on the disk that are waiting to be brought
into memory to run the program.
■ User programs go through several steps before being run.
Address binding of instructions and data to memory addresses can happen at three
different stages.
Dynamic Loading
Overlays
■ Keep in memory only those instructions and data that are needed at any given
time.
■ Needed when process is larger than amount of memory allocated to it.
■ Implemented by user, no special support needed from operating system,
programming design of overlay structure is complex
Swapping
■ A process can be swapped temporarily out of memory to a backing store, and then
brought back into memory for continued execution.
■ Backing store – fast disk large enough to accommodate copies of all memory
images for all users; must provide direct access to these memory images.
■ Roll out, roll in – swapping variant used for priority-based scheduling algorithms;
lower-priority process is swapped out so higher-priority process can be loaded
and executed.
■ Major part of swap time is transfer time; total transfer time is directly proportional
to the amount of memory swapped.
■ Modified versions of swapping are found on many systems, i.e., UNIX, Linux,
and Windows.
Contiguous Allocation
■ Multiple-partition allocation
✦ Hole – block of available memory; holes of various size are scattered
throughout memory.
✦ When a process arrives, it is allocated memory from a hole large enough
to accommodate it.
✦ Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
OS OS OS OS
process 8 process 10
First-fit and best-fit better than worst-fit in terms of speed and storage utilization.
Fragmentation
Free Frames
Implementation of Page Table
Associative Memory
■ Associative memory – parallel search
Page # Frame #
■ Hierarchical Paging
■ A logical address (on 32-bit machine with 4K page size) is divided into:
✦ a page number consisting of 20 bits.
✦ a page offset consisting of 12 bits.
■ Since the page table is paged, the page number is further divided into:
✦ a 10-bit page number.
✦ a 10-bit page offset.
■ Thus, a logical address is as follows:
10 10 12
where pi is an index into the outer page table, and p2 is the displacement within
the page of the outer page table.
■ The virtual page number is hashed into a page table. This page table contains a
chain of elements hashing to the same location.
■ Virtual page numbers are compared in this chain searching for a match. If a match
is found, the corresponding physical frame is extracted.
■ Shared code
✦ One copy of read-only (reentrant) code shared among processes (i.e., text
editors, compilers, window systems).
✦ Shared code must appear in same location in the logical address space of
all processes.
■ Private code and data
✦ Each process keeps a separate copy of the code and data.
✦ The pages for the private code and data can appear anywhere in the logical
address space.
1
4
1
2
2
3
4 3
Segmentation Hardware
Example of Segmentation
Sharing of Segments