我运行一个 CI 服务器,用于构建自定义 linux 内核。CI 服务器并不强大,每次构建的时间限制为 3 小时。为了在这个限制内工作,我想到了使用 ccache 缓存内核构建。我希望我可以在每个次要版本发布时创建一个缓存,并将其重新用于补丁版本,例如我有一个为 4.18 制作的缓存,我想将它用于所有 4.18.x 内核。
删除构建时间戳后,这对于我正在构建的确切内核版本非常有用。对于上面提到的 4.18 内核,在 CI 上构建它会提供以下统计信息:
$ ccache -s
cache directory
primary config
secondary config (readonly) /etc/ccache.conf
stats zero time Thu Aug 16 14:36:22 2018
cache hit (direct) 17812
cache hit (preprocessed) 38
cache miss 0
cache hit rate 100.00 %
called for link 3
called for preprocessing 29039
unsupported code directive 4
no input file 2207
cleanups performed 0
files in cache 53652
cache size 1.4 GB
max cache size 5.0 GB
100% 的缓存命中率和一个小时来完成构建,出色的统计数据和预期的一样。
不幸的是,当我尝试构建 4.18.1 时,我得到
cache directory
primary config
secondary config (readonly) /etc/ccache.conf
stats zero time Thu Aug 16 10:36:22 2018
cache hit (direct) 0
cache hit (preprocessed) 233
cache miss 17658
cache hit rate 1.30 %
called for link 3
called for preprocessing 29039
unsupported code directive 4
no input file 2207
cleanups performed 0
files in cache 90418
cache size 2.4 GB
max cache size 5.0 GB
这是 1.30% 的命中率,而构建时间反映了这种糟糕的性能。即仅从单个补丁版本更改。
我本来预计缓存性能会随着时间的推移而下降,但不会降到这个程度,所以我唯一的想法是,除了简单的时间戳之外,还有更多的不确定性。例如,大多数/所有源文件是否包含完整的内核版本字符串?我的理解是,这样的事情会完全破坏缓存。有没有办法让缓存按我的意愿工作,还是不可能?