AOSP 8.1编译时ccache设为30GB却始终不超过1GB的技术咨询
Let's break down the possible reasons why your ccache isn't growing beyond 1GB despite setting a 30GB limit, and walk through practical fixes for each scenario:
1. Verify ccache Configuration in the Container
First, confirm that your max size setting is actually active inside the Docker container:
- Enter your running container with
docker exec -it <container-name> /bin/bash - Run
ccache -pand look for themax_sizeentry. If it shows 1GB instead of 30GB, your configuration isn't taking effect.
Fixes for Configuration Issues:
- Set the max size directly in the container: Run
ccache -M 30Gto enforce the limit immediately. - Align the config file with your mounted directory: ccache reads config from
~/.ccache/ccache.confby default. Since you're mounting/home/builder/ccache/, either:- Move your
ccache.confinto this mounted directory and set the environment variable:export CCACHE_CONFIGPATH=/home/builder/ccache/ccache.conf - Add the max size line directly to the config file:
echo "max_size = 30G" >> /home/builder/ccache/ccache.conf
- Move your
2. Check Host Disk Space & Quotas
Even if the container's ccache is set to 30GB, the host system might be limiting the space:
- On your host machine, run
df -h /path/to/your/host/ccache-directoryto check available space on the partition where your ccache is mounted. Make sure there's at least 30GB of free space here. - Check if disk quotas are enabled for the user owning the host ccache directory: Run
quota -u <your-host-username>to see if a quota cap is restricting growth.
3. Confirm AOSP Build Environment Variables
AOSP's build scripts might be overriding your ccache settings:
- Before starting the build, explicitly set these variables in the container to ensure they take priority:
export USE_CCACHE=1 export CCACHE_DIR=/home/builder/ccache/ export CCACHE_MAXSIZE=30G - You can also add these lines to the builder user's
~/.bashrcor~/.profilein the container to make them persistent across sessions.
4. Check Directory Permissions
If the builder user inside the container doesn't have write access to the mounted ccache directory, ccache can't store more cache:
- In the container, run
ls -ld /home/builder/ccache/to check permissions. The output should show read/write access for thebuilderuser (uid/gid matching the container's user). - If permissions are incorrect, fix them on the host:
chown -R <host-uid>:<host-gid> /path/to/host/ccache(match the uid/gid of thebuilderuser in the container) or adjust them inside the container withsudo chown -R builder:builder /home/builder/ccache/.
5. Check for ccache Version Bugs
Ubuntu 16.04 ships with ccache 3.2.4, which has known issues with large max size settings in some scenarios. Try upgrading to a newer version:
- Inside the container, install dependencies first:
sudo apt-get install autoconf automake libtool - Download and compile the latest stable ccache release (e.g., 4.8.3):
wget https://github.com/ccache/ccache/releases/download/v4.8.3/ccache-4.8.3.tar.xz tar xvf ccache-4.8.3.tar.xz cd ccache-4.8.3 ./configure make sudo make install - Verify the new version with
ccache --versionand re-test your build.
After trying these steps, run watch ccache -s again during your AOSP build—you should see the cache size start growing towards the 30GB limit as more objects are compiled and cached.
内容的提问来源于stack exchange,提问作者Slaviro

