Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCACHE_TEMPDIR="/tmp/ccache-tmp" if /tmp is mounted as tmpfs #4703

Merged
merged 1 commit into from Jan 16, 2023

Conversation

The-going
Copy link
Contributor

@The-going The-going commented Jan 15, 2023

Description

When the system temporary folder is mounted as tmpfs, it makes sense to mount
the temporary compiler cache folder in /tmp. This speeds up the compilation process
and saves the hard disk resource.
About the SSD resource, I think that it is clear to everyone.

How Has This Been Tested?

For my virtual machine 6 spu frequency 3.6G
Compile Time before: Runtime 46:43 min
Compile time after: Runtime 35:42 min

Checklist:

  • Test build

@rpardini
Copy link
Member

rpardini commented Jan 15, 2023

This might make sense, I've explored similar in armbian-next (but took other paths after consideration).

Other, possibly lunatic, ideas:

  • the compression used by ccache reduces disk usage, but takes CPU, even if little, and CPU is what is needed during a build -- so might be worth investigating disabling it
  • any changes to versions in the kernel/u-boot Makefile, LOCALVERSION, or anything related causes version.h to change, which then causes everything else to change. ccache does not help at all if that happens, since the new version causes a cache miss for every single file. in that scenario, ccache is slowing us down.
  • scenarios ccache helps with are:
    • new build after a make clean or git clean -xfd, but with the same versions as before..
    • when only changing the contents of patches, but keeping the same version and rebuilding
    • (compensates a bit for) fact master does/did bizarre make clean in the tree (during packaging for cross build)
    • (compensates a bit for) fact master does not keep proper modification time of patched files / drivers / .config etc
    • when building same version across families of the same architecture (armhf/arm64) - but is counterproductive if building across arches

So it's a tradeoff with ccache already, trying to optimize it by tmpfs I don't think makes much difference.
I wouldn't do it by default since I think having /tmp in tmpfs is done by systemd tmp.mount, (so everywhere) and then any reboot causes lost cache, which might be surprising.
Maybe just use PRIVATE_CCACHE for pointing to your tmpfs instead.

EDIT: I had missed it's about CCACHE_TEMPDIR not CCACHE_DIR

@rpardini
Copy link
Member

trying to optimize it by tmpfs I don't think makes much difference.

Scratch that. I didn't pay attention (or you edited the original post?) to the below.

Compile Time before: Runtime 46:43 min
Compile time after: Runtime 35:42 min

I will shut up and go test your idea.

@rpardini
Copy link
Member

For my virtual machine 6 spu frequency 3.6G

Please also tell us the storage configuration?
Also what kind of virtualization technology.

Copy link
Contributor

@iav iav left a comment

Choose a reason for hiding this comment

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

What do you think about to add into config-docker.conf something like DOCKER_FLAGS+=(-v=$(mktemp -d)/:/tmp/)?

@iav
Copy link
Contributor

iav commented Jan 15, 2023

I wouldn't do it by default since I think having /tmp in tmpfs is done by systemd tmp.mount, (so everywhere) and then any reboot causes lost cache, which might be surprising.

It's not ccache data itself.

@The-going
Copy link
Contributor Author

@rpardini Do you understand well how the compiler cache works?
Explanations:

CCACHE_DIR - The folder in which the result of the compilation process is recorded with the process log for each file.

CCACHE_TEMPDIR - Temporary files are constantly being written and destroyed in this folder in the process of work. when the result is achieved, it is transferred to the CCACHE_DIR folder. This is a very large read write traffic. And a faster option when it happens in RAM.

My desktop machine has an i7 CPU of 8 threads. The RAM is 32 Gigs.
Virtual machine QEMU 6 cpu 8 gigs.

@The-going
Copy link
Contributor Author

What do you think about to add into config-docker.conf

Igor, I don't use this technology and I can't say anything.

@rpardini
Copy link
Member

It's not ccache data itself.

CCACHE_TEMPDIR

Oh damn, I missed the TEMP part of it. Thanks for pointing it out.
That should definitely be in tmpfs!

but CCACHE_TEMPDIR defaults to something like /run/user/0 which should already be tmpfs.
(We might be missing that because of sudo and/or lack of XDG_RUNTIME_DIR)

@The-going
Copy link
Contributor Author

We might be missing that because of sudo

That's right.
verify:

ccache -p
sudo su
ccache -p

@rpardini
Copy link
Member

What do you think about to add into config-docker.conf something like DOCKER_FLAGS+=(-v=$(mktemp -d)/:/tmp/)?

Or, using Docker Volumes, --mount type=tmpfs,destination=/tmp which works across hosts/VMs too.

@iav
Copy link
Contributor

iav commented Jan 15, 2023

@The-going 177 min for full image with your proposal, about 230 min without.
ODroid-N2, emmc disk.
Nice!

@The-going The-going merged commit 43ac0cc into armbian:master Jan 16, 2023
@hzyitc
Copy link
Member

hzyitc commented Jan 16, 2023

Maybe point to .tmp/ccache and mount it as tmpfs in the script? So it can work with all environments.

@iav
Copy link
Contributor

iav commented Jan 16, 2023

Maybe point to .tmp/ccache and mount it as tmpfs in the script? So it can work with all environments.

then ccache build database will be lost on reboot

iav added a commit to iav/armbian that referenced this pull request Jan 16, 2023
@hzyitc
Copy link
Member

hzyitc commented Jan 17, 2023

then ccache build database will be lost on reboot

I mean CCACHE_TEMPDIR not CCACHE_DIR. Just make this PR work everywhere. Mounting /tmp as tmpfs isn't a default behavior on Ubuntu or Debian.

@hzyitc
Copy link
Member

hzyitc commented Jan 17, 2023

What's more, I check the manual of ccache.

temporary_dir (CCACHE_TEMPDIR)
  This option specifies where ccache will put temporary files. The default is /run/user/<UID>/ccache-tmp if /run/user/<UID> exists, otherwise <cache_dir>/tmp.

And /run/user/<UID> is mounted as tmpfs by default.

@rpardini
Copy link
Member

What's more, I check the manual of ccache.

That's outdated manual, new version states XDG_RUNTIME_DIR -- which amounts to the same thing.

And /run/user/<UID> is mounted as tmpfs by default.

On sane systems, yes. Using sane sudo enchantment, yes. Otherwise no -- which is the case with master.

Mounting /tmp as tmpfs isn't a default behavior on Ubuntu or Debian.

That's why he is checking to see it if /tmp is a tmpfs before doing it.

@hzyitc
Copy link
Member

hzyitc commented Jan 17, 2023

That's why he is checking to see it if /tmp is a tmpfs before doing it.

I mean let's do this mount in our script. So it can work for everyone since most users or developers didn't known mounting /tmp can speed up the completion.

@rpardini
Copy link
Member

I mean let's do this mount in our script. So it can work for everyone since most users or developers didn't known mounting /tmp can speed up the completion.

True. I've been doing this in different spots in armbian-next -- where the trap manager helps a lot.

tmpfs helps a lot when building on really slow I/O subsystems like mmc or spinning rust -- and not only for ccache.

Either way thanks @The-going for sparking this initiative

@The-going The-going deleted the tmpdir-ccache branch January 18, 2023 18:48
igorpecovnik pushed a commit that referenced this pull request Jan 19, 2023
Signed-off-by: Igor Velkov <iav@iav.lv>

Signed-off-by: Igor Velkov <iav@iav.lv>
smlinux pushed a commit to smlinux/armbian-tanix-tx6 that referenced this pull request Jan 20, 2023
…armbian#4704)

Signed-off-by: Igor Velkov <iav@iav.lv>

Signed-off-by: Igor Velkov <iav@iav.lv>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants