public void CacheReadReference(string cacheBlock) { int blockIndex = -1; this.totalCacheAccesses++; //Increment the total number of references we've seen in the cache so far this.refreshCounter++; //increment the refresh counter GhostCacheElement ghostBlock = null; if (this.reverseLookup.TryGetValue(cacheBlock, out ghostBlock)) //O(1) { //hit, it's in the cache blockIndex = this.stack.IndexOfKey(ghostBlock.refreshCounter); // O(log n) ghostBlock.refreshCounter = this.refreshCounter; //update counter in the block //update the counter at its current depth Debug.Assert(this.depthsAccesses[blockIndex] + 1 < UInt32.MaxValue); //make sure we don't overflow the counter this.depthsAccesses[blockIndex] += 1; //Move it to the right place in the stack (new counter value == "0th position") this.stack.RemoveAt(blockIndex); //O(log n) this.stack.Add(this.refreshCounter, ghostBlock); //O(log n) } else { this.Evict(); //check if we need to free up space (should rarely have to...) ghostBlock = new GhostCacheElement(refreshCounter, cacheBlock); this.stack.Add(refreshCounter, ghostBlock); this.reverseLookup.Add(cacheBlock, ghostBlock); this.coldMisses++; //this is only true (ie: a cold miss) until the ghost cache has to start evicting things } }
public void CacheReadReference(string cacheBlock) { this.refreshCounter++; //increment the refresh counter this.totalCacheReferences++; //Increment the total number of references we've seen in the cache so far Int32 blockIndex = -1; byte[] hashedByteValue = this.Murmur3HashFunction.ComputeHash(System.Text.Encoding.UTF8.GetBytes(cacheBlock)); UInt64 hashedValue = IntHelpers.GetUInt64(hashedByteValue, 8); if ((hashedValue & (this.modulusP - 1)) < this.thresholdT) { this.totalProcessedReferences++; GhostCacheElement ghostBlock = null; if (this.hashTableLookup.TryGetValue(hashedValue, out ghostBlock)) //O(1) { //hit, it's in the ghost cache blockIndex = this.distanceTree.IndexOfKey(ghostBlock.refreshCounter); // O(log n) Int32 scaledReuseDistance = (Int32)Math.Round((double)blockIndex / this.samplingRateR); ghostBlock.refreshCounter = this.refreshCounter; //update counter in the block //update the counter at its current depth Debug.Assert(this.reuseAccessHistogram[scaledReuseDistance] + 1 < UInt32.MaxValue); //make sure we don't overflow the counter this.reuseAccessHistogram[scaledReuseDistance] += 1; //Move it to the right place in the stack (new counter value == "0th position") this.distanceTree.RemoveAt(blockIndex); //O(log n) this.distanceTree.Add(this.refreshCounter, ghostBlock); //O(log n) } else { this.Evict(); //check if we need to free up space (should rarely have to...) ghostBlock = new GhostCacheElement(refreshCounter, hashedValue); this.distanceTree.Add(refreshCounter, ghostBlock); this.hashTableLookup.Add(hashedValue, ghostBlock); this.coldMisses++; //this is only true (ie: a cold miss) until the ghost cache has to start evicting things } } }
public void CacheReadReference(string cacheBlock) { this.refreshCounter++; //increment the refresh counter this.totalCacheReferences++; //Increment the total number of references we've seen in the cache so far Int32 blockIndex = -1; byte[] hashedByteValue = this.Murmur3HashFunction.ComputeHash(System.Text.Encoding.UTF8.GetBytes(cacheBlock)); UInt64 hashedValue = IntHelpers.GetUInt64(hashedByteValue, 8); if ((hashedValue & (this.modulusP - 1)) < this.thresholdT){ this.totalProcessedReferences++; GhostCacheElement ghostBlock = null; if (this.hashTableLookup.TryGetValue(hashedValue, out ghostBlock)) //O(1) { //hit, it's in the ghost cache blockIndex = this.distanceTree.IndexOfKey(ghostBlock.refreshCounter); // O(log n) Int32 scaledReuseDistance = (Int32)Math.Round((double)blockIndex / this.samplingRateR); ghostBlock.refreshCounter = this.refreshCounter; //update counter in the block //update the counter at its current depth Debug.Assert(this.reuseAccessHistogram[scaledReuseDistance] + 1 < UInt32.MaxValue); //make sure we don't overflow the counter this.reuseAccessHistogram[scaledReuseDistance] += 1; //Move it to the right place in the stack (new counter value == "0th position") this.distanceTree.RemoveAt(blockIndex); //O(log n) this.distanceTree.Add(this.refreshCounter, ghostBlock); //O(log n) } else { this.Evict(); //check if we need to free up space (should rarely have to...) ghostBlock = new GhostCacheElement(refreshCounter, hashedValue); this.distanceTree.Add(refreshCounter, ghostBlock); this.hashTableLookup.Add(hashedValue, ghostBlock); this.coldMisses++; //this is only true (ie: a cold miss) until the ghost cache has to start evicting things } } }