]>
Commit | Line | Data |
---|---|---|
6a566b9c | 1 | /* |
1f7b830e | 2 | * Copyright (C) 1996-2025 The Squid Software Foundation and contributors |
6a566b9c | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
6a566b9c | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 20 Storage Manager Heap-based replacement */ |
10 | ||
6a566b9c | 11 | /* |
12 | * The code in this file is Copyrighted (C) 1999 by Hewlett Packard. | |
26ac0430 | 13 | * |
6a566b9c | 14 | * |
15 | * For a description of these cache replacement policies see -- | |
16 | * http://www.hpl.hp.com/techreports/1999/HPL-1999-69.html | |
17 | */ | |
18 | ||
582c2af2 | 19 | #include "squid.h" |
6a566b9c | 20 | #include "heap.h" |
528b2c61 | 21 | #include "MemObject.h" |
602d9612 A |
22 | #include "Store.h" |
23 | #include "store_heap_replacement.h" | |
6a566b9c | 24 | |
074d6a40 | 25 | #include <cmath> |
582c2af2 | 26 | |
6a566b9c | 27 | /* |
28 | * Key generation function to implement the LFU-DA policy (Least | |
29 | * Frequently Used with Dynamic Aging). Similar to classical LFU | |
30 | * but with aging to handle turnover of the popular document set. | |
31 | * Maximizes byte hit rate by keeping more currently popular objects | |
32 | * in cache regardless of size. Achieves lower hit rate than GDS | |
33 | * because there are more large objects in cache (so less room for | |
34 | * smaller popular objects). | |
26ac0430 | 35 | * |
6a566b9c | 36 | * This version implements a tie-breaker based upon recency |
37 | * (e->lastref): for objects that have the same reference count | |
38 | * the most recent object wins (gets a higher key value). | |
39 | * | |
40 | * Note: this does not properly handle when the aging factor | |
41 | * gets so huge that the added value is outside of the | |
42 | * precision of double. However, Squid has to stay up | |
43 | * for quite a extended period of time (number of requests) | |
44 | * for this to become a problem. (estimation is 10^8 cache | |
45 | * turnarounds) | |
46 | */ | |
f0debecb | 47 | heap_key |
b6a7f52c | 48 | HeapKeyGen_StoreEntry_LFUDA(void *entry, double heap_age) |
6a566b9c | 49 | { |
e6ccf245 | 50 | StoreEntry *e = (StoreEntry *)entry; |
6a566b9c | 51 | heap_key key; |
52 | double tie; | |
62e76326 | 53 | |
6a566b9c | 54 | if (e->lastref <= 0) |
62e76326 | 55 | tie = 0.0; |
6a566b9c | 56 | else if (squid_curtime <= e->lastref) |
62e76326 | 57 | tie = 0.0; |
6a566b9c | 58 | else |
62e76326 | 59 | tie = 1.0 - exp((double) (e->lastref - squid_curtime) / 86400.0); |
60 | ||
b6a7f52c | 61 | key = heap_age + (double) e->refcount - tie; |
62e76326 | 62 | |
e4049756 | 63 | debugs(81, 3, "HeapKeyGen_StoreEntry_LFUDA: " << e->getMD5Text() << |
64 | " refcnt=" << e->refcount << " lastref=" << e->lastref << | |
65 | " heap_age=" << heap_age << " tie=" << tie << " -> " << key); | |
62e76326 | 66 | |
cb868059 AR |
67 | if (e->mem_obj) |
68 | debugs(81, 3, "storeId=" << e->mem_obj->storeId()); | |
62e76326 | 69 | |
be1ed2a4 | 70 | return (double) key; |
6a566b9c | 71 | } |
72 | ||
6a566b9c | 73 | /* |
74 | * Key generation function to implement the GDS-Frequency policy. | |
75 | * Similar to Greedy Dual-Size Hits policy, but adds aging of | |
76 | * documents to prevent pollution. Maximizes object hit rate by | |
77 | * keeping more small, popular objects in cache. Achieves lower | |
78 | * byte hit rate than LFUDA because there are fewer large objects | |
79 | * in cache. | |
26ac0430 | 80 | * |
6a566b9c | 81 | * This version implements a tie-breaker based upon recency |
82 | * (e->lastref): for objects that have the same reference count | |
83 | * the most recent object wins (gets a higher key value). | |
84 | * | |
85 | * Note: this does not properly handle when the aging factor | |
86 | * gets so huge that the added value is outside of the | |
87 | * precision of double. However, Squid has to stay up | |
88 | * for quite a extended period of time (number of requests) | |
89 | * for this to become a problem. (estimation is 10^8 cache | |
90 | * turnarounds) | |
91 | */ | |
f0debecb | 92 | heap_key |
b6a7f52c | 93 | HeapKeyGen_StoreEntry_GDSF(void *entry, double heap_age) |
6a566b9c | 94 | { |
e6ccf245 | 95 | StoreEntry *e = (StoreEntry *)entry; |
6a566b9c | 96 | heap_key key; |
97 | double size = e->swap_file_sz ? (double) e->swap_file_sz : 1.0; | |
98 | double tie = (e->lastref > 1) ? (1.0 / e->lastref) : 1.0; | |
b6a7f52c | 99 | key = heap_age + ((double) e->refcount / size) - tie; |
e4049756 | 100 | debugs(81, 3, "HeapKeyGen_StoreEntry_GDSF: " << e->getMD5Text() << |
101 | " size=" << size << " refcnt=" << e->refcount << " lastref=" << | |
102 | e->lastref << " heap_age=" << heap_age << " tie=" << tie << | |
103 | " -> " << key); | |
62e76326 | 104 | |
cb868059 AR |
105 | if (e->mem_obj) |
106 | debugs(81, 3, "storeId=" << e->mem_obj->storeId()); | |
62e76326 | 107 | |
6a566b9c | 108 | return key; |
109 | } | |
110 | ||
62e76326 | 111 | /* |
6a566b9c | 112 | * Key generation function to implement the LRU policy. Normally |
113 | * one would not do this with a heap -- use the linked list instead. | |
114 | * For testing and performance characterization it was useful. | |
115 | * Don't use it unless you are trying to compare performance among | |
116 | * heap-based replacement policies... | |
117 | */ | |
f0debecb | 118 | heap_key |
b6a7f52c | 119 | HeapKeyGen_StoreEntry_LRU(void *entry, double heap_age) |
6a566b9c | 120 | { |
e6ccf245 | 121 | StoreEntry *e = (StoreEntry *)entry; |
26ac0430 AJ |
122 | debugs(81, 3, "HeapKeyGen_StoreEntry_LRU: " << |
123 | e->getMD5Text() << " heap_age=" << heap_age << | |
124 | " lastref=" << (double) e->lastref ); | |
62e76326 | 125 | |
cb868059 AR |
126 | if (e->mem_obj) |
127 | debugs(81, 3, "storeId=" << e->mem_obj->storeId()); | |
62e76326 | 128 | |
6a566b9c | 129 | return (heap_key) e->lastref; |
130 | } | |
f53969cc | 131 |