Skip to content

Do not open log file with O_SYNC - #5547

Merged
lifubang merged 1 commit into
opencontainers:mainfrom
kolyshkin:log-no-osync
Oct 20, 2026
Merged

lifubang merged 1 commit into
opencontainers:mainfrom
kolyshkin:log-no-osync

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

The log file is opened with O_SYNC since commit 8f20692 ("Ensure logs
are flushed", PR #637). The intent was to make sure log entries are not
lingering in a buffer, but *os.File is not buffered: logrus does a
single Write per entry, which is a single write(2), and the data is
visible to any reader (e.g. containerd reading the log after runc
exits) as soon as it returns.

What O_SYNC actually does is wait for the data to hit the disk on every
write, which only helps to preserve the log in case of a host crash or
power loss. This is of little value for runc logs, while the cost on a
slow disk (e.g. a network-attached cloud volume) is substantial,
especially with --debug.

Remove O_SYNC.

Fixes: #5540

@kolyshkin

Copy link
Copy Markdown
Contributor Author

Just checked how it affects runc exec, out of curiosity:

A rootless busybox container, with runc --debug --log writing to ext4 on a local NVMe drive (/var/tmp, which is not tmpfs). Kernel 7.2.5, measured with hyperfine (300 runs, 20 warmup runs):

  $ hyperfine -N -w 20 -r 300 \
    -n before "runc.before --root $R --debug --log $L/before.log exec bench true" \
    -n after  "runc.after  --root $R --debug --log $L/after.log  exec bench true" \
    -n nolog  "runc.after  --root $R exec bench true"
  | `runc exec`           | mean ± σ        | max     |
  |-----------------------|-----------------|---------|
  | before (with O_SYNC)  | 31.2 ± 4.6 ms   | 91.4 ms |
  | after (no O_SYNC)     | 11.1 ± 1.0 ms   | 14.3 ms |
  | no `--log` at all     | 10.7 ± 1.1 ms   | 14.4 ms |

A single exec writes 52 debug log lines, so before this change it waited for the disk 52 times. That works out to about 0.4 ms per line, or about 20 ms per exec. With this patch, writing a debug log costs almost nothing compared to running with no log at all. A repeated run gave the same results.

This is a fast local NVMe drive. On a network-attached cloud volume, where fsync takes milliseconds, the difference should be much bigger.

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@kolyshkin kolyshkin left a comment

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.

(fake review to trigger review-policy check)

@kolyshkin

Copy link
Copy Markdown
Contributor Author

Review-policy workflow works, giving other maintainers time to review:

Error: Needs another LGTM, or re-run this check after 2026-10-19 02:46 UTC.

So it's either 2 LGTMs or 1 LGTM + 1 week.

@cyphar cyphar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah the justification for this in #637 seems very suspect. Thanks!

@cyphar
cyphar added this pull request to the merge queue Oct 20, 2026
@cyphar

cyphar commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

I'm shocked how big an impact O_SYNC made in our startup times. I wonder how this impacts the classic crun performance comparison... Maybe "300% faster" should be in the changelog! 😉

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Oct 20, 2026
@cyphar
cyphar added this pull request to the merge queue Oct 20, 2026
@cyphar

cyphar commented Oct 20, 2026

Copy link
Copy Markdown
Member

Weird, all the checks passed...?

@kolyshkin

Copy link
Copy Markdown
Contributor Author

@cyphar merge queue is broken but is being fixed by #5563, which only needs two LGTMs

@kolyshkin

Copy link
Copy Markdown
Contributor Author

I'm shocked how big an impact O_SYNC made in our startup times. I wonder how this impacts the classic crun performance comparison... Maybe "300% faster" should be in the changelog! 😉

Logging to a real fs is not the common case. The common cases (when run from podman or docker or some such) are either logging to pipes or to tmpfs.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Oct 20, 2026
The log file is opened with O_SYNC since commit 8f20692 ("Ensure logs
are flushed", PR opencontainers#637). The intent was to make sure log entries are not
lingering in a buffer, but *os.File is not buffered: logrus does a
single Write per entry, which is a single write(2), and the data is
visible to any reader (e.g. containerd reading the log after runc
exits) as soon as it returns.

What O_SYNC actually does is wait for the data to hit the disk on every
write, which only helps to preserve the log in case of a host crash or
power loss. This is of little value for runc logs, while the cost on a
slow disk (e.g. a network-attached cloud volume) is substantial,
especially with --debug.

Remove O_SYNC.

Fixes: opencontainers#5540
Suggested-by: Benjamin Peterson <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
@lifubang
lifubang added this pull request to the merge queue Oct 20, 2026
Merged via the queue into opencontainers:main with commit 1ffa703 Oct 20, 2026
96 checks passed
ctalledo pushed a commit to nestybox/sysbox-runc that referenced this pull request Oct 20, 2026
Upstream runc is about to make similar change: opencontainers/runc#5547

Signed-off-by: Benjamin Peterson <[email protected]>
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.

log file opened with O_SYNC

4 participants