chore: capture post-P0/P1 state for clean P2 start (working tree was dirty at task begin)

This commit is contained in:
2026-05-27 00:53:49 -05:00
parent 9cb38a9a18
commit 0c1840d223
17 changed files with 1500 additions and 170 deletions
+95
View File
@@ -428,3 +428,98 @@ func (m *MemoryFS) EvictFIFO(bytesNeeded uint) uint {
return evicted
}
// EvictLFU evicts least frequently used files first (by AccessCount asc; P1-03 real LFU using existing field).
// Ties broken by ATime (older first).
func (m *MemoryFS) EvictLFU(bytesNeeded uint) uint {
m.mu.Lock()
defer m.mu.Unlock()
var evicted uint
var candidates []*types.FileInfo
// Collect all files
for _, fi := range m.info {
candidates = append(candidates, fi)
}
// Sort by access count asc (LFU), then older ATime for ties
sort.Slice(candidates, func(i, j int) bool {
if candidates[i].AccessCount != candidates[j].AccessCount {
return candidates[i].AccessCount < candidates[j].AccessCount
}
return candidates[i].ATime.Before(candidates[j].ATime)
})
// Evict until enough space
for _, fi := range candidates {
if m.size <= m.capacity-int64(bytesNeeded) {
break
}
key := fi.Key
// Remove from LRU
m.LRU.Remove(key)
// Remove from maps
delete(m.info, key)
delete(m.data, key)
// Update size
m.size -= fi.Size
evicted += uint(fi.Size)
// Clean up key lock
shardIndex := locks.GetShardIndex(key)
m.keyLocks[shardIndex].Delete(key)
}
return evicted
}
// EvictHybrid evicts using time-decayed score (recency + frequency from GetTimeDecayedScore; lower value first).
// This makes "hybrid" a meaningful size+recency+freq policy (P1-03).
func (m *MemoryFS) EvictHybrid(bytesNeeded uint) uint {
m.mu.Lock()
defer m.mu.Unlock()
var evicted uint
var candidates []*types.FileInfo
// Collect all files
for _, fi := range m.info {
candidates = append(candidates, fi)
}
// Sort by ascending decayed score (least valuable = evict first)
sort.Slice(candidates, func(i, j int) bool {
return candidates[i].GetTimeDecayedScore() < candidates[j].GetTimeDecayedScore()
})
// Evict until enough space
for _, fi := range candidates {
if m.size <= m.capacity-int64(bytesNeeded) {
break
}
key := fi.Key
// Remove from LRU
m.LRU.Remove(key)
// Remove from maps
delete(m.info, key)
delete(m.data, key)
// Update size
m.size -= fi.Size
evicted += uint(fi.Size)
// Clean up key lock
shardIndex := locks.GetShardIndex(key)
m.keyLocks[shardIndex].Delete(key)
}
return evicted
}