Skip to content

Make eviction strategy in dir cache link-aware - #3641

Merged
peterebden merged 5 commits into
masterfrom
dir-cache-link-aware-eviction
Oct 31, 2026
Merged

peterebden merged 5 commits into
masterfrom
dir-cache-link-aware-eviction

Conversation

@peterebden

Copy link
Copy Markdown
Collaborator

First part of #3629

Accounts for links in cache files so when cleaning we don't free things from the cache that are actively used elsewhere. We bump mtime on retrieve and use that to evict instead of atime (which is not usually updated frequently, most things mount with relatime).

@peterebden
peterebden added this pull request to stack #3643 October 24, 2026 09:24
@peterebden peterebden linked an issue Oct 26, 2026 that may be closed by this pull request
Comment thread src/cache/dir_cache.go
log.Warning("Failed to store cache file %s: %s", cachedFile, err)
}
// TODO(peterebden): This is a little inefficient, it would be better to track the size in
// RecursiveCopy rather than walking again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we are still keeping this comment because unsharedSize is still inefficient?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little out of date (since we do RecursiveLink rather than RecursiveCopy for some time now) but not fully inaccurate.
I'm just going to remove it though, I don't think anything is going to change here.

Comment thread src/cache/dir_cache.go Resolved
Comment thread src/cache/dir_cache.go Resolved
Comment thread src/cache/dir_cache.go
}
id, links := fileInfo(info)
if _, present := files[id]; !present {
files[id] = &cacheFile{Size: uint64(info.Size()), Links: links}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel a slight unease with a function called readEntry writing to one of its input, but maybe this is just a functional programming pet peeves of mine.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's just not very easy to figure out a better way of handling it. Because things can error partway an iterator doesn't work super well either.

Comment thread src/cache/dir_cache.go Resolved
Comment thread src/cache/dir_cache.go
continue
}
totalSize -= entry.Size
// A file is only freed once the last entry referring to it is removed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference counting requires a global lock. Does this mean we can't merge this until #3644 is merged?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope that's about concurrency across processes. The reference counts here are all in memory, we've collected them all into this map.

@peterebden
peterebden force-pushed the dir-cache-link-aware-eviction branch from 3dcae26 to a0c07da Compare October 27, 2026 16:33
@peterebden
peterebden force-pushed the dir-cache-link-aware-eviction branch from a0c07da to b316ddd Compare October 31, 2026 10:21
@peterebden
peterebden merged commit b44e262 into master Oct 31, 2026
3 of 8 checks passed
@peterebden
peterebden deleted the dir-cache-link-aware-eviction branch October 31, 2026 10:21
peterebden added a commit that referenced this pull request Oct 31, 2026
Second part of #3629 , stacked on #3641 

Implements the size cap as a percentage of disk size, and a warning if
we cannot free enough from the cache to save required space (because
most entries are linked elsewhere)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve performance with multiple plz-outs

2 participants