Coder Social home page Coder Social logo

sonisiddharth / cache_replacement_policies Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 159 KB

Cache Replacement Policies in operating system from scratch

Makefile 2.17% C 94.60% Python 3.23%
complexity workload loop-workload random-workloads fifo lru-cache lru lru-replacement-algorithm fifo-cache

cache_replacement_policies's Introduction

Cache replacement policies

This is the implementation of differnt cache replacement policies with analyzing them on different workloads.

Policies: LRU (exact and approx), FIFO, Random Workloads: 80-20 (local), looping, random

Usage

To generate plots for each workload use make as follows:

  1. Random Workload - make random
  2. Looping Workload - make loop
  3. Local Workload - make local

Plots and Analysis

Random Workload

alt text

80-20 Workload

alt text

Loop Workload

alt text

Policy Analysis

  • hit function will iterate through the cache array to search for a page so it takes linear time to search for a page. Time complexity of this function is O(cache size)

FIFO (First In First Out) Policy

  1. Time complexity - the algorithm will iterate over the workload containing pages to be accessed. For each page, a call to hit function will take O(cache size). Therefore the overall time complexity becomes O(workload size * cache size)

  2. Space complexity - It takes an array for storing cache O(cache size)

Random Policy

  1. Time complexity -

    • the algorithm will iterate over the workload containing pages to be accessed. For each page, a call to hit function will take O(cache size). Therefore the overall time complexity becomes O(workload size * cache size)

    • Do this policy takes O(1) time? - No the policy do not take a constant time for a page because the page to be replaced is selected by a random choice so to replace that page in the cache it will take linear time to search for that node. However it is not taking the linear time here because of linear time search also.

  2. Space complexity - It takes an array for storing cache O(cache size)

Least Frequently Used (LRU) Policy

  1. Time complexity -

    • the algorithm will iterate over the workload containing pages to be accessed. For each page, a call to hit function will take O(cache size). Therefore the overall time complexity becomes O(workload size * cache size)
  2. Space complexity - It takes an array for storing cache O(cache size)

Least Frequently used Approx Policy

  1. Time complexity -

    • the algorithm will iterate over the workload containing pages to be accessed. For each page, a call to hit function will take O(cache size).

    • After getting a miss the algorithm searches for a page whose used bit is 1 which takes a linear time. Therefore the overall time complexity becomes O(workload size * cache size)

  2. Space complexity - It takes array for storing cache and one more array to store used bits so complexity becomes O(2*cache size)

cache_replacement_policies's People

Contributors

sonisiddharth avatar

Stargazers

 avatar

Watchers

 avatar

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.