--------------------- PatchSet 1295 Date: 2001/01/13 03:18:05 Author: hno Branch: compactsentry Tag: (none) Log: Optimiazation #2, bring the RemovalNode into StoreEntry. Members: src/structs.h:1.21.2.1->1.21.2.2 src/repl/lru/store_repl_lru.c:1.5->1.5.2.1 Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.21.2.1 retrieving revision 1.21.2.2 diff -u -r1.21.2.1 -r1.21.2.2 --- squid/src/structs.h 13 Jan 2001 01:32:06 -0000 1.21.2.1 +++ squid/src/structs.h 13 Jan 2001 03:18:05 -0000 1.21.2.2 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.21.2.1 2001/01/13 01:32:06 hno Exp $ + * $Id: structs.h,v 1.21.2.2 2001/01/13 03:18:05 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1364,8 +1364,10 @@ /* Removal policies */ -struct _RemovalPolicyNode { +union _RemovalPolicyNode { void *data; + dlink_node dlink; + /* heap_node heap; */ }; struct _RemovalPolicy { Index: squid/src/repl/lru/store_repl_lru.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/repl/lru/store_repl_lru.c,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- squid/src/repl/lru/store_repl_lru.c 12 Jan 2001 08:20:36 -0000 1.5 +++ squid/src/repl/lru/store_repl_lru.c 13 Jan 2001 03:18:06 -0000 1.5.2.1 @@ -68,25 +68,13 @@ default: break; \ } -typedef struct _LruNode LruNode; -struct _LruNode { - /* Note: the dlink_node MUST be the first member of the LruNode - * structure. This member is later pointer typecasted to LruNode *. - */ - dlink_node node; -}; - -static MemPool *lru_node_pool = NULL; static int nr_lru_policies = 0; static void lru_add(RemovalPolicy * policy, StoreEntry * entry, RemovalPolicyNode * node) { LruPolicyData *lru = policy->_data; - LruNode *lru_node; - assert(!node->data); - node->data = lru_node = memPoolAlloc(lru_node_pool); - dlinkAddTail(entry, &lru_node->node, &lru->list); + dlinkAddTail(entry, &node->dlink, &lru->list); lru->count += 1; if (!lru->type) lru->type = repl_guessType(entry, node); @@ -96,20 +84,15 @@ lru_remove(RemovalPolicy * policy, StoreEntry * entry, RemovalPolicyNode * node) { LruPolicyData *lru = policy->_data; - LruNode *lru_node = node->data; - if (!lru_node) - return; /* * It seems to be possible for an entry to exist in the hash * but not be in the LRU list, so check for that case rather * than suffer a NULL pointer access. */ - if (NULL == lru_node->node.data) + if (NULL == node->dlink.data) return; - assert(lru_node->node.data == entry); - node->data = NULL; - dlinkDelete(&lru_node->node, &lru->list); - memPoolFree(lru_node_pool, lru_node); + dlinkDelete(&node->dlink, &lru->list); + node->dlink.data = NULL; lru->count -= 1; } @@ -118,29 +101,27 @@ RemovalPolicyNode * node) { LruPolicyData *lru = policy->_data; - LruNode *lru_node = node->data; - if (!lru_node) - return; - dlinkDelete(&lru_node->node, &lru->list); - dlinkAddTail((void *) entry, &lru_node->node, &lru->list); + if (node->dlink.data) + dlinkDelete(&node->dlink, &lru->list); + dlinkAddTail((void *) entry, &node->dlink, &lru->list); } /** RemovalPolicyWalker **/ typedef struct _LruWalkData LruWalkData; struct _LruWalkData { - LruNode *current; + dlink_node *current; }; const StoreEntry * lru_walkNext(RemovalPolicyWalker * walker) { LruWalkData *lru_walk = walker->_data; - LruNode *lru_node = lru_walk->current; - if (!lru_node) + dlink_node *node = lru_walk->current; + if (!node) return NULL; - lru_walk->current = (LruNode *) lru_node->node.next; - return (StoreEntry *) lru_node->node.data; + lru_walk->current = node->next; + return (StoreEntry *) node->data; } static void @@ -168,7 +149,7 @@ walker->_data = lru_walk; walker->Next = lru_walkNext; walker->Done = lru_walkDone; - lru_walk->current = (LruNode *) lru->list.head; + lru_walk->current = lru->list.head; return walker; } @@ -176,8 +157,8 @@ typedef struct _LruPurgeData LruPurgeData; struct _LruPurgeData { - LruNode *current; - LruNode *start; + dlink_node *current; + dlink_node *start; }; static StoreEntry * @@ -186,29 +167,28 @@ LruPurgeData *lru_walker = walker->_data; RemovalPolicy *policy = walker->_policy; LruPolicyData *lru = policy->_data; - LruNode *lru_node; + dlink_node *node; StoreEntry *entry; try_again: - lru_node = lru_walker->current; - if (!lru_node || walker->scanned >= walker->max_scan) + node = lru_walker->current; + if (!node || walker->scanned >= walker->max_scan) return NULL; walker->scanned += 1; - lru_walker->current = (LruNode *) lru_node->node.next; + lru_walker->current = node->next; if (lru_walker->current == lru_walker->start) { /* Last node found */ lru_walker->current = NULL; } - entry = (StoreEntry *) lru_node->node.data; - dlinkDelete(&lru_node->node, &lru->list); + entry = (StoreEntry *) node->data; + dlinkDelete(node, &lru->list); + node->data = NULL; if (storeEntryLocked(entry)) { /* Shit, it is locked. we can't return this one */ walker->locked++; - dlinkAddTail(entry, &lru_node->node, &lru->list); + dlinkAddTail(entry, node, &lru->list); goto try_again; } - memPoolFree(lru_node_pool, lru_node); lru->count -= 1; - SET_POLICY_NODE(entry, NULL); return entry; } @@ -238,7 +218,7 @@ walker->max_scan = max_scan; walker->Next = lru_purgeNext; walker->Done = lru_purgeDone; - lru_walk->start = lru_walk->current = (LruNode *) lru->list.head; + lru_walk->start = lru_walk->current = lru->list.head; return walker; } @@ -263,9 +243,6 @@ LruPolicyData *lru_data; /* no arguments expected or understood */ assert(!args); - /* Initialize */ - if (!lru_node_pool) - lru_node_pool = memPoolCreate("LRU policy node", sizeof(LruNode)); /* Allocate the needed structures */ lru_data = xcalloc(1, sizeof(*lru_data)); policy = CBDATA_ALLOC(RemovalPolicy, NULL);