Skip to content

Commit

Permalink
fix: fix lru high priority weight calculation (#797)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <[email protected]>
  • Loading branch information
MrCroxx committed Nov 26, 2024
1 parent 430045c commit 9900541
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions foyer-memory/src/eviction/lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ where
strict_assert!(state.link.is_linked());

match (state.is_pinned, state.in_high_priority_pool) {
(true, _) => unsafe { self.pin_list.remove_from_ptr(Arc::as_ptr(record)) },
(true, false) => unsafe { self.pin_list.remove_from_ptr(Arc::as_ptr(record)) },
(true, true) => unsafe {
self.high_priority_weight -= record.weight();
state.in_high_priority_pool = false;
self.pin_list.remove_from_ptr(Arc::as_ptr(record))
},
(false, true) => {
self.high_priority_weight -= record.weight();
state.in_high_priority_pool = false;
Expand Down Expand Up @@ -487,12 +492,25 @@ pub mod tests {
lru.acquire_mutable(&rs[11]);
assert_ptr_vec_vec_eq(lru.dump(), vec![vec![r(10)], vec![r(1)], vec![r(0), r(11)]]);

// remove pinned
// remove pinned (low priority)
// pin: [0]
// 10, [1]
lru.remove(&rs[11]);
assert_ptr_vec_vec_eq(lru.dump(), vec![vec![r(10)], vec![r(1)], vec![r(0)]]);

// remove pinned (high priority)
// step 1:
// pin: [0], [2]
// 10, [1]
lru.push(r(2));
lru.acquire_mutable(&rs[2]);
assert_ptr_vec_vec_eq(lru.dump(), vec![vec![r(10)], vec![r(1)], vec![r(0), r(2)]]);
// step 2:
// pin: [0]
// 10, [1]
lru.remove(&rs[2]);
assert_ptr_vec_vec_eq(lru.dump(), vec![vec![r(10)], vec![r(1)], vec![r(0)]]);

// release removed
// pin: [0]
// 10, [1]
Expand Down

0 comments on commit 9900541

Please sign in to comment.