Skip to content

lru: atomic refcount, unlock release path#111

Merged
nclack merged 11 commits into
mainfrom
issue-108-atomic-lru-refcount
May 20, 2026
Merged

lru: atomic refcount, unlock release path#111
nclack merged 11 commits into
mainfrom
issue-108-atomic-lru-refcount

Conversation

@nclack
Copy link
Copy Markdown
Owner

@nclack nclack commented May 19, 2026

What

Make the per-entry refcount atomic and drop the cache mutex from the release path. Acquire still takes the mutex — incrementing from zero has to be serialized against the eviction scan, which reads refcounts to decide what's safe to evict.

Why

The refcount is a per-entry counter. It was under the cache mutex only because the field lived inside the entry struct, not because the value needed that lock.

Results

Not a lot of measured performance change on my laptop. The change is still worth landing for cleaner refcount semantics and for the new contention test that exercises the release path under concurrency, but don't expect this workload to get faster.

Key file

src/util/lru.c — refcount, acquire/release, eviction reads.

Closes #108.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 67.96117% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.77%. Comparing base (da828e1) to head (cfafcf0).

Files with missing lines Patch % Lines
src/threadpool/threadpool.c 0.00% 13 Missing ⚠️
src/util/lru.c 55.55% 7 Missing and 5 partials ⚠️
src/zarr/zarr_meta_cache.c 82.60% 4 Missing ⚠️
src/util/pool.c 81.81% 2 Missing ⚠️
src/store/store_fs.c 93.33% 1 Missing ⚠️
src/zarr/zarr_shard_cache.c 92.85% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (67.96%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
+ Coverage   55.56%   55.77%   +0.21%     
==========================================
  Files          49       49              
  Lines        6875     6890      +15     
  Branches     1227     1232       +5     
==========================================
+ Hits         3820     3843      +23     
- Misses       2570     2572       +2     
+ Partials      485      475      -10     
Flag Coverage Δ
unittests 55.77% <67.96%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/store/store_fs.c 74.09% <93.33%> (+0.24%) ⬆️
src/zarr/zarr_shard_cache.c 64.67% <92.85%> (-1.01%) ⬇️
src/util/pool.c 91.02% <81.81%> (-2.31%) ⬇️
src/zarr/zarr_meta_cache.c 71.03% <82.60%> (-0.69%) ⬇️
src/util/lru.c 79.31% <55.55%> (-1.92%) ⬇️
src/threadpool/threadpool.c 0.00% <0.00%> (ø)

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nclack nclack force-pushed the issue-108-atomic-lru-refcount branch from badd06a to dafe8b8 Compare May 20, 2026 03:51
@nclack nclack merged commit 67de519 into main May 20, 2026
6 checks passed
@nclack nclack deleted the issue-108-atomic-lru-refcount branch May 20, 2026 17:14
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.

Lock-free LRU refcount; eliminate cache_mu hot path

1 participant