]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/repl/heap/store_heap_replacement.cc
1bee98bf557a47797ca3fe4b42b3dd456119181d
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 20 Storage Manager Heap-based replacement */
12 * The code in this file is Copyrighted (C) 1999 by Hewlett Packard.
15 * For a description of these cache replacement policies see --
16 * http://www.hpl.hp.com/techreports/1999/HPL-1999-69.html
21 #include "MemObject.h"
23 #include "store_heap_replacement.h"
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).
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).
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
48 HeapKeyGen_StoreEntry_LFUDA(void *entry
, double heap_age
)
50 StoreEntry
*e
= (StoreEntry
*)entry
;
56 else if (squid_curtime
<= e
->lastref
)
59 tie
= 1.0 - exp((double) (e
->lastref
- squid_curtime
) / 86400.0);
61 key
= heap_age
+ (double) e
->refcount
- tie
;
63 debugs(81, 3, "HeapKeyGen_StoreEntry_LFUDA: " << e
->getMD5Text() <<
64 " refcnt=" << e
->refcount
<< " lastref=" << e
->lastref
<<
65 " heap_age=" << heap_age
<< " tie=" << tie
<< " -> " << key
);
68 debugs(81, 3, "storeId=" << e
->mem_obj
->storeId());
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
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).
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
93 HeapKeyGen_StoreEntry_GDSF(void *entry
, double heap_age
)
95 StoreEntry
*e
= (StoreEntry
*)entry
;
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;
99 key
= heap_age
+ ((double) e
->refcount
/ size
) - tie
;
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
<<
106 debugs(81, 3, "storeId=" << e
->mem_obj
->storeId());
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...
119 HeapKeyGen_StoreEntry_LRU(void *entry
, double heap_age
)
121 StoreEntry
*e
= (StoreEntry
*)entry
;
122 debugs(81, 3, "HeapKeyGen_StoreEntry_LRU: " <<
123 e
->getMD5Text() << " heap_age=" << heap_age
<<
124 " lastref=" << (double) e
->lastref
);
127 debugs(81, 3, "storeId=" << e
->mem_obj
->storeId());
129 return (heap_key
) e
->lastref
;