1
0
mirror of https://github.com/opencontainers/runc.git synced 2026-10-23 19:49:01 +03:00

Do not open log file with O_SYNC

The log file is opened with O_SYNC since commit 8f206929 ("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
Suggested-by: Benjamin Peterson <benjamin@engflow.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2026-10-11 19:46:01 -07:00
committed by lfbzhm
parent 96a7a46d02
commit 2b5f516b12

View File

@@ -228,7 +228,7 @@ func configLogrus(cmd *cli.Command) error {
}
if file := cmd.String("log"); file != "" {
f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0o644)
f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644)
if err != nil {
return err
}