Giter VIP home page Giter VIP logo

multi-level-feedback-queue-scheduling-algorithm's Introduction

Multilevel Feedback Queue Scheduling Algorithm

The multilevel feedback queue is a method of kernel scheduling that attempts to resolve the problems associated with First-Come-First-Serve (FCFS) scheduling and Shortest-Job-First (SJF) scheduling, namely inefficient turnaround times for interactive and real-time processes and job starvation respectively.

Multilevel feedback queue (MLFQ) scheduling uses a system of queues, each designated a different priority. Each queue is assigned a different quantum time for Round-Robin (RR) scheduling. The important thing to note about MLFQ scheduling is that it is preemptive: a currently running process can be removed from the CPU if another process is deemed to be of higher priority. At each cycle of the CPU, processes can be moved between queues, and therefore the priority of a process can be considered dynamic.

This implementation in Python is a simple demonstration of Multilevel Feedback Queue Scheduling, and is by no means a directly translatable implementation to an operating system's kernel. There are 256 different priorities, and therefore 256 queues in this sample system.

Transitions to consider

  1. New process: goes to first priority queue Q0

  2. Process leaves voluntarily (process yields or blocks for I/O): process leaves system and is inserted back in the same queue when it returns

  3. Process takes up quantum time at Q[X]: bump down to the next priority queue Q[X+1]

  4. Process blocks for I/O at Q[X]: bump up to a higher priority queue Q[X-1] to allow escape from lowest priority level (prevents starving)

Procedure:

  1. Move processes to their positions

  2. pick first process in topmost queue

*** Given current process currProc and list of queues queues: ***

First step:

Q = queue of currProc
index = index of Q
p = currProc

if p is blocking for I/O:
    save processing state to p.PCB

    Q.dequeue()

    if index == 0:
        Q.enqueue(p)

    else:
        queues[index-1].enqueue(p)

    endif

elif p leaves voluntarily:
    save processing state to p.PCB

    Q.dequeue()

    store (p.pid, index)

else:
    p.taskTime -= 1

    p.Qtime -= 1

    if quantum time finished (p.Qtime <= 0):
        save processing state to p.PCB
        Q.dequeue()

        if task not finished (p.taskTime > 0):
            queues[index+1].enqueue(p)

        else:
            destroy(p)

        endif

    elif task finished (p.taskTime <= 0):
        Q.dequeue()

        destroy(p)

    else:
        pass

    endif

endif

Second step:

for Q in queues:
  if Q is not empty:
    p = Q.peek()
    currProc = p
    send p to CPU
    break
  endif
endfor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.