1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

Replace POSIX_FADV_DONTNEED with POSIX_FADV_NOREUSE

On Linux 7.2.11, this would make BACKUP SERVER TO without O_DIRECT
faster than with O_DIRECT; previously, it was the opposite.
This commit is contained in:
Marko Mäkelä
2026-10-23 09:01:49 +03:00
parent b1260be171
commit 7587aeaec8
2 changed files with 26 additions and 12 deletions

View File

@@ -114,9 +114,6 @@ static ssize_t pread_write(backup::handle in_fd, backup_fd out_fd,
ret= pread(in_fd, b, ssize_t(size), o);
if (ret > 0)
{
#ifdef POSIX_FADV_DONTNEED
std::ignore= posix_fadvise(in_fd, o, ret, POSIX_FADV_DONTNEED);
#endif
uint64_t wo{o};
o+= ret;
count-= uint64_t(ret);
@@ -178,6 +175,7 @@ int copy_entire_file(int src, int dst) noexcept
{
uint64_t end(lseek(src, 0, SEEK_END));
#ifdef POSIX_FADV_NOREUSE
std::ignore= posix_fadvise(src, 0, 0, POSIX_FADV_NOREUSE);
std::ignore= posix_fadvise(dst, 0, 0, POSIX_FADV_NOREUSE);
#endif
int ret;
@@ -190,9 +188,6 @@ int copy_entire_file(int src, int dst) noexcept
std::ignore= posix_fadvise(src, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
ret= backup::copy(src, dst, 0, end);
#ifdef POSIX_FADV_DONTNEED
std::ignore= posix_fadvise(src, 0, 0, POSIX_FADV_DONTNEED);
#endif
#ifdef POSIX_FADV_NORMAL
std::ignore= posix_fadvise(src, 0, 0, POSIX_FADV_NORMAL);
#endif
@@ -250,9 +245,6 @@ int copy(handle src, backup_fd dst, uint64_t start, uint64_t end) noexcept
#else
ssize_t ret{pread_write<false>(src, dst, start, end)};
assert(ret <= 0);
#ifdef POSIX_FADV_DONTNEED
std::ignore= posix_fadvise(src, start, end, POSIX_FADV_DONTNEED);
#endif
return int(ret);
#endif
}
@@ -484,9 +476,6 @@ int copy_file_range_try(int src, int dst, uint64_t start, uint64_t end)
assert(ret <= 0);
if (ret && (errno == EOPNOTSUPP || errno == EXDEV))
return 1;
#ifdef POSIX_FADV_DONTNEED
std::ignore= posix_fadvise(src, start, end - start, POSIX_FADV_DONTNEED);
#endif
return int(ret);
}
#endif

View File

@@ -615,14 +615,28 @@ public:
std::swap(f, l);
}
#ifdef POSIX_FADV_NOREUSE
std::ignore= posix_fadvise(f, 0, 0, POSIX_FADV_NOREUSE);
#endif
#ifdef POSIX_FADV_SEQUENTIAL
std::ignore= posix_fadvise(f, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
tracked=
new tracked_log{f, first_lsn, log_sys.file_size};
if (l != OS_FILE_CLOSED)
{
#ifdef POSIX_FADV_NOREUSE
std::ignore= posix_fadvise(l, 0, 0, POSIX_FADV_NOREUSE);
#endif
#ifdef POSIX_FADV_SEQUENTIAL
std::ignore= posix_fadvise(l, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
tracked->next= new tracked_log{l, first_lsn + log_sys.capacity(),
uint64_t
(IF_WIN(os_file_get_size(l),
lseek(l, 0, SEEK_END)))};
}
}
log_dst= context::log_track_create(target, first_lsn);
if (IF_WIN(log_dst != INVALID_HANDLE_VALUE, log_dst >= 0))
@@ -1655,6 +1669,10 @@ private:
# endif
for (;;)
{
#ifdef POSIX_FADV_NOREUSE
std::ignore=
posix_fadvise(node->handle, 0, 0, POSIX_FADV_NOREUSE);
#endif
#ifdef POSIX_FADV_SEQUENTIAL
std::ignore=
posix_fadvise(node->handle, 0, 0, POSIX_FADV_SEQUENTIAL);
@@ -2205,11 +2223,18 @@ public:
{
# ifdef POSIX_FADV_NOREUSE
std::ignore= posix_fadvise(dst, 0, 0, POSIX_FADV_NOREUSE);
std::ignore= posix_fadvise(src, 0, 0, POSIX_FADV_NOREUSE);
# endif
# ifdef POSIX_FADV_SEQUENTIAL
std::ignore= posix_fadvise(src, 0, 0, POSIX_FADV_SEQUENTIAL);
# endif
err= extend(dst, chunk->offset) ||
backup::copy(src, dst, chunk[-1].offset, chunk[-1].offset +
chunk[-1].length) ||
(lsn <= ctx.checkpoint && write_checkpoint(dst, cp_buf));
# ifdef POSIX_FADV_NORMAL
std::ignore= posix_fadvise(src, 0, 0, POSIX_FADV_NORMAL);
# endif
#ifdef _WIN32
err|= !CloseHandle(dst);
#else