Skip to content
/ server Public

MDEV - 38507 fadvise64() called on socat pipe by Mariabackup is useless overhead (ESPIPE)#4748

Open
kjarir wants to merge 1 commit intoMariaDB:10.11from
kjarir:MDEV-38507-mariabackup-overhead
Open

MDEV - 38507 fadvise64() called on socat pipe by Mariabackup is useless overhead (ESPIPE)#4748
kjarir wants to merge 1 commit intoMariaDB:10.11from
kjarir:MDEV-38507-mariabackup-overhead

Conversation

@kjarir
Copy link

@kjarir kjarir commented Mar 6, 2026

Background:
When taking backups or streaming data through pipes using mariabackup, posix_fadvise with a 0 length/size was being called restrictively after every successful write operation across ds_stdout.cc, ds_tmpfile.cc, and ds_local.cc datasinks.

In the case of pipes, posix_fadvise evaluates to ESPIPE and fails. Since it was being executed inside the my_write condition logic repeatedly for every single write, it introduced massive overhead through millions of redundant, failing syscalls.

Changes in this PR:
As discussed and suggested by @grooverdan in the issue thread, the posix_fadvise call with a length/size of 0 (which equates to EOF/entire file) only needs to be made once when the file/sink is opened, rather than repetitively after every write.

We moved the respective posix_fadvise(..., 0, 0, POSIX_FADV_DONTNEED) calls out of my_write blocks into the initialization/open blocks (local_open, stdout_open, tmpfile_open).

Impact:

  • Fixes the massive overhead associated with redundant syscalls on pipes.
  • Fails fast on the pipe early on instead of running millions of redundant syscalls on large files.
  • Drastically reduces posix_fadvise system call counts, improving performance.

Testing done:
Verified the correctness of the changes by successfully running and passing the mariabackup test suite in a local build environment:

Screenshot 2026-03-07 at 12 14 40 AM

@grooverdan grooverdan self-assigned this Mar 7, 2026
…s overhead (ESPIPE)

Currently, posix_fadvise(..., 0, 0, POSIX_FADV_DONTNEED) is executed repeatedly after each my_write. In case of pipes, it evaluates to ESPIPE and fails. Because it executes after every write, this results in millions of redundant syscalls, introducing massive overhead.

As proposed by Daniel Black, posix_fadvise with a length/size of 0 (which equates to EOF) should be invoked once when the file is opened, rather than repetitively after every write. This change moves the fadvise call to the respective _open functions for ds_local, ds_stdout and ds_tmpfile datasinks. It fails fast on pipes early on and eliminates the redundant syscall overhead for subsequent write operations.
@kjarir kjarir force-pushed the MDEV-38507-mariabackup-overhead branch from de5a73b to 67268ac Compare March 7, 2026 09:21
@CLAassistant
Copy link

CLAassistant commented Mar 7, 2026

CLA assistant check
All committers have signed the CLA.

@kjarir kjarir changed the base branch from main to 10.11 March 7, 2026 09:22
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.

3 participants