Lec 3-Scheduling(2)

Lee Nam Gil·2025년 4월 10일

Operating Systems

목록 보기
6/18

Priority Schedulers

Simple Priority Scheduler

SJF, STCF are both priority schedulers

  • Priority is CPU burst time

Also, FCFS and RR are priority schedulers

  • FCFS's priority is arrival time
  • RR's priority is dynamical

Problem with priority scheduling

  • Starvation
    • High priority tasks can dominate the CPU
      \Rightarrow low priority tasks will be starved

Possible solution

  • Dynamically vary priorities based on proces behavior

Simple Priority Scheduler

  • Schedule high priority tasks first
  • No preemption
  • Cannot automatically balance response and turnaround time

EDF: Earilest Deadline First

Each process has a deadline it must finish

  • Tighter deadlines are given higher priority

  • EDF is optimal (assuming preemption)
  • But only useful if processes have known deadlines (e.g. Real-Time OS)

MLQ: Multilevel Queue

Key idea: Divide the ready queue in two

  1. High priority queue for interactive processes
    • RR scheduling
  2. Low priority queue for CPU bound processes
    • FCFS scheduling

Each process is assigned a priority on startup
Each queue is given a fixed amount of CPU time


Problems with MLQ

  • Assume you can classify processes into high and low priority
    • How actually do this at run time
    • What if process's behavior changes over time
  • High biased use of CPU time
    • How can we set the percentage
    • Convoy problems for low priority tasks

MLFQ: Multilevel Feedback Queue

Goals

  • Minimize resopnse and turnaround time
  • Dynamically adjust process priorities over time
    = Move processes between queue based on observed behavior
    • No prior knowledge about burst times or process behavior

First 4 Rules of MLFQ

  1. If Priority(A) > Priority(B), A runs

  2. If Priority(A) = Priority(B), A & B run in RR

  3. Processes start at the highest priority
    = Assume initial process is interactive

  4. Priority change rule
    4a) If a process uses an entire time slice, priority is reduced
    Each level queue has different time slice

    4b) If a process gives up the CPU before its time slice is up, priority level remains
    e.g.) Process performs I/O operations so that context switching occurs

1, 2. Process has time limit \rightarrow priority is reduced
2. MLFQ \approx STCF
3. Blocked on I/O \rightarrow priority level remains


Problems with MLFQ

  • By Rule 4b) Cheating can occur

MLFQ Rule 5: Priority Boost

  • After period SS, move all processes to the highest priority queue (=initialize)
  • Solves two problems
    • Starvation
      • Low priority processes will eventually become high priority
    • Dynamic behavior
      • CPU bound process that has become interactive will be high priority


Revised Rule 4 (Cheat prevention)

Problem :

  • Cheating (Repeatedly yield just before the time limit expires)

Solution :

  • Once a process uses up its time allotment at a given priority, demote its priority
  • Keep track of total CPU time during each time interval SS
    • Instead of looking at continuous CPU time


MLFQ Rule Review

  1. If Priority(A) > Priority(B), A runs
  2. If Priority(A) = Priority(B), A & B run in RR
  3. Processes start at the highest priority
    = Assume initial process is interactive
  4. Once a process uses up its time allotment at given priority, demote it
  5. After some time period SS, move all processes to the highest prioirty queue

Note

  • Achieve goals
    • MLFQ balances response time and turnaround time
    • MLFQ does not require prior knowledge about processes
  • Parameters to tune
    • Number of queue
    • Distribution of CPU time
    • For each queue
      • Which scheduling regime
      • Time slice
  • In practice
    • High priority queues - short time slices
    • Low priority queues - long time slices
      • Low priority - CPU bound - Longer time slice
    • Priority 0 sometimes reserved for OS processes
  • Giving advice
    • Some OS allow users/processes to give the scheduler hints about priority
    • nice command on Linux
      • Run the command with adjusted priority
      • Values -20 ~ 19 is added to process priority

0개의 댓글