Skip to content

Fix ccahe handling#103

Open
hauke wants to merge 6 commits intoopenwrt:mainfrom
hauke:ccache-fix-keys
Open

Fix ccahe handling#103
hauke wants to merge 6 commits intoopenwrt:mainfrom
hauke:ccache-fix-keys

Conversation

@hauke
Copy link
Copy Markdown
Member

@hauke hauke commented Apr 18, 2026

This contains multiple fixes and improvements for the ccache handling in the Github actions. This is very hard to test in all the situations. I hope this fixes the ccache handling in the github actions now.

For small changes it should reduce the build time of a Linux kernel from 25 minutes to 2:30 minutes.

Here is an example run on main: https://github.com/hauke/openwrt/actions/runs/24610733561/job/71964583220
and here on a PR: https://github.com/hauke/openwrt/actions/runs/24612062608/job/71968121620

This also needs this OpenWrt change: openwrt/openwrt#22995

hauke and others added 6 commits April 18, 2026 20:03
Rename the system ccache.conf path var from SYSTEM_CCACHE_CONF to
CCACHE_CONFIGPATH2, the env var ccache itself reads for a secondary
config, and make it absolute (rooted at github.workspace/openwrt/)
so it matches the checkout layout rather than depending on
working-directory: openwrt.

Write both CCACHE_DIR and CCACHE_CONFIGPATH2 to $GITHUB_ENV from
the configure step so every subsequent step inherits the same
values. Previously each step had to redeclare CCACHE_DIR in its
own env block and the "Show ccache stats" step was running without
CCACHE_CONFIGPATH2 at all, so it never saw the system ccache.conf
written during configuration.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
File ctime and mtime change when the ccache archive is tar'd and
extracted for upload/restore, causing spurious hash mismatches. Tell
ccache to ignore them.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
The external toolchain is rebuilt daily by the build bots, but the
compiler itself usually does not change. Without an explicit
compiler_check, ccache falls back to the compiler binary's mtime, so
each daily rebuild produces a "new" compiler and every lookup misses.

Derive a stable compiler_check string from the OpenWrt commit that
last touched toolchain/gcc or toolchain/binutils. For external
toolchains, read the build commit from "gcc --version" (r0-<SHA>
pkgversion) and resolve the last change relative to it; otherwise
fall back to HEAD. Full git history is needed for "git log", so
switch checkout to fetch-depth: 0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Before saving/uploading the ccache archive on push, run two
maintenance commands and drop the scratch directory from the tar:

  * ccache --evict-older-than 1d drops entries that were not
    accessed in the last day, so long-unused results do not sit
    in the cache forever across runs.
  * ccache --cleanup enforces max_size, which is otherwise only
    applied opportunistically during inserts. Running it here
    guarantees the archive we upload is trimmed to the configured
    limit instead of whatever size the cache happened to reach.
  * .ccache/tmp is excluded from the tar. It is ccache's scratch
    directory for in-flight compilations and has no value once
    the build step has finished; including it just inflates the
    archive.

Both ccache invocations must run before the subsequent
"Cleanup dl/build_dir/staging_dir" step, because that step
removes staging_dir/host/bin/ccache.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Bump the kernel ccache max_size from 800M to 1G, and the packages
ccache limit from the default 5G to 8G. Multiple package builds have
been observed hitting the 5G default, and the kernel cache has been
reaching the previous 800M limit. Since entries not accessed in the
last day are now evicted before the archive is uploaded, a larger
max_size no longer risks unbounded growth across runs.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Zero the ccache stats before the build so the stats printed
afterwards reflect only the current run, not counters accumulated
into the restored cache archive. Also fix the "Show ccache stats"
step, which was missing CCACHE_CONFIGPATH2 and so didn't see the
system ccache.conf written during configuration, and switch it to
-vv for the per-reason breakdown that's useful when debugging cache
misses.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
[ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=800M >> $SYSTEM_CCACHE_CONF
echo compiler_type=gcc >> $CCACHE_CONFIGPATH2
[ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=1G >> $CCACHE_CONFIGPATH2
[ ${{ inputs.ccache_type }} = 'packages' ] && echo max_size=8G >> $CCACHE_CONFIGPATH2
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In my test the mips malta full build generated 1.9GB and x86/64 2.4GB.

@github-actions
Copy link
Copy Markdown

Warning

Some formality checks failed.

Consider (re)reading submissions guidelines.

Failed checks

Issues marked with an ❌ are failing checks.

Commit 3a3b290

  • 🔶 Commit subject length: recommended max 60, required max 80 characters

For more details, see the full job log.

Something broken? Consider providing feedback.

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