Skip to content

reusable_build: improve ccahe handling#94

Merged
hauke merged 3 commits intoopenwrt:mainfrom
hauke:ccache
Apr 12, 2026
Merged

reusable_build: improve ccahe handling#94
hauke merged 3 commits intoopenwrt:mainfrom
hauke:ccache

Conversation

@hauke
Copy link
Copy Markdown
Member

@hauke hauke commented Apr 11, 2026

  • reusable_build: show ccache statistics after build

    Add a step to print the ccache hit rate, miss rate, and cache size
    after each build. This makes it easy to verify that the cache is
    being populated and used correctly.

  • reusable_build: increase kernel ccache size limit to 800M

    The previous limit of 400M was too small to hold a complete kernel
    build. A cold build of kernel 6.12 for ipq40xx/generic fills the
    cache to 659M, which means ccache was evicting entries mid-build.
    Those evicted entries would then be cache misses on the next build,
    reducing the hit rate and defeating the purpose of the cache. Increase
    the limit to 800M to fit a full kernel build and maximize hits on
    subsequent builds.

    Measured cache usage after a cold kernel 6.12 build for ipq40xx/generic:

    buildbot@013d604d7d26:/openwrt$ du -sh .ccache/
    659M    .ccache/
    buildbot@013d604d7d26:/openwrt$ CCACHE_DIR=.ccache staging_dir/host/bin/ccache --show-stats
    Cacheable calls:    5842 / 5955 (98.10%)
      Hits:               43 / 5842 ( 0.74%)
        Direct:           43 /   43 (100.0%)
        Preprocessed:      0 /   43 ( 0.00%)
      Misses:           5799 / 5842 (99.26%)
    Uncacheable calls:   113 / 5955 ( 1.90%)
    Local storage:
      Cache size (GiB):  0.6 /  5.0 (12.82%)
      Hits:               43 / 5842 ( 0.74%)
      Misses:           5799 / 5842 (99.26%)
    
  • reusable_build: use fresh ccache when upload_ccache_cache is set

    When upload_ccache_cache is enabled, skip restoring the existing cache
    from S3 and GitHub Actions before building. This ensures the uploaded
    cache only contains entries from the current build, without
    accumulating stale entries from previous builds that may no longer be
    relevant (e.g. after a kernel version bump). A smaller, fresher cache
    is faster to download and more effective than a large cache polluted
    with obsolete entries.

@hauke hauke requested a review from Ansuel April 11, 2026 14:52
@hauke hauke changed the title cache fixes ccache fixes Apr 11, 2026

echo compiler_type=gcc >> $SYSTEM_CCACHE_CONF
[ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=400M >> $SYSTEM_CCACHE_CONF
[ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=800M >> $SYSTEM_CCACHE_CONF
Copy link
Copy Markdown
Member Author

@hauke hauke Apr 11, 2026

Choose a reason for hiding this comment

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

@Ansuel Do you have enough storage for this change?

@hauke hauke changed the title ccache fixes reusable_build: improve ccahe handling Apr 11, 2026
@hauke
Copy link
Copy Markdown
Member Author

hauke commented Apr 11, 2026

This is untested, how do I test this?

I was running the build in a local container in a similar way like the CI does it.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

hauke added 3 commits April 12, 2026 16:42
Add a step to print the ccache hit rate, miss rate, and cache size
after each build. This makes it easy to verify that the cache is
being populated and used correctly.

Link: openwrt#94
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
The previous limit of 400M was too small to hold a complete kernel
build. A cold build of kernel 6.12 for ipq40xx/generic fills the
cache to 659M, which means ccache was evicting entries mid-build.
Those evicted entries would then be cache misses on the next build,
reducing the hit rate and defeating the purpose of the cache. Increase
the limit to 800M to fit a full kernel build and maximize hits on
subsequent builds.

Measured cache usage after a cold kernel 6.12 build for ipq40xx/generic:

```
buildbot@013d604d7d26:/openwrt$ du -sh .ccache/
659M    .ccache/
buildbot@013d604d7d26:/openwrt$ CCACHE_DIR=.ccache staging_dir/host/bin/ccache --show-stats
Cacheable calls:    5842 / 5955 (98.10%)
  Hits:               43 / 5842 ( 0.74%)
    Direct:           43 /   43 (100.0%)
    Preprocessed:      0 /   43 ( 0.00%)
  Misses:           5799 / 5842 (99.26%)
Uncacheable calls:   113 / 5955 ( 1.90%)
Local storage:
  Cache size (GiB):  0.6 /  5.0 (12.82%)
  Hits:               43 / 5842 ( 0.74%)
  Misses:           5799 / 5842 (99.26%)
```

Link: openwrt#94
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
When upload_ccache_cache is enabled, skip restoring the existing cache
from S3 and GitHub Actions before building. This ensures the uploaded
cache only contains entries from the current build, without
accumulating stale entries from previous builds that may no longer be
relevant (e.g. after a kernel version bump). A smaller, fresher cache
is faster to download and more effective than a large cache polluted
with obsolete entries.

Skip it only for kernel builds, because this would reduce the speed of
all package builds too much.

Link: openwrt#94
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
@hauke hauke merged commit 90fd27a into openwrt:main Apr 12, 2026
1 check passed
@hauke hauke deleted the ccache branch April 12, 2026 15:09
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.

1 participant