๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โญ Group_Study/Operating System

[4์ฃผ์ฐจ] Deadlock: Deadlock Detection and Recovery

by ํฌ์ŠคํŠธ์‰์ดํฌ 2022. 12. 29.

Deadlock: Deadlock Detection and Recovery

Deadlock Detection

โœ” Deadlock ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ ์‚ฌ์ „ ์ž‘์—…์„ ํ•˜์ง€ ์•Š์Œ

  • Deadlock์ด ๋ฐœ์ƒ ๊ฐ€๋Šฅ

โœ” ์ฃผ๊ธฐ์ ์œผ๋กœ deadlock ๋ฐœ์ƒ ํ™•์ธ

  • ์‹œ์Šคํ…œ์ด deadlock ์ƒํƒœ์ธ๊ฐ€?
  • ์–ด๋–ค ํ”„๋กœ์„ธ์Šค๊ฐ€ deadlock ์ƒํƒœ์ธ๊ฐ€?

โœ” Resource Allocation Graph(RAG) ์‚ฌ์šฉ

Resource Allocation Graph(RAG)

โœ” Deadlock ๊ฒ€์ถœ์„ ์œ„ํ•ด ์‚ฌ์šฉ
โœ” Directed, Bipartite Graph


โœ” Directed graph G = (N, E)

  • N = ${N_p, N_r}$ where
    • $N_p$ is the set of processes = ${P1, P2, ..., P_N}$
    • and $N_r$ is the set of resources = ${R1, R2, ..., R_m}$

โœ” Edge๋Š” $N_p$์™€ $N_r$ ์‚ฌ์ด์—๋งŒ ์กด์žฌ

  • $e = (P_i, R_j)$: ์ž์› ์š”์ฒญ
  • $e = (R_j, P_i)$: ์ž์› ํ• ๋‹น

โœ” $R_k$: k type์˜ ์ž์›
โœ” $t_k$: $R_k$์˜ ๋‹จ์œ„ ์ž์› ์ˆ˜

  • For each $R_k ∈ N_r, ∃ T_k$ which is the number of units of $R_k$

โœ” |(a, b)|: (a, b) edge์˜ ์ˆ˜


โœ” RAG example

Deadlock Detection Method

โœ” Graph reduction

  • ์ฃผ์–ด์ง„ RAG์—์„œ edge๋ฅผ ํ•˜๋‚˜์”ฉ ์ง€์›Œ๊ฐ€๋Š” ๋ฐฉ๋ฒ•
  • Completely reduced
    • ๋ชจ๋“  edge๊ฐ€ ์ œ๊ฑฐ ๋จ
    • Deadlock์— ๋น ์ง„ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์—†์Œ
  • Irreducible
    • ์ง€์šธ ์ˆ˜ ์—†๋Š” edge๊ฐ€ ์กด์žฌ
    • ํ•˜๋‚˜ ์ด์ƒ์˜ ํ”„๋กœ์„ธ์Šค๊ฐ€ deadlock ์ƒํƒœ

Graph Reduction

โœ” Unblocked process

  • ํ•„์š”ํ•œ ์ž์›์„ ๋ชจ๋‘ ํ• ๋‹น ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ์„ธ์Šค
  • $P_i$๊ฐ€ ์š”์ฒญํ•˜๋Š” ๋ชจ๋“  ์ž์›์˜ ์ˆ˜๊ฐ€ ํ•ด๋‹น ์ž์›๋“ค์˜ ํ˜„์žฌ ๋‚จ์•„์žˆ๋Š” ์ˆ˜๋ณด๋‹ค ์ ์€ ๊ฒฝ์šฐ unblocked

Graph Reduction Procedure

  1. Unblocked process ์— ์—ฐ๊ฒฐ๋œ ๋ชจ๋“  edge์ œ๊ฑฐ
  2. ๋” ์ด์ƒ unblocked process๊ฐ€ ์—†์„ ๋•Œ๊นŒ์ง€ 1 ๋ฐ˜๋ณต

โœ” ์ตœ์ข… graph์—์„œ...

  1. ๋ชจ๋“  edge๊ฐ€ ์ œ๊ฑฐ ๋จ(Completely reduced)
    • ํ˜„์žฌ ์ƒํƒœ์—์„œ deadlock์ด ์—†์Œ
  2. ์ผ๋ถ€ edge๊ฐ€ ๋‚จ์Œ(irreducible)
    • ํ˜„์žฌ deadlock์ด ์กด์žฌ

example 1

example 2

Graph Reduction ์ •๋ฆฌ

โœ” High Overhead

  • ๊ฒ€์‚ฌ ์ฃผ๊ธฐ์— ์˜ํ–ฅ์„ ๋ฐ›์Œ
  • Node์˜ ์ˆ˜์— ์˜ํ–ฅ์„ ๋ฐ›์Œ

โœ” Low overhead deadlock detection methods(special case)

  • single unit resources(Cycle detection)
  • single unit request in expedient state(knot detection)

Deadlock Avoidance ve Detection

โœ” Deadlock Avoidance

  • ์ตœ์•…์˜ ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐ: ์•ž์œผ๋กœ ์ผ์–ด๋‚  ์ผ์„ ๊ณ ๋ ค
  • Deadlock์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์Œ

โœ” Deadlock Detection

  • ์ตœ์„ ์˜ ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐ: ํ˜„์žฌ ์ƒํƒœ๋งŒ ๊ณ ๋ ค
  • Deadlock ๋ฐœ์ƒ ์‹œ Recovery ๊ณผ์ •์ด ํ•„์š”

Deadlock Recovery

โœ” Deadlock์„ ๊ฒ€์ถœ ํ•œ ํ›„ ํ•ด๊ฒฐํ•˜๋Š” ๊ณผ์ •

Deadlock Recovery Methods

  1. Process termination
    • Deadlock ์ƒํƒœ์— ์žˆ๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ์ข…๋ฃŒ ์‹œํ‚ด
    • ๊ฐ•์ œ ์ข…๋ฃŒ ๋œ ํ”„๋กœ์„ธ์Šค๋Š” ์ดํ›„ ์žฌ์‹œ์ž‘ ๋จ
  2. Resource preemption
    • Deadlock ์ƒํƒœ ํ•ด๊ฒฐ ์œ„ํ•ด ์„ ์ ํ•  ์ž์› ์„ ํƒ
    • ์„ ์ • ๋œ ์ž์›์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ”„๋กœ์„ธ์Šค์—์„œ ์ž์›์„ ๋นผ์•—์Œ
      • ์ž์›์„ ๋นผ์•—๊ธด ํ”„๋กœ์„ธ์Šค๋Š” ๊ฐ•์ œ ์ข…๋ฃŒ ๋จ

Process Termination

โœ” Deadlock ์ƒํƒœ์ธ ํ”„๋กœ์„ธ์Šค ์ค‘ ์ผ๋ถ€ ์ข…๋ฃŒ

โœ” Termination cost model

  • ์ข…๋ฃŒ ์‹œํ‚ฌ deadlock ์ƒํƒœ์˜ ํ”„๋กœ์„ธ์Šค ์„ ํƒ
  • Termination cost
    • ์šฐ์„ ์ˆœ์œ„ (Process priority)
    • ์ข…๋ฅ˜ (Process type)
    • ์ด ์ˆ˜ํ–‰ ์‹œ๊ฐ„ (Accumulated execution time of the process)
    • ๋‚จ์€ ์ˆ˜ํ–‰ ์‹œ๊ฐ„ (Remaining time of the process)
    • ์ข…๋ฃŒ ๋น„์šฉ (Accounting cost)
    • Etc.

โœ” Process termination

  • Lowest-termination cost process first
    • Simple
    • Low overhead
    • ๋ถˆํ•„์š”ํ•œ ํ”„๋กœ์„ธ์Šค๋“ค์ด ์ข…๋ฃŒ ๋  ๊ฐ€๋Šฅ์„ฑ
  • Minimum cost recovery
    • ์ตœ์†Œ ๋น„์šฉ์œผ๋กœ deadlock ์ƒํƒœ๋ฅผ ํ•ด์†Œ ํ•  ์ˆ˜ ์žˆ๋Š” process ์„ ํƒ (๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜ ๊ณ ๋ ค)
    • Complex
    • High overhead($O(2^k)$)

Resource Preemption

โœ” deadlock ์ƒํƒœ ํ•ด๊ฒฐ์„ ์œ„ํ•ด ์„ ์ ํ•  ์ž์› ์„ ํƒ
โœ” ํ•ด๋‹น ์ž์›์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ์ข…๋ฃŒ ์‹œํ‚ด

  • Deadlock ์ƒํƒœ๊ฐ€ ์•„๋‹Œ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒ ๋  ์ˆ˜๋„ ์žˆ์Œ
  • ํ•ด๋‹น ํ”„๋กœ์„ธ์Šค๋Š” ์ดํ›„ ์žฌ์‹œ์ž‘

โœ” ์„ ์ ํ•  ์ž์› ์„ ํƒ

  • Preeption cost model ํ•„์š”
  • Minimul cost recovery method ์‚ฌ์šฉ ($O(r)$)

Checkpoint-restart method

โœ” ํ”„๋กœ์„ธ์Šค์˜ ์ˆ˜ํ–‰ ์ค‘ ํŠน์ • ์ง€์ (checkpoint)๋งˆ๋‹ค context ์ €์žฅ

โœ” Rollback์„ ์œ„ํ•ด ์‚ฌ์šฉ

  • ํ”„๋กœ์„ธ์Šค ๊ฐ•์ œ ์ข…๋ฃŒ ํ›„, ๊ฐ€์žฅ ์ตœ๊ทผ์˜ checkpotint์— ์ €์žฅ

๋Œ“๊ธ€