1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
/*-
* Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/time.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "cacheplcs.h"
#include "debug.h"
static void cache_fifo_policy_update_item(struct cache_policy_ *,
struct cache_policy_item_ *);
static void cache_lfu_policy_add_item(struct cache_policy_ *,
struct cache_policy_item_ *);
static struct cache_policy_item_ * cache_lfu_policy_create_item(void);
static void cache_lfu_policy_destroy_item(struct cache_policy_item_ *);
static struct cache_policy_item_ *cache_lfu_policy_get_first_item(
struct cache_policy_ *);
static struct cache_policy_item_ *cache_lfu_policy_get_last_item(
struct cache_policy_ *);
static struct cache_policy_item_ *cache_lfu_policy_get_next_item(
struct cache_policy_ *, struct cache_policy_item_ *);
static struct cache_policy_item_ *cache_lfu_policy_get_prev_item(
struct cache_policy_ *, struct cache_policy_item_ *);
static void cache_lfu_policy_remove_item(struct cache_policy_ *,
struct cache_policy_item_ *);
static void cache_lfu_policy_update_item(struct cache_policy_ *,
struct cache_policy_item_ *);
static void cache_lru_policy_update_item(struct cache_policy_ *,
struct cache_policy_item_ *);
static void cache_queue_policy_add_item(struct cache_policy_ *,
struct cache_policy_item_ *);
static struct cache_policy_item_ * cache_queue_policy_create_item(void);
static void cache_queue_policy_destroy_item(struct cache_policy_item_ *);
static struct cache_policy_item_ *cache_queue_policy_get_first_item(
struct cache_policy_ *);
static struct cache_policy_item_ *cache_queue_policy_get_last_item(
struct cache_policy_ *);
static struct cache_policy_item_ *cache_queue_policy_get_next_item(
struct cache_policy_ *, struct cache_policy_item_ *);
static struct cache_policy_item_ *cache_queue_policy_get_prev_item(
struct cache_policy_ *, struct cache_policy_item_ *);
static void cache_queue_policy_remove_item(struct cache_policy_ *,
struct cache_policy_item_ *);
static void destroy_cache_queue_policy(struct cache_queue_policy_ *);
static struct cache_queue_policy_ *init_cache_queue_policy(void);
/*
* All cache_queue_policy_XXX functions below will be used to fill
* the cache_queue_policy structure. They implement the most functionality of
* LRU and FIFO policies. LRU and FIFO policies are actually the
* cache_queue_policy_ with cache_update_item function changed.
*/
static struct cache_policy_item_ *
cache_queue_policy_create_item(void)
{
struct cache_queue_policy_item_ *retval;
TRACE_IN(cache_queue_policy_create_item);
retval = (struct cache_queue_policy_item_ *)calloc(1,
sizeof(struct cache_queue_policy_item_));
assert(retval != NULL);
TRACE_OUT(cache_queue_policy_create_item);
return ((struct cache_policy_item_ *)retval);
}
static void
cache_queue_policy_destroy_item(struct cache_policy_item_ *item)
{
TRACE_IN(cache_queue_policy_destroy_item);
assert(item != NULL);
free(item);
TRACE_OUT(cache_queue_policy_destroy_item);
}
static void
cache_queue_policy_add_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_queue_policy_ *queue_policy;
struct cache_queue_policy_item_ *queue_item;
TRACE_IN(cache_queue_policy_add_item);
queue_policy = (struct cache_queue_policy_ *)policy;
queue_item = (struct cache_queue_policy_item_ *)item;
TAILQ_INSERT_TAIL(&queue_policy->head, queue_item, entries);
TRACE_OUT(cache_queue_policy_add_item);
}
static void
cache_queue_policy_remove_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_queue_policy_ *queue_policy;
struct cache_queue_policy_item_ *queue_item;
TRACE_IN(cache_queue_policy_remove_item);
queue_policy = (struct cache_queue_policy_ *)policy;
queue_item = (struct cache_queue_policy_item_ *)item;
TAILQ_REMOVE(&queue_policy->head, queue_item, entries);
TRACE_OUT(cache_queue_policy_remove_item);
}
static struct cache_policy_item_ *
cache_queue_policy_get_first_item(struct cache_policy_ *policy)
{
struct cache_queue_policy_ *queue_policy;
TRACE_IN(cache_queue_policy_get_first_item);
queue_policy = (struct cache_queue_policy_ *)policy;
TRACE_OUT(cache_queue_policy_get_first_item);
return ((struct cache_policy_item_ *)TAILQ_FIRST(&queue_policy->head));
}
static struct cache_policy_item_ *
cache_queue_policy_get_last_item(struct cache_policy_ *policy)
{
struct cache_queue_policy_ *queue_policy;
TRACE_IN(cache_queue_policy_get_last_item);
queue_policy = (struct cache_queue_policy_ *)policy;
TRACE_OUT(cache_queue_policy_get_last_item);
return ((struct cache_policy_item_ *)TAILQ_LAST(&queue_policy->head,
cache_queue_policy_head_));
}
static struct cache_policy_item_ *
cache_queue_policy_get_next_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_queue_policy_ *queue_policy;
struct cache_queue_policy_item_ *queue_item;
TRACE_IN(cache_queue_policy_get_next_item);
queue_policy = (struct cache_queue_policy_ *)policy;
queue_item = (struct cache_queue_policy_item_ *)item;
TRACE_OUT(cache_queue_policy_get_next_item);
return ((struct cache_policy_item_ *)TAILQ_NEXT(queue_item, entries));
}
static struct cache_policy_item_ *
cache_queue_policy_get_prev_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_queue_policy_ *queue_policy;
struct cache_queue_policy_item_ *queue_item;
TRACE_IN(cache_queue_policy_get_prev_item);
queue_policy = (struct cache_queue_policy_ *)policy;
queue_item = (struct cache_queue_policy_item_ *)item;
TRACE_OUT(cache_queue_policy_get_prev_item);
return ((struct cache_policy_item_ *)TAILQ_PREV(queue_item,
cache_queue_policy_head_, entries));
}
/*
* Initializes cache_queue_policy_ by filling the structure with the functions
* pointers, defined above
*/
static struct cache_queue_policy_ *
init_cache_queue_policy(void)
{
struct cache_queue_policy_ *retval;
TRACE_IN(init_cache_queue_policy);
retval = (struct cache_queue_policy_ *)calloc(1,
sizeof(struct cache_queue_policy_));
assert(retval != NULL);
retval->parent_data.create_item_func = cache_queue_policy_create_item;
retval->parent_data.destroy_item_func = cache_queue_policy_destroy_item;
retval->parent_data.add_item_func = cache_queue_policy_add_item;
retval->parent_data.remove_item_func = cache_queue_policy_remove_item;
retval->parent_data.get_first_item_func =
cache_queue_policy_get_first_item;
retval->parent_data.get_last_item_func =
cache_queue_policy_get_last_item;
retval->parent_data.get_next_item_func =
cache_queue_policy_get_next_item;
retval->parent_data.get_prev_item_func =
cache_queue_policy_get_prev_item;
TAILQ_INIT(&retval->head);
TRACE_OUT(init_cache_queue_policy);
return (retval);
}
static void
destroy_cache_queue_policy(struct cache_queue_policy_ *queue_policy)
{
struct cache_queue_policy_item_ *queue_item;
TRACE_IN(destroy_cache_queue_policy);
while (!TAILQ_EMPTY(&queue_policy->head)) {
queue_item = TAILQ_FIRST(&queue_policy->head);
TAILQ_REMOVE(&queue_policy->head, queue_item, entries);
cache_queue_policy_destroy_item(
(struct cache_policy_item_ *)queue_item);
}
free(queue_policy);
TRACE_OUT(destroy_cache_queue_policy);
}
/*
* Makes cache_queue_policy_ behave like FIFO policy - we don't do anything,
* when the cache element is updated. So it always stays in its initial
* position in the queue - that is exactly the FIFO functionality.
*/
static void
cache_fifo_policy_update_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
TRACE_IN(cache_fifo_policy_update_item);
/* policy and item arguments are ignored */
TRACE_OUT(cache_fifo_policy_update_item);
}
struct cache_policy_ *
init_cache_fifo_policy(void)
{
struct cache_queue_policy_ *retval;
TRACE_IN(init_cache_fifo_policy);
retval = init_cache_queue_policy();
retval->parent_data.update_item_func = cache_fifo_policy_update_item;
TRACE_OUT(init_cache_fifo_policy);
return ((struct cache_policy_ *)retval);
}
void
destroy_cache_fifo_policy(struct cache_policy_ *policy)
{
struct cache_queue_policy_ *queue_policy;
TRACE_IN(destroy_cache_fifo_policy);
queue_policy = (struct cache_queue_policy_ *)policy;
destroy_cache_queue_policy(queue_policy);
TRACE_OUT(destroy_cache_fifo_policy);
}
/*
* Makes cache_queue_policy_ behave like LRU policy. On each update, cache
* element is moved to the end of the queue - so it would be deleted in last
* turn. That is exactly the LRU policy functionality.
*/
static void
cache_lru_policy_update_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_queue_policy_ *queue_policy;
struct cache_queue_policy_item_ *queue_item;
TRACE_IN(cache_lru_policy_update_item);
queue_policy = (struct cache_queue_policy_ *)policy;
queue_item = (struct cache_queue_policy_item_ *)item;
TAILQ_REMOVE(&queue_policy->head, queue_item, entries);
TAILQ_INSERT_TAIL(&queue_policy->head, queue_item, entries);
TRACE_OUT(cache_lru_policy_update_item);
}
struct cache_policy_ *
init_cache_lru_policy(void)
{
struct cache_queue_policy_ *retval;
TRACE_IN(init_cache_lru_policy);
retval = init_cache_queue_policy();
retval->parent_data.update_item_func = cache_lru_policy_update_item;
TRACE_OUT(init_cache_lru_policy);
return ((struct cache_policy_ *)retval);
}
void
destroy_cache_lru_policy(struct cache_policy_ *policy)
{
struct cache_queue_policy_ *queue_policy;
TRACE_IN(destroy_cache_lru_policy);
queue_policy = (struct cache_queue_policy_ *)policy;
destroy_cache_queue_policy(queue_policy);
TRACE_OUT(destroy_cache_lru_policy);
}
/*
* LFU (least frequently used) policy implementation differs much from the
* LRU and FIFO (both based on cache_queue_policy_). Almost all cache_policy_
* functions are implemented specifically for this policy. The idea of this
* policy is to represent frequency (real number) as the integer number and
* use it as the index in the array. Each array's element is
* the list of elements. For example, if we have the 100-elements
* array for this policy, the elements with frequency 0.1 (calls per-second)
* would be in 10th element of the array.
*/
static struct cache_policy_item_ *
cache_lfu_policy_create_item(void)
{
struct cache_lfu_policy_item_ *retval;
TRACE_IN(cache_lfu_policy_create_item);
retval = (struct cache_lfu_policy_item_ *)calloc(1,
sizeof(struct cache_lfu_policy_item_));
assert(retval != NULL);
TRACE_OUT(cache_lfu_policy_create_item);
return ((struct cache_policy_item_ *)retval);
}
static void
cache_lfu_policy_destroy_item(struct cache_policy_item_ *item)
{
TRACE_IN(cache_lfu_policy_destroy_item);
assert(item != NULL);
free(item);
TRACE_OUT(cache_lfu_policy_destroy_item);
}
/*
* When placed in the LFU policy queue for the first time, the maximum
* frequency is assigned to the element
*/
static void
cache_lfu_policy_add_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_lfu_policy_ *lfu_policy;
struct cache_lfu_policy_item_ *lfu_item;
TRACE_IN(cache_lfu_policy_add_item);
lfu_policy = (struct cache_lfu_policy_ *)policy;
lfu_item = (struct cache_lfu_policy_item_ *)item;
lfu_item->frequency = CACHELIB_MAX_FREQUENCY - 1;
TAILQ_INSERT_HEAD(&(lfu_policy->groups[CACHELIB_MAX_FREQUENCY - 1]),
lfu_item, entries);
TRACE_OUT(cache_lfu_policy_add_item);
}
/*
* On each update the frequency of the element is recalculated and, if it
* changed, the element would be moved to the another place in the array.
*/
static void
cache_lfu_policy_update_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_lfu_policy_ *lfu_policy;
struct cache_lfu_policy_item_ *lfu_item;
int index;
TRACE_IN(cache_lfu_policy_update_item);
lfu_policy = (struct cache_lfu_policy_ *)policy;
lfu_item = (struct cache_lfu_policy_item_ *)item;
/*
* We calculate the square of the request_count to avoid grouping of
* all elements at the start of the array (for example, if array size is
* 100 and most of its elements has frequency below the 0.01, they
* all would be grouped in the first array's position). Other
* techniques should be used here later to ensure, that elements are
* equally distributed in the array and not grouped in its beginning.
*/
if (lfu_item->parent_data.last_request_time.tv_sec !=
lfu_item->parent_data.creation_time.tv_sec) {
index = ((double)lfu_item->parent_data.request_count *
(double)lfu_item->parent_data.request_count /
(lfu_item->parent_data.last_request_time.tv_sec -
lfu_item->parent_data.creation_time.tv_sec + 1)) *
CACHELIB_MAX_FREQUENCY;
if (index >= CACHELIB_MAX_FREQUENCY)
index = CACHELIB_MAX_FREQUENCY - 1;
} else
index = CACHELIB_MAX_FREQUENCY - 1;
TAILQ_REMOVE(&(lfu_policy->groups[lfu_item->frequency]), lfu_item,
entries);
lfu_item->frequency = index;
TAILQ_INSERT_HEAD(&(lfu_policy->groups[index]), lfu_item, entries);
TRACE_OUT(cache_lfu_policy_update_item);
}
static void
cache_lfu_policy_remove_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_lfu_policy_ *lfu_policy;
struct cache_lfu_policy_item_ *lfu_item;
TRACE_IN(cache_lfu_policy_remove_item);
lfu_policy = (struct cache_lfu_policy_ *)policy;
lfu_item = (struct cache_lfu_policy_item_ *)item;
TAILQ_REMOVE(&(lfu_policy->groups[lfu_item->frequency]), lfu_item,
entries);
TRACE_OUT(cache_lfu_policy_remove_item);
}
static struct cache_policy_item_ *
cache_lfu_policy_get_first_item(struct cache_policy_ *policy)
{
struct cache_lfu_policy_ *lfu_policy;
struct cache_lfu_policy_item_ *lfu_item;
int i;
TRACE_IN(cache_lfu_policy_get_first_item);
lfu_item = NULL;
lfu_policy = (struct cache_lfu_policy_ *)policy;
for (i = 0; i < CACHELIB_MAX_FREQUENCY; ++i)
if (!TAILQ_EMPTY(&(lfu_policy->groups[i]))) {
lfu_item = TAILQ_FIRST(&(lfu_policy->groups[i]));
break;
}
TRACE_OUT(cache_lfu_policy_get_first_item);
return ((struct cache_policy_item_ *)lfu_item);
}
static struct cache_policy_item_ *
cache_lfu_policy_get_last_item(struct cache_policy_ *policy)
{
struct cache_lfu_policy_ *lfu_policy;
struct cache_lfu_policy_item_ *lfu_item;
int i;
TRACE_IN(cache_lfu_policy_get_last_item);
lfu_item = NULL;
lfu_policy = (struct cache_lfu_policy_ *)policy;
for (i = CACHELIB_MAX_FREQUENCY - 1; i >= 0; --i)
if (!TAILQ_EMPTY(&(lfu_policy->groups[i]))) {
lfu_item = TAILQ_LAST(&(lfu_policy->groups[i]),
cache_lfu_policy_group_);
break;
}
TRACE_OUT(cache_lfu_policy_get_last_item);
return ((struct cache_policy_item_ *)lfu_item);
}
static struct cache_policy_item_ *
cache_lfu_policy_get_next_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_lfu_policy_ *lfu_policy;
struct cache_lfu_policy_item_ *lfu_item;
int i;
TRACE_IN(cache_lfu_policy_get_next_item);
lfu_policy = (struct cache_lfu_policy_ *)policy;
lfu_item = TAILQ_NEXT((struct cache_lfu_policy_item_ *)item, entries);
if (lfu_item == NULL)
{
for (i = ((struct cache_lfu_policy_item_ *)item)->frequency + 1;
i < CACHELIB_MAX_FREQUENCY; ++i) {
if (!TAILQ_EMPTY(&(lfu_policy->groups[i]))) {
lfu_item = TAILQ_FIRST(&(lfu_policy->groups[i]));
break;
}
}
}
TRACE_OUT(cache_lfu_policy_get_next_item);
return ((struct cache_policy_item_ *)lfu_item);
}
static struct cache_policy_item_ *
cache_lfu_policy_get_prev_item(struct cache_policy_ *policy,
struct cache_policy_item_ *item)
{
struct cache_lfu_policy_ *lfu_policy;
struct cache_lfu_policy_item_ *lfu_item;
int i;
TRACE_IN(cache_lfu_policy_get_prev_item);
lfu_policy = (struct cache_lfu_policy_ *)policy;
lfu_item = TAILQ_PREV((struct cache_lfu_policy_item_ *)item,
cache_lfu_policy_group_, entries);
if (lfu_item == NULL)
{
for (i = ((struct cache_lfu_policy_item_ *)item)->frequency - 1;
i >= 0; --i)
if (!TAILQ_EMPTY(&(lfu_policy->groups[i]))) {
lfu_item = TAILQ_LAST(&(lfu_policy->groups[i]),
cache_lfu_policy_group_);
break;
}
}
TRACE_OUT(cache_lfu_policy_get_prev_item);
return ((struct cache_policy_item_ *)lfu_item);
}
/*
* Initializes the cache_policy_ structure by filling it with appropriate
* functions pointers
*/
struct cache_policy_ *
init_cache_lfu_policy(void)
{
int i;
struct cache_lfu_policy_ *retval;
TRACE_IN(init_cache_lfu_policy);
retval = (struct cache_lfu_policy_ *)calloc(1,
sizeof(struct cache_lfu_policy_));
assert(retval != NULL);
retval->parent_data.create_item_func = cache_lfu_policy_create_item;
retval->parent_data.destroy_item_func = cache_lfu_policy_destroy_item;
retval->parent_data.add_item_func = cache_lfu_policy_add_item;
retval->parent_data.update_item_func = cache_lfu_policy_update_item;
retval->parent_data.remove_item_func = cache_lfu_policy_remove_item;
retval->parent_data.get_first_item_func =
cache_lfu_policy_get_first_item;
retval->parent_data.get_last_item_func =
cache_lfu_policy_get_last_item;
retval->parent_data.get_next_item_func =
cache_lfu_policy_get_next_item;
retval->parent_data.get_prev_item_func =
cache_lfu_policy_get_prev_item;
for (i = 0; i < CACHELIB_MAX_FREQUENCY; ++i)
TAILQ_INIT(&(retval->groups[i]));
TRACE_OUT(init_cache_lfu_policy);
return ((struct cache_policy_ *)retval);
}
void
destroy_cache_lfu_policy(struct cache_policy_ *policy)
{
int i;
struct cache_lfu_policy_ *lfu_policy;
struct cache_lfu_policy_item_ *lfu_item;
TRACE_IN(destroy_cache_lfu_policy);
lfu_policy = (struct cache_lfu_policy_ *)policy;
for (i = 0; i < CACHELIB_MAX_FREQUENCY; ++i) {
while (!TAILQ_EMPTY(&(lfu_policy->groups[i]))) {
lfu_item = TAILQ_FIRST(&(lfu_policy->groups[i]));
TAILQ_REMOVE(&(lfu_policy->groups[i]), lfu_item,
entries);
cache_lfu_policy_destroy_item(
(struct cache_policy_item_ *)lfu_item);
}
}
free(policy);
TRACE_OUT(destroy_cache_lfu_policy);
}
|