Online Algor ithm Paging and Caching. Caching (paging) Structure of data storage Cache memory : Static RAM Level 1 Cache Level 2 Cache Main memory Hard.

Slides:



Advertisements
Similar presentations
9.4 Page Replacement What if there is no free frame?
Advertisements

Online Algorithm Huaping Wang Apr.21
Chapter 11 – Virtual Memory Management
Yannis Smaragdakis / 11-Jun-14 General Adaptive Replacement Policies Yannis Smaragdakis Georgia Tech.
9.1 Strictly Determined Games Game theory is a relatively new branch of mathematics designed to help people who are in conflict situations determine the.
Online Algorithms Advanced Seminar A Supervisor: Matya Katz Ran Taig, Achiya Elyasaf December, 2009.
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Evolution and Repeated Games D. Fudenberg (Harvard) E. Maskin (IAS, Princeton)
Congestion Games with Player- Specific Payoff Functions Igal Milchtaich, Department of Mathematics, The Hebrew University of Jerusalem, 1993 Presentation.
Online Algorithms Amrinder Arora Permalink:
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Competitive Analysis.
1 Competitive analysis of the LRFU paging algorithm Edith Cohen -- AT&T Haim Kaplan -- Tel Aviv Univ. Uri Zwick -- Tel Aviv Univ.
Cache Memory By JIA HUANG. "Computer Science has only three ideas: cache, hash, trash.“ - Greg Ganger, CMU.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management – 4 Page Replacement Algorithms CS 342 – Operating Systems.
Review CPSC 321 Andreas Klappenecker Announcements Tuesday, November 30, midterm exam.
Institute of Computer Science University of Wroclaw Page Migration in Dynamic Networks Marcin Bieńkowski Joint work with: Jarek Byrka (Centrum voor Wiskunde.
Online Algorithms Motivation and Definitions Paging Problem Competitive Analysis Online Load Balancing.
Paging Algorithms Vivek Pai / Kai Li Princeton University.
Lectures in Microeconomics-Charles W. Upton Minimax Strategies.
CSI 400/500 Operating Systems Spring 2009 Lecture #9 – Paging and Segmentation in Virtual Memory Monday, March 2 nd and Wednesday, March 4 th, 2009.
Ecole Polytechnique, Nov 7, Online Job Scheduling Marek Chrobak University of California, Riverside.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Minimax Strategies. Everyone who has studied a game like poker knows the importance of mixing strategies. –With a bad hand, you often fold –But you must.
1 Last Time: Paging Motivation Page Tables Hardware Support Benefits.
Paging for Multi-Core Shared Caches Alejandro López-Ortiz, Alejandro Salinger ITCS, January 8 th, 2012.
Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Maninder Kaur VIRTUAL MEMORY 24-Nov
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
International Graduate School of Dynamic Intelligent Systems, University of Paderborn Improved Algorithms for Dynamic Page Migration Marcin Bieńkowski.
Nash equilibrium Nash equilibrium is defined in terms of strategies, not payoffs Every player is best responding simultaneously (everyone optimizes) This.
Online Paging Algorithm By: Puneet C. Jain Bhaskar C. Chawda Yashu Gupta Supervisor: Dr. Naveen Garg, Dr. Kavitha Telikepalli.
Online Algorithms. Introduction An offline algorithm has a full information in advance so it can compute the optimal strategy to maximize its profit (minimize.
Minimizing Cache Usage in Paging Alejandro López-Ortiz, Alejandro Salinger University of Waterloo.
Second-Chance Algorithm Basically, it’s a FIFO algorithm When a page has been selected, we inspect its reference bit. If the value is 0, we proceed to.
COT 4600 Operating Systems Fall 2009 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 3:00-4:00 PM.
CPSC 404, Laks V.S. Lakshmanan1 External Sorting Chapter 13: Ramakrishnan & Gherke and Chapter 2.3: Garcia-Molina et al.
CSE 5314 On-line Computation Homework 1 Wook Choi Feb/26/2004.
Demand Paged Virtual Memory Andy Wang Operating Systems COP 4610 / CGS 5765.
Page Replacement Algorithms and Simulation Neville Allen.
1 What is Game Theory About? r Analysis of situations where conflict of interests is present r Goal is to prescribe how conflicts can be resolved 2 2 r.
A Optimal On-line Algorithm for k Servers on Trees Author : Marek Chrobak Lawrence L. Larmore 報告人:羅正偉.
A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS.
Memory Management & Virtual Memory © Dr. Aiman Hanna Department of Computer Science Concordia University Montreal, Canada.
Demand Paging Reference Reference on UNIX memory management
1 Chapter 5-1 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
International Graduate School of Dynamic Intelligent Systems, University of Paderborn Fighting Against Two Adversaries: Page Migration in Dynamic Networks.
1  2004 Morgan Kaufmann Publishers Locality A principle that makes having a memory hierarchy a good idea If an item is referenced, temporal locality:
Problem 3.2 Paging Algorithms-Time & Space Requirements Problem:What are the space and time requirements of LIFO, LFU, and LED? LRU:(least-recently-used):
What is it and why do we need it? Chris Ward CS147 10/16/2008.
1 Distributed Vertex Coloring. 2 Vertex Coloring: each vertex is assigned a color.
CACHE MEMORY CS 147 October 2, 2008 Sampriya Chandra.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
COT 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Page Replacement FIFO, LIFO, LRU, NUR, Second chance
Memory Management (2).
Game Theory Just last week:
Better Algorithms for Better Computers
Computer Architecture
Greedy Algorithms / Caching Problem Yin Tat Lee
Demand Paged Virtual Memory
Greedy Algorithms / Caching Problem Yin Tat Lee
Page Replacement FIFO, LIFO, LRU, NUR, Second chance
Exercise (11).
Exercise (10).
Jazan University, Jazan KSA
Module IV Memory Organization.
ARC (Adaptive Replacement Cache)
Chapter 9: Virtual Memory CSS503 Systems Programming
CGS 3763 Operating Systems Concepts Spring 2013
Presentation transcript:

Online Algor ithm Paging and Caching

Caching (paging) Structure of data storage Cache memory : Static RAM Level 1 Cache Level 2 Cache Main memory Hard disk Outside storage Cloud storage How to manage data in Cache (or Main memory)

Model Data is organized into blocks called “pages” Cache can have at most k pages of data If a data in a cache is requested, it costs 0 If a data outside a cache is requested, a page containing the data is loaded from memory to cache (and discard 1 page of data)  called “page fault” A page fault costs 1 unit of time Problem: Which data page should be discarded?

If we know the future action For every algorithm, it may happen a new data is always requested 1 unit for each data request  worst case is same However, an algorithm may need 1000 units while another needs only 10 units. If we know the future, we can design optimal algorithm OPT Not worse than any other algorithm for any sequence of data request If we design compiler to design caching during runtime of a program, we can know (almost) all data requests beforehand What is that algorithm? FFU algorithm = OPT

If you do not know future We consider the competitive ratio ALG/OPT Many algorithms used in practice (and some absurd ones) First-in-First-out: FIFO Last-in-Last-out: LIFO Least Recently Used: LRU Most Recently Used :MRL Least Frequently Used: LFU Random replacement: Random All clear: Clear Marking algorithm: Mark Marking & Random: MarkRand

Algorithms with infinite competitive ratio LIFO (Last in First out) MRU (Most recently used) LFU (least frequently used): We give counter to count the number of requests of each page in cache after it was loaded. LIFO: if the sequence is 1,2,3,..,k, k+1, k, k+1,k, k+1, k…….. Problem: Show bad request sequences for others Question. Do you think they are useless?? There are some works claiming that those algorithms are indeed nice. We may modify the algorithm so that they work better

Performance of LRU Discard least recently used page B A bad scenario: B is requested next. Scenario with k+ 1 pages (say, 1,2,3,…,k+1) Sequence: 1,2,3,…,k, k+1, 1,2,3,…,k, k+1,1,2,3,…,k, k+1 This kind of sequences often happens (in which occasion??) LRU will have page fault every time after the k+1-th request Surprisingly, MRU (most recently used) is the best algorithm for this. MRU causes faults only once for every k requests. LIFO also works. So, the competitive ratio of LRU is at least k  Too bad!! But, experimentally LRU is a very good algorithm  Why??

There is indeed no big hope! Theorem Competitive ratio of any online algorithm ALG is at least k Proof. Suppose we only use k+1 pages. For any online algorithm, the demon can make an input causing page fault every time (request the absent page). But, the optimal algorithm knowing the future causes page fault only once in k times. Theorem Competitive ratio of LRU, FIFO, and Clear is k The number k is usually some hundred or thousand, thus huge. Also, Clear is obviously a bad algorithm in practice. So, this looks the (sad) end of story. Are there any hero to rescue?

Better method to compare algorithms Competitive ratio = ALG/OPT The input sequence is made by a strong adversary (demon) who knows your algorithm Worst input for the algorithm is constructed On the other hand, OPT knows the input sequence This is “Too much handicap” For example, if we play “Janken(rock-paper-scissors)”, you lose all even if you are very clever, but OPT wins all. But, if you play Janken, you do not lose much against anyone.

Oblivious adversary model You design an algorithm using randomness Adversary (demon) reads the algorithm, and make a worst sequence for it. But he cannot predict random coin flip. Your algorithm runs for the sequence, using randomness. Two models: Adversary cannot change the sequence at runtime (oblivious model) Adversary can change the sequence at runtime (adaptive model)

Expected competitive ratio We consider randomized competitive ratio E(ALG)/OPT, where E(ALG) is the expected cost for a randomized algorithm. Exercise: Can you have a better expected competitive ratio than 2 for the ski-rental problem?? Problem: How good expected competitive ratio can be obtained for the caching problem.

Game theory and algorithms Strategy is important: 孫子 (military text by Sun Tzu, 512 BC) 田忌賽馬 : General Deng and the king would compete horses in three races. Deng had three nice horses, but the king had a slightly better three horses. Find a good strategy to win. Game theory: (we have already learned in card gambling problem) John von Neumann : There is an optimal strategy if we consider “mixed strategy” (corresponding to randomized algorithms) 1928 The “last-giant” multi-scientist: Computer, Atomic Bomb, Mathematics, Quantum physics, OR, Economics, Geophysics, etc. Operations Research: Started during WWII  RAND Project (RAND Corporation) von Neumann+Oscar Morgenstern  Economics with game theory 1944 John Nash  Theory of Equilibrium 1950 A.C. Yao  Introduce game theory in randomized algorithm analysis 1977 Algorithmic game theory in theory of computing: From 1999

Marking algorithm(s) Marking algorithm: If a page is requested, we give a mark to that page. If there is a page fault, we select one (or more) unmarked page and discard it. If all pages are marked, we erase all marks. (a,b,c,d)  request a  (A,b,c,d)  request c  (A, b,C,d)  request e  (A,b,C,E)  request b  (a,b,c,e) Exercise: LRU and Clear are marking algorithms, while FIFO is not. Theorem Any marking algorithm has competitive ratio k Idea from game theory: We have a set of marking algorithms each has competitive ratio k for particular sequences of page request, but much better in average. If we mix marking algorithms, its competitive ratio should be better for any sequence.

Random marking algorithm MARK When page fault occurs, select an unmarked page “randomly” Theorem: The competitive ratio E(ALG)/OPT = O( log k) Proof: Basic phase: A maximal time interval after the previous basic phase where only k pages are requested. 1,2,3,2,4,2,1,4,1,3,4,1,2,1,4,1,5,1,3,1,2,1,4 (k=3) (1,2,3,2),(4,5,1,4,1),(3,4,1),(2,3,4,3),(5,1,6,1),(2,3,4) OPT makes s faults in two consecutive basic phases if they have k+s different pages

Can we do better? Theorem For any randomized online algorithm ALG, E(ALG)/OPT = Ω(log n) This means no hope to drastically improve the performance of MARK Tools to prove this: Yao’s minmax principle Coupon collector lemma