public LIRS(Segment<K, V> s, int capacity, int maxBatchSize, float batchThresholdFactor) { this.segment = s; this.maximumSize = capacity; this.maximumHotSize = calculateLIRSize( capacity ); this.maxBatchQueueSize = maxBatchSize > MAX_BATCH_SIZE ? MAX_BATCH_SIZE : maxBatchSize; this.batchThresholdFactor = batchThresholdFactor; this.accessQueue = new ConcurrentLinkedQueue<LIRSHashEntry<K, V>>(); }
@Override public Set<HashEntry<K, V>> execute() { Set<HashEntry<K, V>> evicted = new HashSet<HashEntry<K, V>>(); try { for ( LIRSHashEntry<K, V> e : accessQueue ) { if ( e.isResident() ) { e.hit( evicted ); } } removeFromSegment( evicted ); } finally { accessQueue.clear(); } return evicted; }
/** * Prunes HIR blocks in the bottom of the stack until an HOT block sits in * the stack bottom. If pruned blocks were resident, then they * remain in the queue; otherwise they are no longer referenced, and are thus * removed from the backing map. */ private void pruneStack(Set<HashEntry<K, V>> evicted) { // See section 3.3: // "We define an operation called "stack pruning" on the LIRS // stack S, which removes the HIR blocks in the bottom of // the stack until an LIR block sits in the stack bottom. This // operation serves for two purposes: (1) We ensure the block in // the bottom of the stack always belongs to the LIR block set. // (2) After the LIR block in the bottom is removed, those HIR // blocks contiguously located above it will not have chances to // change their status from HIR to LIR, because their recencies // are larger than the new maximum recency of LIR blocks." LIRSHashEntry<K, V> bottom = stackBottom(); while ( bottom != null && bottom.state != Recency.LIR_RESIDENT ) { bottom.removeFromStack(); if ( bottom.state == Recency.HIR_NONRESIDENT ) { evicted.add( bottom ); } bottom = stackBottom(); } }
/** * Prunes HIR blocks in the bottom of the stack until an HOT block sits in * the stack bottom. If pruned blocks were resident, then they * remain in the queue; otherwise they are no longer referenced, and are thus * removed from the backing map. */ private void pruneStack(Set<HashEntry<K, V>> evicted) { // See section 3.3: // "We define an operation called "stack pruning" on the LIRS // stack S, which removes the HIR blocks in the bottom of // the stack until an LIR block sits in the stack bottom. This // operation serves for two purposes: (1) We ensure the block in // the bottom of the stack always belongs to the LIR block set. // (2) After the LIR block in the bottom is removed, those HIR // blocks contiguously located above it will not have chances to // change their status from HIR to LIR, because their recencies // are larger than the new maximum recency of LIR blocks." LIRSHashEntry<K, V> bottom = stackBottom(); while ( bottom != null && bottom.state != Recency.LIR_RESIDENT ) { bottom.removeFromStack(); if ( bottom.state == Recency.HIR_NONRESIDENT ) { evicted.add( bottom ); } bottom = stackBottom(); } }
@Override public Set<HashEntry<K, V>> execute() { Set<HashEntry<K, V>> evicted = new HashSet<HashEntry<K, V>>(); try { for ( LIRSHashEntry<K, V> e : accessQueue ) { if ( e.isResident() ) { e.hit( evicted ); } } removeFromSegment( evicted ); } finally { accessQueue.clear(); } return evicted; }
public LIRS(Segment<K, V> s, int capacity, int maxBatchSize, float batchThresholdFactor) { this.segment = s; this.maximumSize = capacity; this.maximumHotSize = calculateLIRSize( capacity ); this.maxBatchQueueSize = maxBatchSize > MAX_BATCH_SIZE ? MAX_BATCH_SIZE : maxBatchSize; this.batchThresholdFactor = batchThresholdFactor; this.accessQueue = new ConcurrentLinkedQueue<LIRSHashEntry<K, V>>(); }
@Override public <K, V> EvictionPolicy<K, V> make(Segment<K, V> s, int capacity, float lf) { return new LIRS<K, V>( s, capacity, capacity * 10, lf ); } };
@Override public Set<HashEntry<K, V>> onEntryMiss(HashEntry<K, V> en) { LIRSHashEntry<K, V> e = (LIRSHashEntry<K, V>) en; Set<HashEntry<K, V>> evicted = e.miss(); removeFromSegment( evicted ); return evicted; }
@Override public Set<HashEntry<K, V>> onEntryMiss(HashEntry<K, V> en) { LIRSHashEntry<K, V> e = (LIRSHashEntry<K, V>) en; Set<HashEntry<K, V>> evicted = e.miss(); removeFromSegment( evicted ); return evicted; }
@Override public <K, V> EvictionPolicy<K, V> make(Segment<K, V> s, int capacity, float lf) { return new LIRS<K, V>( s, capacity, capacity * 10, lf ); } };