--------------------- PatchSet 1299 Date: 2001/01/13 03:55:44 Author: hno Branch: compactsentry Tag: (none) Log: Brought heap replacement into the StoreEntry unified world.. Members: include/heap.h:1.4.2.1->1.4.2.2 lib/heap.c:1.4.2.1->1.4.2.2 src/structs.h:1.21.2.2->1.21.2.3 src/repl/heap/store_repl_heap.c:1.5->1.5.2.1 Index: squid/include/heap.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/heap.h,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -u -r1.4.2.1 -r1.4.2.2 --- squid/include/heap.h 13 Jan 2001 03:19:04 -0000 1.4.2.1 +++ squid/include/heap.h 13 Jan 2001 03:55:44 -0000 1.4.2.2 @@ -1,5 +1,5 @@ /* - * $Id: heap.h,v 1.4.2.1 2001/01/13 03:19:04 hno Exp $ + * $Id: heap.h,v 1.4.2.2 2001/01/13 03:55:44 hno Exp $ * * AUTHOR: John Dilley, Hewlett Packard * @@ -136,6 +136,7 @@ * free as necessary. */ extern heap_t heap_extractmin(heap *); +extern heap_node *heap_extractmin_node(heap *); /* * Extract the last leaf node (does not change the heap property). Index: squid/lib/heap.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/heap.c,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -u -r1.4.2.1 -r1.4.2.2 --- squid/lib/heap.c 13 Jan 2001 03:19:04 -0000 1.4.2.1 +++ squid/lib/heap.c 13 Jan 2001 03:55:44 -0000 1.4.2.2 @@ -1,6 +1,6 @@ /* - * $Id: heap.c,v 1.4.2.1 2001/01/13 03:19:04 hno Exp $ + * $Id: heap.c,v 1.4.2.2 2001/01/13 03:55:44 hno Exp $ * * AUTHOR: John Dilley, Hewlett Packard * @@ -160,7 +160,7 @@ * in, which the caller must free if necessary. */ heap_t -heap_delete(heap * hp, heap_node * elm) +heap_remove(heap * hp, heap_node * elm) { heap_node *lastNode; heap_t data = elm->data; @@ -185,6 +185,14 @@ return data; } +heap_t +heap_delete(heap * hp, heap_node * elm) +{ + heap_t data = heap_remove(hp, elm); + elm->data = NULL; + return data; +} + /* * Delete the last element (leaf) out of the heap. Does not require a * heapify operation. @@ -224,6 +232,13 @@ return data; } +heap_node +heap_extractmin_node(heap *hp) +{ + heap_node *node; + +} + /* * Remove the last node in HP. Frees the heap internal structure and Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.21.2.2 retrieving revision 1.21.2.3 diff -u -r1.21.2.2 -r1.21.2.3 --- squid/src/structs.h 13 Jan 2001 03:18:05 -0000 1.21.2.2 +++ squid/src/structs.h 13 Jan 2001 03:55:44 -0000 1.21.2.3 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.21.2.2 2001/01/13 03:18:05 hno Exp $ + * $Id: structs.h,v 1.21.2.3 2001/01/13 03:55:44 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -33,6 +33,7 @@ #include "config.h" #include "splay.h" +#include "heap.h" struct _dlink_node { void *data; @@ -1367,7 +1368,7 @@ union _RemovalPolicyNode { void *data; dlink_node dlink; - /* heap_node heap; */ + heap_node heap; }; struct _RemovalPolicy { Index: squid/src/repl/heap/store_repl_heap.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/repl/heap/store_repl_heap.c,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- squid/src/repl/heap/store_repl_heap.c 12 Jan 2001 08:20:36 -0000 1.5 +++ squid/src/repl/heap/store_repl_heap.c 13 Jan 2001 03:55:44 -0000 1.5.2.1 @@ -48,42 +48,17 @@ heap_key_func *keyfunc; int count; int nwalkers; - enum heap_entry_type { - TYPE_UNKNOWN = 0, TYPE_STORE_ENTRY, TYPE_STORE_MEM - } type; }; -/* Hack to avoid having to remember the RemovalPolicyNode location. - * Needed by the purge walker. - */ -static enum heap_entry_type -heap_guessType(StoreEntry * entry, RemovalPolicyNode * node) -{ - if (node == &entry->repl) - return TYPE_STORE_ENTRY; - if (entry->mem_obj && node == &entry->mem_obj->repl) - return TYPE_STORE_MEM; - fatal("Heap Replacement: Unknown StoreEntry node type"); - return TYPE_UNKNOWN; -} -#define SET_POLICY_NODE(entry,value) \ - switch(heap->type) { \ - case TYPE_STORE_ENTRY: entry->repl.data = value; break ; \ - case TYPE_STORE_MEM: entry->mem_obj->repl.data = value ; break ; \ - default: break; \ - } - static void heap_add(RemovalPolicy * policy, StoreEntry * entry, RemovalPolicyNode * node) { HeapPolicyData *heap = policy->_data; - assert(!node->data); + assert(!node->heap.data); if (EBIT_TEST(entry->flags, ENTRY_SPECIAL)) return; /* We won't manage these.. they messes things up */ - node->data = heap_insert(heap->heap, entry); + heap_insert(heap->heap, &node->heap, entry); heap->count += 1; - if (!heap->type) - heap->type = heap_guessType(entry, node); /* Add a little more variance to the aging factor */ heap->heap->age += heap->heap->age / 100000000; } @@ -93,11 +68,11 @@ RemovalPolicyNode * node) { HeapPolicyData *heap = policy->_data; - heap_node *hnode = node->data; - if (!hnode) + heap_node *hnode = &node->heap; + if (!hnode->data) return; heap_delete(heap->heap, hnode); - node->data = NULL; + hnode->data = NULL; heap->count -= 1; } @@ -106,7 +81,7 @@ RemovalPolicyNode * node) { HeapPolicyData *heap = policy->_data; - heap_node *hnode = node->data; + heap_node *hnode = &node->heap; if (!hnode) return; heap_update(heap->heap, hnode, (StoreEntry *) entry); @@ -176,18 +151,19 @@ RemovalPolicy *policy = walker->_policy; HeapPolicyData *heap = policy->_data; StoreEntry *entry; + heap_node *node; heap_key age; try_again: if (!heap_nodes(heap->heap) > 0) return NULL; /* done */ age = heap_peepminkey(heap->heap); - entry = heap_extractmin(heap->heap); + node = heap_extractmin_node(heap->heap); + entry = node->data; if (storeEntryLocked(entry)) { - linklistPush(&heap_walker->locked_entries, entry); + linklistPush(&heap_walker->locked_entries, node); goto try_again; } heap_walker->min_age = age; - SET_POLICY_NODE(entry, NULL); return entry; } @@ -197,7 +173,7 @@ HeapPurgeData *heap_walker = walker->_data; RemovalPolicy *policy = walker->_policy; HeapPolicyData *heap = policy->_data; - StoreEntry *entry; + heap_node *node; assert(strcmp(policy->_type, "heap") == 0); assert(heap->nwalkers > 0); heap->nwalkers -= 1; @@ -209,9 +185,8 @@ /* * Reinsert the locked entries */ - while ((entry = linklistShift(&heap_walker->locked_entries))) { - heap_node *node = heap_insert(heap->heap, entry); - SET_POLICY_NODE(entry, node); + while ((node = linklistShift(&heap_walker->locked_entries))) { + heap_insert(heap->heap, node->data, node); } safe_free(walker->_data); cbdataFree(walker);