[OS] CPU, Disk Scheduling

seunghyunยท2023๋…„ 4์›” 9์ผ
0

๐Ÿ’ป

๋ชฉ๋ก ๋ณด๊ธฐ
8/15

Introduction

๐Ÿ’ก System ์˜ ์ž์›์„ Process/Thread ์—๊ฒŒ ์–ด๋–ป๊ฒŒ ํ• ๋‹นํ•  ๊ฒƒ์ธ๊ฐ€?

  • Assign system resource (CPU, I/O device, etc) to processes/threads to meet system objectives (response time, turnaround time; ํ”„๋กœ์„ธ์Šค ์‹œ์ž‘๋ถ€ํ„ฐ ๋๊นŒ์ง€ ์ด ์‹œ๊ฐ„ , throughput; ์‹œ๊ฐ„๋‹น ์ฒ˜๋ฆฌํ•˜๋Š” ํ”„๋กœ์„ธ์Šค ์ˆ˜, or fairness..)
  • In practice, these goals often conflict

โœ”๏ธ CPU Scheduler

  • Ready ์ƒํƒœ์˜ ํ”„๋กœ์„ธ์Šค ์ค‘์—์„œ ์ด๋ฒˆ์— CPU์— ํ• ๋‹นํ•  ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ณ ๋ฅธ๋‹ค

โœ”๏ธ Dispatcher

  • CPU์˜ ์ œ์–ด๊ถŒ์„ CPU Scheduler์— ์˜ํ•ด ์„ ํƒ๋œ ํ”„๋กœ์„ธ์Šค์—๊ฒŒ ๋„˜๊ธด๋‹ค
  • ์ด ๊ณผ์ •์„ Context Switch ๋ผ ํ•œ๋‹ค

โœ”๏ธ CPU ์Šค์ผ€์ค„๋ง์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ๋Š” ํ”„๋กœ์„ธ์Šค์—๊ฒŒ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ƒํƒœ ๋ณ€ํ™”๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ๋‹ค
1. Running ๐Ÿ‘‰ Blocked (ex: I/O ์š”์ฒญํ•˜๋Š” System Call)
2. Running ๐Ÿ‘‰ Ready (ex: ํ• ๋‹น์‹œ๊ฐ„๋งŒ๋ฃŒ๋กœ timer interrupt)
3. Blocked ๐Ÿ‘‰ Ready (ex: I/O ์™„๋ฃŒํ›„ ์ธํ„ฐ๋ŸฝํŠธ)
4. Terminate

  • 1, 4 ์—์„œ์˜ ์Šค์ผ€์ค„๋ง์€ nonpreemptive ๋น„์„ ์ 
  • ๋‚˜๋จธ์ง€๋Š” preemptive ์„ ์ 

โœ”๏ธ Scheduling Criteria (Performance Index, ์„ฑ๋Šฅ ์ฒ™๋„)

  • CPU utilization ์ด์šฉ๋ฅ 
    • Keep the CPU as busy as possible
  • Throughput ์ฒ˜๋ฆฌ๋Ÿ‰
    • of processes that complete their execution per time unit
  • Turnaround Time ์†Œ์š”,๋ฐ˜ํ™˜ ์‹œ๊ฐ„
    • amount of time to execute a particular process
  • Waiting Time ๋Œ€๊ธฐ ์‹œ๊ฐ„
    • amount of time a process has been waiting in the ready queue
  • Response Time ์‘๋‹ต ์‹œ๊ฐ„
    • amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)

Scheduler ์ข…๋ฅ˜

์žฅ๊ธฐ ์Šค์ผ€์ค„๋Ÿฌ

(or Job scheduler)
โœ”๏ธ ์‹œ์ž‘ ํ”„๋กœ์„ธ์Šค ์ค‘ ์–ด๋–ค ๊ฒƒ๋“ค์„ ready queue ๋กœ ๋ณด๋‚ผ์ง€ ๊ฒฐ์ •
โœ”๏ธ ํ”„๋กœ์„ธ์Šค์— memory(๋ฐ ๊ฐ์ข… ์ž์›)์„ ์ฃผ๋Š” ๋ฌธ์ œ
โœ”๏ธ degree of Multiprogramming ์„ ์ œ์–ด
โœ”๏ธ time sharing system ์—๋Š” ๋ณดํ†ต ์žฅ๊ธฐ ์Šค์ผ€์ค„๋Ÿฌ๊ฐ€ ์—†๋‹ค (๋ฌด์กฐ๊ฑด ready)

๋‹จ๊ธฐ ์Šค์ผ€์ค„๋Ÿฌ

(or CPU scheduler)
โœ”๏ธ ์–ด๋–ค ํ”„๋กœ์„ธ์Šค๋ฅผ ๋‹ค์Œ๋ฒˆ์— runnning ์‹œํ‚ฌ์ง€ ๊ฒฐ์ •
โœ”๏ธ ํ”„๋กœ์„ธ์Šค์— CPU๋ฅผ ์ฃผ๋Š” ๋ฌธ์ œ
โœ”๏ธ ์ถฉ๋ถ„ํžˆ ๋นจ๋ผ์•ผ ํ•จ (millisecond ๋‹จ์œ„)

์ค‘๊ธฐ ์Šค์ผ€์ค„๋Ÿฌ

(or Swapper)
โœ”๏ธ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋„ˆ๋ฌด ๋ถ€์กฑํ•  ๋•Œ, ์—ฌ์œ  ๊ณต๊ฐ„ ๋งˆ๋ จ์„ ์œ„ํ•ด ํ”„๋กœ์„ธ์Šค๋ฅผ ํ†ต์งธ๋กœ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ๋””์Šคํฌ๋กœ ์ซ“์•„๋ƒ„
โœ”๏ธ ํ”„๋กœ์„ธ์Šค์—๊ฒŒ์„œ memory๋ฅผ ๋บ๋Š” ๋ฌธ์ œ
โœ”๏ธ degree of Multiprogramming ์„ ์ œ์–ด


Processor Scheduling

Three types of processor scheduling

โœ”๏ธ Long-term scheduling (admission scheduler) : ์‹œ์Šคํ…œ์— ์ž…์žฅ์„ ํ—ˆ๋ฝํ•  ๊ฒƒ์ด๋ƒ

  • Decide which jobs/processes to be admitted to the system
    • Contorl the degree of multiprogramming
  • Once admitted, a job or user program becomes a process
    • The process may be added to the ready queue for the short-term scheduler or to a queue for the medium-term scheduler in a swapped-out condition

โœ”๏ธ Mid-term scheduling (swapper) : ๋ฉ”๋ชจ๋ฆฌ๋กœ ๊ฐ€์ ธ์˜ฌ ๊ฒƒ์ด๋ƒ ์ซ“์•„๋‚ผ ๊ฒƒ์ด๋ƒ

  • Remove a process from main memory and place them on secondary memory, or vice versa Sswap in out process

โœ”๏ธ Short-term scheduling (dispatcher) : CPU์— ํ• ๋‹น

  • Decide which of the ready, in-memory processes to be executed by the processor following a clock interrupt, IO interrupt, or OS call

  • Execute most frequently

  • The main objective of short-term scheduling is to allocate processor time to optimize system behaviour

--

Disk Scheduling

โœ”๏ธ Disk Cache ๋””์Šคํฌ ์„นํ„ฐ์˜ ์นดํ”ผ๋ณธ์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ๋””์Šคํฌ access ์—†์ด ์ œ๊ณตํ•˜๋Š” ๋ฐฉ๋ฒ•

  • Disk Cache is a buffer in main memory for disk sectors
    • Contains a copy of some of the sectors on the disk

โœ”๏ธ When an I/O request is made for a particular sector, a check is made to determine if the sector is in the disk cache

  • If YES ๐Ÿ‘‰ the request is satisfied via the cache
  • If NO ๐Ÿ‘‰ the requested sector is read into the disk cache from the disk

โœ”๏ธ LRU; Least Recently Used

  • The most commonly used algorithm
  • The block that has not been referenced for the longest time is replaced
  • A stack of pointers reference the cache
    • Most recently referenced block is on the top of the stack
    • When a block is referenced or brought into the cache, it is placed on the top of the stack

โœ”๏ธ LFU; Least Frequently Used

  • The block that has experienced the fewest references is replaced
  • A counter is associated with each block
  • Counter is incremented each tiem block is accessed
  • When replacement is required, the block with the smallest count is selected
  • Problematic When
    • Certain blocks are referenced relatively infrequently overall, but when they are referenced, there are short intervals of repeated references due to locality, building up high reference counts. After such interval is over, the reference count may br misleading

๐Ÿ”— Reference

[KUOCW] ์ตœ๋ฆฐ ๊ต์ˆ˜๋‹˜์˜ ์šด์˜์ฒด์ œ ๊ฐ•์˜๋ฅผ ์ˆ˜๊ฐ•ํ•˜๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์ž˜๋ชป๋œ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜Š

0๊ฐœ์˜ ๋Œ“๊ธ€