Modul 3 - Scheduling Flashcards
What is turnaround time? (Omloppstiden)
- Turnaround time = Finish time - Arrival time
- The time it takes for a process to finish execution minus the time when the process entered the system.
- It’s the time required for a particular process to complete, from submission time to completion. It is equal to the sum total of Waiting time and Execution time.
What is response time? (Responstiden)
- Response time = First run time (first scheduled) - Arrival time
- The time a process first gets to run minus the time the process entered the system
- Response time - The time taken in a program from the issuance of a command to the commence of a response to that command.(i.e., the time-interval between submission of a request, and the first response to that request, not the output .)
Scheduling algorithms?
- First in first out (FIFO)
- Shortest job first (SJF)
- Shortest time to completion first (STCF)
- Round Robin (RR)
- Multilevel feedback queue (MLFQ)
Explain First in first out (FIFO) scheduling algorithm
The processes run to completion in the order in which they came in.
Explain Shortest job first (SJF) scheduling algorithm
Runs the processes that has the shortest execution time to run first. It’s a non-preempt scheduler.
Explain Shortest time to completion first (STCF) scheduling algorithm
Like SJF, which runs the processes that has the shortest execution time first, but it is possible to stop and run processes alternately (växelvis). It’s a preempt scheduler.
Solves the problem of SJF, if a process that takes longer time to complete arrives before another process that is shorter.
So any time a new process enters the system the STCF scheduler determines which of the remaining jobs (including the new job) has the least time left, and schedules that one.
Alltså om process1 tar 30 ms anländer vid tid 0ms och process2 tar 10 ms och anländer vid tid 10 ms. Så kommer process1 att pausas och process2 börja köras tills den blir klar. Sen återuptas process1 igen. (Om inte det finns någon annan kortare process som väntar på att köras)
- Bad response time.
Explain Round Robin (RR) scheduling algorithm
•Runs processes in time slices.
For example if we have three process that all take 40 ms to complete. Then we can improve the response time by giving each process a time-slice of 10 ms. So it alternates between the processes every 10ms.
•Good for response time but really bad for turnaround time. (worst policy for turnaround time).
- What RR is doing is stretching out each job as long as it can, by only running each job for a short bit before moving to the next. Because turnaround time only cares about when jobs finish, RR is nearly pessimal, even worse than simple FIFO in many cases.
- Making the time slice too short is problematic: suddenly the cost of context switching will dominate overall performance.
What are the problems with scheduling algorithms such as Shortest job first (SJF) and Shortest time to completion first (STCF) and how can we address the problem?
- Problems with algorithms such as SJF and STCF is that we cannot know in advance how long a program will run.
- Multilevel feedback queue addresses this problem
How does Multilevel feedback queue (MLFQ) scheduling algorithm work?
- It decides which processes run first by observing their behavior and assigning different priorities. Processes with high priority are chosen to run first. Processes with the same priority runs with round-robin scheduling (RR).
- MLFQ has a number of distinct queues, each assigned to a different priority level.
- MLFQ tries to optimize turnaround time and minimize response time (to make the program feel more interactive).
- If a process uses the CPU under a long amount of time => low priority
- If a process gives away CPU time often, for example while waiting for input from the keyboard => keeps its high priority (as this is how an interactive process might behave.)
- MLFQ will try to learn about processes as they run, and thus use the history of the job to predict its future behavior.
- Because it dosen’t know how long a processes will be, it will assume that is short (set to high priority first) and then lower the priority if the processes consumes all the time that is given in each priority level.
Assume we have a scheduler that implements “shortest job first” i.e. not able to preempt jobs. If we have three jobs that will take 10ms, 20ms and 30ms it’s a better strategy than taking the jobs in random order, show why. (Tenta fråga)
Answer:
- Turnaround time = (10 + 30 + 60) / 3 = 33 ms
- Wrong order could give turnaround time = (30 + 50 + 60) / 3 = 47 ms
Where turnaround time is : Finish time - Arrival time
What happens to a process if it initiates a I/O-operation? (Scheduling)
- An I/O-operation will take time to complete and we (the CPU) could do some useful work while a process is waiting.
- That is why a process is descheduled if it is preempted or if it initiates a I/O-operation. It enters the blocked state. When the I/O is completed it will enter the ready state.
What is the convoy effect?
It when a number of relatively-short potential consumers of a resource get queued behind a heavyweight resource consumer.
For example if we use FIFO (first in first out) with with two processes , process1 (takes 5 ms to complete) and process2 (takes 20 ms to complete). If process2 arrives before, then we get the convoy effect.
To fix this use SJF (Shortest job first).
Preemptive vs non-preemptive schedulers?
- non-preemptive schedulers run each job to completion before considering whether to run a new job.
- preemptive schedulers quite willing to stop one process from running in order to run another. Virtually all modern schedulers are this way.
This implies that the scheduler employs a context switch, stopping one running process temporarily and resuming (or starting) another.
What is the cost of a context switch? (switching which process that runs on the CPU)
The cost of context switching does not arise solely from the OS actions of saving and restoring a few registers. When programs run, they build up a great deal of state in CPU caches, TLBs, branch predictors, and other on-chip hardware. Switching to another job causes this state to be flushed and new state relevant to the currently running job to be brought in, which may exact a noticeable performance cost.
Which rules has the Multilevel feedback queue (MLFQ) scheduling policy?
MLFQ rules:
- Rule 1: If Priority(A) > Priority (B) => A is scheduled for execution.
- Rule 2: If Priority(A) = Priority (B) => A and B are scheduled in round-robin (RR), i.e., time-slices.
- Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue). i.e., when a new job is created it starts with the highest priority.
— A job is given a allotted time, to consume at each priority level. —-
• Rule 4: a job that has consumed its allotted time (regardless of how many times it has given up the CPU) is moved to a lower priority.
- With such protections in place, regardless of the I/O behavior of the process, it slowly moves down the queues, and thus cannot gain an unfair share of the CPU.
• Rule 5: After some time period S, move all jobs to the highest priority. (Solves starvation problem: which is if there are too many short jobs it will never let a long running job finish.)
How are time-slices usually distributed in MLFQ scheduling?
- Most MLFQ variants allow varying time-slice length across different queues. Where the highest priority queues are usually given short time slices (consists of interactive jobs, thus quickly alternates between them which makes sense for higher response time). And long time slices for long-running jobs that are CPU-bound.
How is the performance of MLFQ?
- MLFQ can deliver excellent overall performance ( similar to SJF/STCF) for short-running interactive jobs, and is fair and makes progress for long-running CPU-intensive workloads. Many systems use a form of MLFQ.
What is proportional-share scheduler (fair-share scheduler)?
Proportional-share is a scheduling algorithm which tries to guarantee that each job obtain a certain percentage of CPU time. Instead of trying to optimize for turnaround or response time.
Name a few proportional/fair-share schedulers? (fixa)
- Lottery scheduling (random/ non-deterministic)
- Stride scheduling (deterministic)
- Completely Fair Scheduler (CFS) (Used in Linux)
Basic idea of the lottery scheduling?
The basic idea is quite simple: every so often, hold a lottery to determine which process should get to run next; processes that should run more often should be given more chances to win the lottery.
What are tickets in lottery scheduling?
tickets are used to represent the share of a resource that a process (or user or whatever) should receive. The percent of tickets that a process has represents its share of the system resource in question.
For example if process A has 75 tickets and process B has 25 tickets then A recives75% of the CPU and B the remaining 25%. (In a case where there are only two processes)
How does the lottery scheduler determine which process to run?
Each process is given an amount of tickets and every so often (say, every time slice) a lottery is being hold. Where the scheduler picks a winning ticket (randomly). The process that holds the winning ticket is the process which gets to run.
(The lottery scheduler keeps track how many tickets have been distributed).
Flexibility with the lottery scheduler? (fixa)
- A new job can be given a set of tickets as long as we keep track of how many tickets we have.
- We can give a user a set of tickets and allow the user to distribute them among its jobs. (ticket currency)
- Each user can have its local tickets and then have a local lottery.
- We could allow each user to create new tickets, i.e. inflation, if we trust each other. (ticket inflation)
Explain the mechanism to manipulate tickets called ticket currency?
Currency allows a user with a set of tickets
to allocate tickets among their own jobs in whatever currency they would like; the system then automatically converts said currency into the correct global value.
For example, assume users A and B have each been given 100 tickets. User A is running two jobs, A1 and A2, and gives them each 500 tickets (out of 1000 total) in User A’s own currency. User B is running only 1 job and gives it 10 tickets (out of 10 total). The system will convert A1’s and A2’s allocation from 500 each in A’s currency to 50 each in the global currency; similarly, B1’s 10 ticketswill be converted to 100 tickets. The lottery will then be held over the global ticket currency (200 total) to determine
which job runs.
User A –> 500 (A’s currency) to A1 –> 50 (global currency)
–> 500 (A’s currency) to A2 –> 50 (global currency)
User B -> 10 (B’s currency) to B1 -> 100 (global currency)