Skip to content

less fsyncs via overlay volatile - #11559

Merged
sipsma merged 1 commit into
dagger:mainfrom
sipsma:chown-slow
Dec 30, 2025
Merged

sipsma merged 1 commit into
dagger:mainfrom
sipsma:chown-slow

Conversation

@sipsma

@sipsma sipsma commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor

Looked into the chown perf regression with ebpf and found that each chown was causing overlay to call fsync on every file (within its copy-up internal functions), each of which took ~8ms on my laptop. 8ms isn't a lot to a human but when you are serially chowning 100k files it adds up quickly. Syscalls like this shouldn't be that slow generally, especially for the test case where each file is only 1 byte.

It's not entirely clear to me why overlay makes this so slow. I can repro the slowness outside of dagger with hand-crafted overlay mounts, but when I remove overlay from the equation and use the same underlying filesystem it's much much faster.

  • This might be worth looking into separately. It may easily just be expected behavior I haven't encountered before, but smells slightly off...

This all reminded me of @marcosnils's effort a long time ago to upstream support for the overlay volatile option, which met a bunch of friction and didn't get merged. Thankfully, we no longer have those problems!

volatile skips the fsyncs overlay does and fixes the perf problem for me.

cc @grouville


First run in CI is definitely quite fast, a couple of checks are several minutes faster than they were most recently on main:

  1. This PR
  2. Main

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@sipsma
sipsma force-pushed the chown-slow branch 3 times, most recently from ffa4bc7 to 58b2487 Compare December 29, 2025 20:46
@sipsma
sipsma marked this pull request as ready for review December 29, 2025 20:46
@sipsma sipsma added this to the v0.19.9 milestone Dec 29, 2025
@sipsma
sipsma requested a review from a team December 29, 2025 21:03

@vito vito left a comment

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.

Image

return fmt.Errorf("mount rootfs: %w", err)
}

overlayIncompatDirs := overlay.VolatileIncompatDirs(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.

For the curious (as I was) what an 'incompat' dir is: https://docs.kernel.org/filesystems/overlayfs.html#volatile-mount

Seems like a way to determine whether a mount should be discarded in the event of a rough shutdown. I guess it shouldn't matter much in our case, but that the right thing to do is to clean it up after use in the 'happy path'? The docs also say the "user" should notice its presence and discard the dirs, so I guess the OS doesn't do that itself?

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 exactly, sorry I explained all this in more depth in the updated commit message but that doesn't autopropagate to the PR description. I'll put a nice comment on the code before merging too

Looked into the chown perf regression with ebpf and found that each chown was causing overlay to
call fsync on every file (within its copy-up internal functions), each of which took ~8ms on my
laptop. 8ms isn't a lot to a human but when you are serially chowning 100k files it adds up quickly.
Syscalls like this shouldn't be that slow generally, especially for the test case where each file is
only 1 byte.

It's not entirely clear to me why overlay makes this so slow. I can repro the slowness outside of
dagger with hand-crafted overlay mounts, but when I remove overlay from the equation and use the
same underlying filesystem it's much much faster.

This all reminded me of marcosnils's effort a long time ago to upstream support for the overlay
volatile option, which met a bunch of friction and didn't get merged. Thankfully, we no longer have
those problems!

`volatile` skips the fsyncs overlay does and fixes the perf problem for me. There's a good chunk of
trickiness and careful handling needed here since we sometimes need to remount overlays that were
previously mounted with the same upper/work dirs (cache mounts, exec-after-failure mounts, etc.), in
which case the leftover `<workdir>/work/incompat` dir needs to be removed to prevent overlay from
error'ing out (its attempt to warn us that the mount may have been corrupted after a previous crash).

Signed-off-by: Erik Sipsma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants