Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Scheduling Disciplines: Preemptive vs. Non-Preemptive and Size-Based vs. Non-Size-Based, Lecture notes of Operating Systems

Different scheduling disciplines for queueing models, focusing on preemptive and non-preemptive strategies, as well as size-based and non-size-based algorithms. Preemptive scheduling allows stopping and restarting jobs, while non-preemptive scheduling runs jobs to completion. Size-based algorithms consider job size, while non-size-based algorithms do not. The document uses average residence time as a metric to evaluate scheduling disciplines and provides examples of various scheduling strategies, including fcfs, lcfs, random, lcfspr, ps, sjf, and srpt.

Typology: Lecture notes

2021/2022

Uploaded on 09/27/2022

jeena
jeena 🇬🇧

4.2

(6)

215 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 547 Lecture 17: Scheduling
Daniel Myers
Thus far, we’ve only considered first-come-first-serve scheduling in our queueing models. Though FCFS is a
popular choice for many real applications, other scheduling disciplines are possible.
Classifiying Scheduling Disciplines
For this lecture, we’ll classify scheduling strategies based on two qualities
preemptive vs. non-preemptive
size-based vs. non-size-based
In preemptive scheduling, it’s possible to stop a currently executing job, run something else, then return the
original job to service at a later time. We almost always assume that preempted jobs return to service at
the point the left off. In a non-preemptive scheduler, a job only runs to completion once started.
In a size-based algorithm, we know the service requirement of each job and can take these requirements into
account when making scheduling decisions. This allows us to give priority to shorter jobs, which generally
improves performance.
Several metrics have been proposed to evaluate the quality of scheduling disciplines. In this lecture, we’ll
use average residence time, R, as our metric of choice.
Non-Preemptive, Non-Size-Based
This category includes all disciplines that run jobs to completion and do not consider job size.
FCFS falls into this category. Two other popular disciplines with these characteristics are last-come-first-
serve (LCFS) and RANDOM.
LCFS: when the server becomes available, run the job that arrived most recently
RANDOM: when the server becomes available, choose randomly from among all waiting jobs
Somewhat surprisingly, all of these disciplines have the same average residence time. In fact, any non-
preemptive, non-size-based scheduling strategy has the same average residence time as FCFS. By extension,
we can use the M/G/1 residence time equation to calculate Rin any of these queues.
A full proof of this theorem requires reasoning about the full behavior of the queue length distribution using
transform theory, but we can easily analyze the LCFS case to show why the theorem is reasonable.
Consider the waiting time in an M/G/1-LCFS queue. There are two components to the waiting time: the
residual of the customer currently in service (because all jobs run to completion), and the waiting time due
to jobs that arrive after the tagged job arrives, but before it enters service.
1
pf3
pf4

Partial preview of the text

Download Scheduling Disciplines: Preemptive vs. Non-Preemptive and Size-Based vs. Non-Size-Based and more Lecture notes Operating Systems in PDF only on Docsity!

CS 547 Lecture 17: Scheduling

Daniel Myers

Thus far, we’ve only considered first-come-first-serve scheduling in our queueing models. Though FCFS is a popular choice for many real applications, other scheduling disciplines are possible.

Classifiying Scheduling Disciplines

For this lecture, we’ll classify scheduling strategies based on two qualities

  • preemptive vs. non-preemptive
  • size-based vs. non-size-based

In preemptive scheduling, it’s possible to stop a currently executing job, run something else, then return the original job to service at a later time. We almost always assume that preempted jobs return to service at the point the left off. In a non-preemptive scheduler, a job only runs to completion once started.

In a size-based algorithm, we know the service requirement of each job and can take these requirements into account when making scheduling decisions. This allows us to give priority to shorter jobs, which generally improves performance.

Several metrics have been proposed to evaluate the quality of scheduling disciplines. In this lecture, we’ll use average residence time, R, as our metric of choice.

Non-Preemptive, Non-Size-Based

This category includes all disciplines that run jobs to completion and do not consider job size.

FCFS falls into this category. Two other popular disciplines with these characteristics are last-come-first- serve (LCFS) and RANDOM.

  • LCFS: when the server becomes available, run the job that arrived most recently
  • RANDOM: when the server becomes available, choose randomly from among all waiting jobs

Somewhat surprisingly, all of these disciplines have the same average residence time. In fact, any non- preemptive, non-size-based scheduling strategy has the same average residence time as FCFS. By extension, we can use the M/G/1 residence time equation to calculate R in any of these queues.

A full proof of this theorem requires reasoning about the full behavior of the queue length distribution using transform theory, but we can easily analyze the LCFS case to show why the theorem is reasonable.

Consider the waiting time in an M/G/1-LCFS queue. There are two components to the waiting time: the residual of the customer currently in service (because all jobs run to completion), and the waiting time due to jobs that arrive after the tagged job arrives, but before it enters service.

On average, we expect λW customers to arrive during the tagged customer’s waiting period, and each requires an average service time of s.

W = U

s 2

(1 + c^2 s) + λW s

sU (1 + c^2 s) 2(1 − U )

This result is exactly the waiting time in an M/G/1-FCFS queue.

Preemptive, Non-Size-Based

This category includes disciplines that can start and stop jobs at will, but do not take into account job size when making decisions. There are two main disciplines in this category: last-come-first-serve-preemptive- resume (LCFSPR) and processor sharing (PS).

LCFSPR

LCFSPR is the preemptive version of LCFS scheduling.

  • LCFSPR: when a new job arrives to the queue, preempt the currently running job and put the new job into service. When a job departs, return the most recent remaining job back to service. Jobs that return to service after being preempted resume at the point they left off.

A customer arriving to an LCFSPR queue does not have to wait for the customer currently in service, but it may be preempted by other jobs that arrive while it is running. Those jobs, in turn, may be preempted by other arriving jobs. If the customer’s average residence time is R, then we expect λR jobs to arrive during the residence period.

R = λR s + s

=

s 1 − U

This is an unexpected result. The average residence time in a M/G/1-LCFSPR queue is the same as an M/M/1 queue!

PS

Many computer systems use round-robin (RR) scheduling for the processor. In RR scheduling, each job is allowed to run for a certain quanta of time. When a job’s quanta expires, the operating system stops the job and performs a context switch to allow a new job to run. At some time in the future, the OS will return the stopped job back to service, where it will be allowed to run for another quanta.

Processor sharing scheduling is the idealized form of round robin with infinitely small quanta. If there are k jobs in the queue at a given moment, each job is simultaneously receiving exactly (^) k^1 of the server’s total processing power at that instant. Analyzing PS is non-trivial, but it’s possible to show that

R =

s 1 − U

Most modern operating systems use some form of multi-level feedback queue (MLFQ). In an MLFQ scheduler, each job is assigned a priority level. Jobs at lower priority levels are only allowed to run if there are no higher- priority jobs currently in the system. When a new job arrives, it is automatically assigned the highest priority level and begins running immediately. Typically, a job’s priority is reduced once it’s accumulated a certain amount of service time at its current level. If multiple jobs at the same priority level are present, they share the processor in round-robin fashion.

There are many variations to the basic MLFQ idea. For example,

  • the system may have dozens of distinct priority levels
  • the very highest priorities may be reserved for the OS
  • the running quanta of a job may depend on its priority – giving lower priorities a longer quanta allows CPU-bound jobs to make more progress when they finally run
  • I/O bound jobs may be allowed to stay at high priority to improve responsiveness
  • periodically restoring a low-priority job to high-priority keeps long jobs from starving