Skip to content

engine: optimize copies to use hardlinks when possible#11497

Merged
sipsma merged 4 commits intodagger:mainfrom
sipsma:hardlink-copy
Dec 2, 2025
Merged

engine: optimize copies to use hardlinks when possible#11497
sipsma merged 4 commits intodagger:mainfrom
sipsma:hardlink-copy

Conversation

@sipsma
Copy link
Copy Markdown
Contributor

@sipsma sipsma commented Nov 27, 2025

Realized while talking to a user about disk usage problems that thanks to various forward progress on the Theseus front this has become some very low-hanging fruit for optimization.

Before this a WithDirectory operation could under very specific circumstances use MergeOp, which attempts to use hardlinks in its implementation in order to skip copies of files and thus save disk space and time.

This change greatly expands the circumstances in which that hardlink optimization is possible. It will essentially always be used now except for the cases where an owner/permission or other metadata is being modified during the copy.

  • Theoretically possible to support hardlinking even in those cases via overlay metacopy, but that's a big separate can of worms for the future.

Results so far:

  • Fresh (no existing cache) engine build (engine-dev container sync) consumes 1.7GB less space
  • TestModules takes 2.1GB less space
  • Some of the test suites seem to be quite a bit faster (tentatively, hopefully not just CI noise), by up to a few minutes. They all take no longer than 9 minutes to run now (vs. like 12m on main)
    • EDIT: I might have just been getting lucky last week with CI rolls, some of those jobs are taking over 11m again. The disk space benefits still stand though.

@sipsma sipsma force-pushed the hardlink-copy branch 7 times, most recently from 547bdc8 to b8537fd Compare December 1, 2025 20:12
@sipsma sipsma added this to the v0.19.8 milestone Dec 2, 2025
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
}
// TODO: is this robust? the one for submounts is very complicated
if state.rootMount.Selector != "" {
for i, mnt := range rootMnts {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this for loop disappeared in the new version. Not exactly sure what it was trying to do and if you removed it deliberately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah the loop is gone because it was unnecessary. We can just mount the rootfs and then tell runc to use a subdir of that mount rather than reset the source of each mount (which is now handled above on line 405)

@sipsma sipsma merged commit 52cd3ce into dagger:main Dec 2, 2025
48 of 56 checks passed
Copy link
Copy Markdown
Collaborator

@alexcb alexcb left a comment

Choose a reason for hiding this comment

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

looks cool! nice speedup!

raykao pushed a commit to raykao/dagger that referenced this pull request Dec 9, 2025
* engine: optimize copies to use hardlinks when possible

Signed-off-by: Erik Sipsma <erik@sipsma.dev>

* cleanup TODOs

Signed-off-by: Erik Sipsma <erik@sipsma.dev>

* add integ tests

Signed-off-by: Erik Sipsma <erik@sipsma.dev>

* changelog

Signed-off-by: Erik Sipsma <erik@sipsma.dev>

---------

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
raykao pushed a commit to raykao/dagger that referenced this pull request Dec 14, 2025
* engine: optimize copies to use hardlinks when possible

Signed-off-by: Erik Sipsma <erik@sipsma.dev>

* cleanup TODOs

Signed-off-by: Erik Sipsma <erik@sipsma.dev>

* add integ tests

Signed-off-by: Erik Sipsma <erik@sipsma.dev>

* changelog

Signed-off-by: Erik Sipsma <erik@sipsma.dev>

---------

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
tiborvass added a commit to tiborvass/dagger that referenced this pull request Jan 7, 2026
Commit 52cd3ce from PR dagger#11497 regressed cross compilation.
This commit fixes it.

Signed-off-by: Tibor Vass <teabee89@gmail.com>
tiborvass added a commit to tiborvass/dagger that referenced this pull request Jan 7, 2026
Commit 52cd3ce from PR dagger#11497 regressed cross compilation.
This commit fixes it.

Signed-off-by: Tibor Vass <teabee89@gmail.com>
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.

3 participants