kill over_size attribute since we don't use it in python anymore.

This commit is contained in:
Jason Madden 2016-09-19 20:03:12 -05:00
parent 33d57eaf9b
commit 0a5b4394ed
No known key found for this signature in database
GPG Key ID: 349F84431A08B99E
4 changed files with 16 additions and 31 deletions

View File

@ -29,7 +29,6 @@ ffi_from_handle = ffi.from_handle
from .ring import _FFI_RING
_lru_update_mru = _FFI_RING.lru_update_mru
_ring_move_to_head_from_foreign = _FFI_RING.ring_move_to_head_from_foreign
_lru_probation_on_hit = _FFI_RING.lru_probation_on_hit
_eden_add = _FFI_RING.eden_add
_lru_on_hit = _FFI_RING.lru_on_hit
@ -101,7 +100,6 @@ class SizedLRU(object):
self.get_LRU = self._ring.lru
self.make_MRU = self._ring.move_to_head
self.remove = self.delete
self.over_size = False
def __iter__(self):
return iter(self._ring)
@ -120,22 +118,21 @@ class SizedLRU(object):
def add_MRU(self, key, value):
entry = SizedLRURingEntry(key, value)
self.over_size = self._ring.add(entry)
self._ring.add(entry)
return entry
def update_MRU(self, entry, value):
#assert entry.__parent__ is self
old_size = entry.len
entry.set_value(value)
new_size = entry.len
self.over_size = _lru_update_mru(self._ring.ring_home, entry.cffi_ring_node, old_size, new_size)
# XXX: Need to rebalance, if needed.
_lru_update_mru(self._ring.ring_home, entry.cffi_ring_node, old_size, new_size)
def on_hit(self, entry):
return _lru_on_hit(self._ring_home, entry.cffi_ring_node)
def delete(self, entry):
self._ring.delete(entry)
self.over_size = self.size > self.limit
def stats(self):
return {
@ -169,7 +166,7 @@ class EdenLRU(SizedLRU):
self._protected_lru_ring_home,
self._probation_lru_ring_home,
new_entry.cffi_ring_node)
# XXX The various over_size attributes? Are they updated? Do they need to be?
if not rejected_items.r_next:
# Nothing rejected.
return new_entry

View File

@ -51,7 +51,7 @@ static int ring_is_empty(CPersistentRing* ring)
return ring == NULL || ring->r_next == ring || ring->r_next == NULL;
}
int
void
ring_add(CPersistentRing *ring, CPersistentRing *elt)
{
elt->r_next = ring;
@ -63,7 +63,6 @@ ring_add(CPersistentRing *ring, CPersistentRing *elt)
ring->frequency += elt->len;
ring->len++;
return ring_oversize(ring);
}
void
@ -95,7 +94,7 @@ ring_move_to_head(CPersistentRing *ring, CPersistentRing *elt)
ring->r_prev = elt;
}
int
static int
ring_move_to_head_from_foreign(CPersistentRing* current_ring,
CPersistentRing* new_ring,
CPersistentRing* elt)
@ -120,14 +119,14 @@ void lru_on_hit(CPersistentRing* ring, CPersistentRing* entry)
ring_move_to_head(ring, entry);
}
int lru_probation_on_hit(CPersistentRing* probation_ring,
void lru_probation_on_hit(CPersistentRing* probation_ring,
CPersistentRing* protected_ring,
CPersistentRing* entry)
{
entry->frequency++;
int protected_oversize = ring_move_to_head_from_foreign(probation_ring, protected_ring, entry);
if( !protected_oversize ) {
return 0;
return;
}
// Protected got too big. Demote entries back to probation until
@ -141,10 +140,10 @@ int lru_probation_on_hit(CPersistentRing* probation_ring,
ring_move_to_head_from_foreign(protected_ring, probation_ring, protected_lru);
}
return ring_oversize(protected_ring);
}
int lru_update_mru(CPersistentRing* ring,
void lru_update_mru(CPersistentRing* ring,
CPersistentRing* entry,
rs_counter_t old_entry_size,
rs_counter_t new_entry_size)
@ -153,7 +152,7 @@ int lru_update_mru(CPersistentRing* ring,
ring->frequency -= old_entry_size;
ring->frequency += new_entry_size;
ring_move_to_head(ring, entry);
return ring->frequency > ring->max_len;
// XXX TODO: Rebalance all the rings!
}
static int lru_will_fit(CPersistentRing* ring, CPersistentRing* entry)
@ -169,8 +168,8 @@ CPersistentRing eden_add(CPersistentRing* eden_ring,
CPersistentRing rejects = {};
rejects.r_next = rejects.r_prev = NULL;
int eden_oversize = ring_add(eden_ring, entry);
if(!eden_oversize) {
ring_add(eden_ring, entry);
if(!ring_oversize(eden_ring)) {
return rejects;
}

View File

@ -53,7 +53,7 @@ typedef struct CPersistentRing_struct {
/* Add elt as the most recently used object. elt must not already be
* in the list, although this isn't checked.
*/
int ring_add(CPersistentRing *ring, CPersistentRing *elt);
void ring_add(CPersistentRing *ring, CPersistentRing *elt);
/* Remove elt from the list. elt must already be in the list, although
* this isn't checked.
@ -74,18 +74,12 @@ void ring_del(CPersistentRing* ring, CPersistentRing *elt);
void ring_move_to_head(CPersistentRing *ring, CPersistentRing *elt);
int ring_move_to_head_from_foreign(CPersistentRing* current_ring,
CPersistentRing* new_ring,
CPersistentRing* elt);
int lru_probation_on_hit(CPersistentRing* probation_ring,
void lru_probation_on_hit(CPersistentRing* probation_ring,
CPersistentRing* protected_ring,
CPersistentRing* entry);
int lru_update_mru(CPersistentRing* ring,
void lru_update_mru(CPersistentRing* ring,
CPersistentRing* entry,
rs_counter_t old_entry_size,
rs_counter_t new_entry_size);

View File

@ -158,7 +158,6 @@ else:
""", include_dirs=[this_dir])
_ring_move_to_head = _FFI_RING.ring_move_to_head
_ring_move_to_head_from_foreign = _FFI_RING.ring_move_to_head_from_foreign
_ring_del = _FFI_RING.ring_del
_ring_add = _FFI_RING.ring_add
ffi_new = ffi.new
@ -230,10 +229,6 @@ else:
def lru(self):
return ffi_from_handle(self.ring_home.r_next.user_data)
def move_entry_from_other_ring(self, entry, other_ring):
return _ring_move_to_head_from_foreign(other_ring.ring_home,
self.ring_home,
entry.cffi_ring_node)