0% found this document useful (0 votes)
505 views15 pages

Multi Level Feedback Scheduling

Uploaded by

Meghana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
505 views15 pages

Multi Level Feedback Scheduling

Uploaded by

Meghana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

18CS2102R

Operating Systems
Session 8
Scheduling: The Multi-Level Feedback Queue

© 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED 1
Multi-Level Feedback Queue (MLFQ)
• A Scheduler that learns from the past to predict the future.
• Objective:
• Optimize turnaround time  Run shorter jobs first
• Minimize response time without a priori knowledge of job length.

2
MLFQ: Basic Rules
• MLFQ has a number of distinct queues.
• Each queues is assigned a different priority level.

• A job that is ready to run is on a single queue.


• A job on a higher queue is chosen to run.
• Use round-robin scheduling among jobs in the same queue

Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t).


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

3
MLFQ: Basic Rules (Cont.)
• MLFQ varies the priority of a job based on its observed behavior.
• Example:
• A job repeatedly relinquishes the CPU while waiting IOs  Keep its priority
high
• A job uses the CPU intensively for long periods of time  Reduce its priority.

4
MLFQ Example
[High Priority] Q8
A B
Q7

Q6

Q5

Q4
C
Q3

Q2

[Low Priority] Q1
D

5
MLFQ: How to Change Priority
• MLFQ priority adjustment algorithm:
• Rule 3: When a job enters the system, it is placed at the highest priority
• Rule 4a: If a job uses up an entire time slice while running, its priority is
reduced (i.e., it moves down on queue).
• Rule 4b: If a job gives up the CPU before the time slice is up, it stays at the
same priority level

In this manner, MLFQ approximates SJF

6
Example 1: A Single Long-Running
Job
• A three-queue scheduler with time slice 10ms

Q2

Q1

Q0

0 50 100 150 200

Long-running Job Over Time (msec)

7
Example 2: Along Came a Short Job
• Assumption:
• Job A: A long-running CPU-intensive job
• Job B: A short-running interactive job (20ms runtime)
• A has been running for some time, and then B arrives at time T=100.

Q2 A:

Q1 B:

Q0

0 50 100 150 200

Along Came An Interactive Job (msec)


8
Example 3: What About I/O?
• Assumption:
• Job A: A long-running CPU-intensive job
• Job B: An interactive job that need the CPU only for 1ms before performing an
I/O
Q2 A:

Q1 B:

Q0

0 50 100 150 200

A Mixed I/O-intensive and CPU-intensive Workload (msec)

The MLFQ approach keeps an interactive job at the highest priority

9
Problems with the Basic MLFQ
• Starvation
• If there are “too many” interactive jobs in the system.
• Lon-running jobs will never receive any CPU time.

• Game the scheduler


• After running 99% of a time slice, issue an I/O operation.
• The job gain a higher percentage of CPU time.

• A program may change its behavior over time.


• CPU bound process  I/O bound process

10
The Priority Boost
• Rule 5: After some time period S, move all the jobs in the system to
the topmost queue.
• Example:
• A long-running job(A) with two short-running interactive job(B, C)

Q2 Q2

Q1 Q1

Q0 Q0

0 50 100 150 200 0 50 100 150 200

Without(Left) and With(Right) Priority Boost A: B: C:


11
Better Accounting
• How to prevent gaming of our scheduler?
• Solution:
• Rule 4 (Rewrite Rules 4a and 4b): Once a job uses up its time allotment at a
given level (regardless of how many times it has given up the CPU), its priority
is reduced(i.e., it moves down on queue).

Q2 Q2

Q1 Q1

Q0 Q0

0 50 100 150 200 0 50 100 150 200

Without(Left) and With(Right) Gaming Tolerance


12
Tuning MLFQ And Other Issues
Lower Priority, Longer Quanta

• The high-priority queues  Short time slices


• E.g., 10 or fewer milliseconds
• The Low-priority queue  Longer time slices
• E.g., 100 milliseconds

Q2

Q1

Q0

0 50 100 150 200


Example) 10ms for the highest queue, 20ms for the middle,
40ms for the lowest
13
The Solaris MLFQ implementation
• For the Time-Sharing scheduling class (TS)
• 60 Queues
• Slowly increasing time-slice length
• The highest priority: 20msec
• The lowest priority: A few hundred milliseconds
• Priorities boosted around every 1 second or so.

14
MLFQ: Summary
• The refined set of MLFQ rules:
• Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t).
• Rule 2: If Priority(A) = Priority(B), A & B run in RR.
• Rule 3: When a job enters the system, it is placed at the highest priority.
• Rule 4: Once a job uses up its time allotment at a given level (regardless of
how many times it has given up the CPU), its priority is reduced(i.e., it moves
down on queue).
• Rule 5: After some time period S, move all the jobs in the system to the
topmost queue.

15

You might also like