Deadlocks Flashcards

1
Q

deadlock

A

A set of processes is deadlocked if:
- Each process in the set waiting for an event
- That event can be caused only by another
process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

livelock

A

operations are being executed but no progress is made

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

conditions for resource deadlocks

A
  1. mutual exclusion
  2. hold and wait
  3. no preemption
  4. circular wait condition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

mutual exclusion

A

each resource is assigned to at most one process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

hold and wait

A

processes can request a resource when holding another one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

no preemption

A

resources cannot be taken away from a process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

circular wait condition

A

chain of two or more processes must be waiting for a resource held by next process in the chain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

deadlock handling

A
  1. ignore the problem
  2. deadlock detection
  3. deadlock avoidance
  4. deadlock prevention
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

ignore the problem

A

no action taken
the OS doesn’t handle deadlocks, it is up to the programmer, i.e. manual

  • Also known as the ostrich algorithm
  • Cost-effective solution to deadlocks
  • Assumes deadlocks are rare
  • Assumes cost of handling deadlocks is high
  • Assumes effects of deadlocks are tolerable
  • Simplest solution to manage system resources, i.e., process table, inode table, swap space, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

deadlock detection

A

detect deadlock and perform recovery actions
algorithm for detection + algorithm/mechanism for recovery

  • Detection
    • Check for cycles in the resource allocation graph
    • Track progress and time out
    • Explicit detection (e.g., OOM)
  • Useful in practice when simple and efficient detection mechanisms (e.g., progress tracking or explicit detection) along with recovery actions are available
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

deadlock avoidance

A

carefully allocate resources to avoid deadlocks
requires additional information about resources a process might need during its lifeitme

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

deadlock prevention

A

structurally prevent any of the deadlock conditions
provides a method for ensuring at least one of the 4 conditions cannot hold

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

recovery from a deadlock

A

force preemption
checkpoint-rollback
killing the offending process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

killing the offending process

A
  1. abort all deadlocked processes
    ⇒ expensive, computations done so far have to be done again
  2. abort one process at a time until the deadlock cycle is eliminated
    ⇒ considerable overhead, after each process is aborted a deadlock check algorithm is invoked
    abort processes whose termination will incur the minimum cost; think about:
    • what the priority of the process is
    • how long the process has computed how much longer the process will compute completing its designated task
    • resources the process is using and needs to use
    • how many processes will be terminated
    • whether the process is interactive or batch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

issues with aborting a process

A

it was modifying a file→ it leaves a file in an incorrect state

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

force preemption

A
  • reassign the resources so that the deadlock is resolved
  • issues:
    • select a victim process: minimise cost
    • rollback: what to do with the victim (can’t continue execution) → roll back to some safe state and restart it from that state
      • hard to find a safe state → total rollback (abort and restart essentially)
    • starvation: if victim selection is based primarily on cost factors, it may be chosen every time and as a result it will never complete
17
Q

deadlock avoidance

A
  • safe state: the system can allocate resources to each process (up to its maximum) in some order and still avoid a deadlock
  • safe sequence: all requests will be satisfied
  • not all unsafe states are deadlock
18
Q

Banker’s algorithm

A
  • Customers (processes) request credits (resources)
  • Banker (OS) only satisfies requests resulting in safe states
  • A state is safe iff there exists a sequence of other states that allows all the customers to complete
  • Maximum credit demands are known in advance
  • safe state: anybody can obtain new credits and complete, then others can obtain credits and complete
  • unsafe state: nobody can obtain new credits and complete
    • not enough resources for everyone’s max
19
Q

deadlock prevention with mutual exlusion

A
  • must hold for non-shareable processes → hard to avoid
  • spool everything: typically shifts the problem somewhere else
  • not really an option
20
Q

deadlock prevention with hold and wait

A
  • requests all resources initially (or reacquire them)
    • one protocol that can be used requires each process to request and be allocated to its resources before it begins execution
  • instead: release current resources and the request new ones
  • poor parallelism and resource utilisation, starvation is possible
21
Q

deadlock prevention with no preemption

A
  • take resources away
  • if a process is requesting something it releases everything → preemption
  • applicable only to resources whose state can be easily saved and restored later, such as CPU registers and memory space
  • N/A in many cases (e.g. printer vs. memory)
22
Q

deadlock prevention with circular wait

A
  • order resources numerically
  • process requests resources in an increasing order
    • example: P1 has R5, it then needs R4 and R3 → the requests won’t be granted (3,4 < 5)
  • hard to consistently enforce in practice
23
Q

deadlock handling in practice

A

deadlock avoidance: rarely an option (hard to know a resource a priori)
deadlock prevention: adopted in particular domains
ignore the problem: last resort when nothing is available
deadlock detection: solution of choice when adequate detection (and recovery) mechanism are available

24
Q

global OOM killer

A
  • resource: memory
  • mechanisms: explicit detection
25
Q

soft lockup detection

A
  • resource: locks
  • mechanisms: progress tracking
26
Q

locking validator

A
  • resource: locks
  • mechanisms: cycles in the resource allocation graph
27
Q

deadlock detection on Linux

A

global OOM killer
soft lockup detection
locking validator