From ef4734ebb671d9ef19c284a4c5cc9412d6e62874 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 21 Jul 2021 21:55:04 +0200 Subject: [PATCH] fix(arc): actually invalidate --- src/Utils/ARC.hs | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Utils/ARC.hs b/src/Utils/ARC.hs index 62726eb62..a5e2a8c76 100644 --- a/src/Utils/ARC.hs +++ b/src/Utils/ARC.hs @@ -146,23 +146,35 @@ arcAlterF !(force -> unhashedK@(hashed -> k)) f oldARC@ARC{..} now | later <= initialARCTick = uncurry (arcAlterF unhashedK f) $ initARC arcMaximumGhost arcMaximumWeight | otherwise = (, later) <$> if | Just (_p, x@(_, w), arcFrequent') <- HashPSQ.deleteView k arcFrequent - -> f (Just x) <&> \(fromMaybe x -> !(force -> x'@(_, w'))) - -> let (arcFrequent'', arcFrequentWeight'', arcGhostFrequent') = evictToSize (arcMaximumWeight |- arcTargetRecent |- w') arcFrequent' (arcFrequentWeight - w) arcGhostFrequent - in oldARC - { arcFrequent = HashPSQ.insert k now x' arcFrequent'' - , arcFrequentWeight = arcFrequentWeight'' + w' - , arcGhostFrequent = arcGhostFrequent' - } + -> f (Just x) <&> \case + Nothing -> oldARC + { arcFrequent = arcFrequent' + , arcGhostFrequent = HashPSQ.insert k now () arcGhostFrequent + , arcFrequentWeight = arcFrequentWeight - w + } + Just !(force -> x'@(_, w')) + -> let (arcFrequent'', arcFrequentWeight'', arcGhostFrequent') = evictToSize (arcMaximumWeight |- arcTargetRecent |- w') arcFrequent' (arcFrequentWeight - w) arcGhostFrequent + in oldARC + { arcFrequent = HashPSQ.insert k now x' arcFrequent'' + , arcFrequentWeight = arcFrequentWeight'' + w' + , arcGhostFrequent = arcGhostFrequent' + } | Just (_p, x@(_, w), arcRecent') <- HashPSQ.deleteView k arcRecent - -> f (Just x) <&> \(fromMaybe x -> !(force -> x'@(_, w'))) - -> let (arcFrequent', arcFrequentWeight', arcGhostFrequent') = evictToSize (arcMaximumWeight |- arcTargetRecent |- w') arcFrequent arcFrequentWeight arcGhostFrequent - in oldARC - { arcRecent = arcRecent' - , arcRecentWeight = arcRecentWeight - w - , arcFrequent = HashPSQ.insert k now x' arcFrequent' - , arcFrequentWeight = arcFrequentWeight' + w' - , arcGhostFrequent = arcGhostFrequent' - } + -> f (Just x) <&> \case + Nothing -> oldARC + { arcRecent = arcRecent' + , arcGhostRecent = HashPSQ.insert k now () $ evictGhostToCount arcGhostRecent + , arcRecentWeight = arcRecentWeight - w + } + Just !(force -> x'@(_, w')) + -> let (arcFrequent', arcFrequentWeight', arcGhostFrequent') = evictToSize (arcMaximumWeight |- arcTargetRecent |- w') arcFrequent arcFrequentWeight arcGhostFrequent + in oldARC + { arcRecent = arcRecent' + , arcRecentWeight = arcRecentWeight - w + , arcFrequent = HashPSQ.insert k now x' arcFrequent' + , arcFrequentWeight = arcFrequentWeight' + w' + , arcGhostFrequent = arcGhostFrequent' + } | Just (_p, (), arcGhostRecent') <- HashPSQ.deleteView k arcGhostRecent -> f Nothing <&> \case Nothing -> oldARC