Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex...

43
Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz

Transcript of Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex...

Page 1: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Minimizing Cache Usage in PagingAlejandro SalingerUniversity of Waterloo

Joint work with Alex López-Ortiz

Page 2: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Outline

• Paging problem and models• Paging with cache usage• Offline optimum• Online algorithms• Simulations• Conclusions

Page 3: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging

31

14

5

3

8

7

13

9

11

10

15

24

4

18

21

30

17

22

19

2

3

Cache

Memory

Hit!

Memory

Page 4: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging

61

14

5

3

8

7

13

9

11

10

15

24

4

18

21

30

17

22

19

2

Fault!Cache

Memory

6

6

Page 5: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging

Input: sequence of page requests cache size k

Paging algorithm = eviction policyWhat page should be evicted from the cache?

Traditional cost modelHit: 0Fault: 1

Goal: minimize the number of faults

Page 6: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging

Common eviction policies:• Least Recently Used (LRU)• First In First Out (FIFO)• Flush When Full (FWF)• Furthest In The Future (FITF) (offline)

Page 7: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Competitive Analysis• An online algorithm A is r-competitive if for all requests

faults(A)

• Competitive ratio • For any deterministic online algorithm

Page 8: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging Models• Page has fault cost and size• Page fault (classic) model • Uniform size and fault costs

• Weighted caching [Chrobak 91]• Varying fault costs, uniform page sizes

• Fault model [Irani 97]• Varying sizes, uniform fault cost

• Bit model [Irani 97]• Fault cost equals size

• General [Young 98]• k-competitive algorithms for all above

Offline problem is NP-hard

Page 9: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging Models• Full Access Cost [Torng 98]• Hit: 1• Fault:• Marking algorithms: • Coincides with classic model when • Captures locality of reference

Page 10: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging Models• Buying Cache Model [Csirik et al. 01]• Algorithm may purchase cache at cost c(x)• Cost = faults + purchased cache• Approximation to upgrading memory systems• Cost functions

• CR(A)≈3.14619• CR(A)≈d/ln d+o(d/ln d)• Finite competitive ratio cost is polynomially bounded

Page 11: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging with Cache Usage

Page 12: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Paging with Cache Usage• Input: sequence , cache size k• Cost: faults + amount of cache used• k(i): number of pages in cache at request i• k(i) ≤ k• Cache usage: • Total cost

Goal: minimize total cost

fault cost cell cost

Page 13: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Applications• Shared cache multiprocessors

Page 14: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Applications• Shared cache multiprocessors• Cooperative caching

Page 15: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Applications• Energy efficient caching• Content Addressable Memories (CAMs)

1

14

5

3

8

7

13

9

11

10

15

24

4

18

21

30

17

22

19

2

Cache

3

Page 16: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Applications• Energy efficient caching• Content Addressable Memories (CAMs)• Power of search proportional to valid cells

1 5

3

8

7 9 10

15

24

4

30 22 2

Cache

3

Page 17: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Offline Optimum

Page 18: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

…,3,3,4,5,21,3,4,17,5,3,5,5,6,7,8, ???

Offline Optimum• But paging is an online problem!• Offline algorithm can lead to good online algorithms• Classic paging optimum: FITF

• LRU

…,3,3,4,5,21,3,4,17,5,3,5,5,6,7,8,9,6,7,4,4,5,3,15,13,3,3,7,8,9,…

8,7,6,5,5,3,5,17,4

Page 19: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Interval Scheduling1 2 3 4 1 1 3 5 2 3 4 5 1 21 2 3 4 1 1 3 5 2 3 4 5 1 2

• Interval scheduling:• : set of jobs (start time, duration, weight)• m machines• Goal: process of maximum weight• Polytime solution via reduction to minimum-cost flow

Page 20: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Interval Scheduling

: interval representation of (without unfinished intervals)

is feasible schedule of on k-1 machines can be served with cache size k, with with faults and cache usage

1 2 3 4 1 1 3 5 2 3 4 5 1 2

Page 21: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Interval Scheduling

• Minimize faults Maximal Interval Scheduling• Greedy by earliest finish time (= FITF’) • Maximizes number of intervals• Cache usage is not optimal

• Weight assignment: • , • Max weight schedule = minimum faults with minimum cache

1 2 3 4 1 1 3 5 2 3 4 5 1 2

Page 22: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Offline Optimum• Recall, we want to minimize

• Note: optimal does not schedule an interval with • Opt(σ,k):• Compute interval representation• Remove unfinished intervals and intervals with • Assign weights

• Optimal cost =

• time (with [Arkin and Silverberg 87])

Page 23: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Online Algorithms

Page 24: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Online Algorithms

• Marking algorithm: at most k faults in each phase• LRU, FWF, CLOCK

• Conservative algorithm: at most k faults• LRU, FIFO, CLOCK

≤ k distinct pages

≤ k distinct pages

≤ k ≤ k ≤ k ≤ k ≤ k

Page 25: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Online Algorithms• Marking or conservative algorithms are still k-competitive• But they use all available cache

• Family of cost sensitive algorithms• Let be any paging algorithm• : • At t=i, evict page requested at t=i-d if still in cache and was not

requested since• If necessary, evict page according to A’s eviction policy

Page 26: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Online Algorithms

• A is marking or conservative• What is a good choice for d?

• Set d =

• ?

p p

OPT

p p

OPT

Not quite…

Page 27: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

• Let A be marking or conservative

Competitive Ratio of (lower bound)

k = 10

Page 28: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

(1) Request page not in cache among

Cache is never full → no early evictions pays per request OPT doesn’t keep any pages, pays

… 1 2 3 4 5 6 1 2 3 4 …

𝛼

Competitive Ratio of (lower bound)

𝐴𝛼

𝑂𝑃𝑇≥2−

1𝛼+1

Page 29: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Competitive Ratio of (lower bound)

(2) Request page not in cache among

… …In phase:: k faults, pays at least cacheOPT keeps k pages and faults once: 1 fault, cache

4 3 1 6 7 5 8 9 2 0 6 2 3 1k = 9

Page 30: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Competitive Ratio of (upper bound)

• For any conservative or marking A

𝐶𝑅 (𝐴𝛼 )≤ { 2−1

𝛼+1,𝛼<𝑘

¿min(𝑘 , 𝛼 (𝑘+1 )𝑘+𝛼−1 ) ,𝛼≥𝑘

k = 10

Page 31: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Competitive Ratio of (upper bound)

(2)

OPT

𝐴𝛼

𝑂𝑃𝑇≤𝑘

Page 32: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Competitive Ratio of (upper bound)

Page 33: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Competitive Ratio of (upper bound)

Page 34: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Competitive Ratio of (upper bound)

𝐴𝛼

𝑂𝑃𝑇≤𝛼 (𝑘+1 )𝑘+𝛼−1

Page 35: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Locality of Reference• L = Average length of phase in k-phase partition

𝐶𝑅 (𝐴𝛼 )≤ {2𝐿>𝑘𝛼 (𝛼−2)

1+𝑘 (𝛼−1 )+1𝛼+𝑘−1+𝐿

k = 10L = 150

Page 36: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Simulations

Page 37: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Cost Ratio k=5

Page 38: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Cost Ratio k=7

Page 39: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Faults k=5

Page 40: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Faults k=7

Page 41: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Average Cache Usage k=5

Page 42: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Average Cache Usage k=7

Page 43: Minimizing Cache Usage in Paging Alejandro Salinger University of Waterloo Joint work with Alex López-Ortiz.

Conclusions• Introduced Minimum Cache Usage problem• Cost-sensitive family of online algorithms • 2 ≤ CR(α) ≤ k• 2-competitive for sequences with high locality

• Polynomial time optimal offline algorithm• Algorithms highly competitive in practice

• Future Work:• Deeper lower bound analysis• Other online algorithms• Applications, e.g., shared cache cooperative strategy

Thank you