From ca8d982d4fa83de1a480935b965cf2a1c1d97a13 Mon Sep 17 00:00:00 2001 From: Alan Swanson Date: Wed, 10 May 2023 17:15:05 +0100 Subject: [PATCH] use madvise(MADV_RANDOM) when torrenting mmaped files to reduce disk readahead --- src/mmap.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/mmap.cpp b/src/mmap.cpp index c4c8da6d5d4..4e91a3bc87b 100644 --- a/src/mmap.cpp +++ b/src/mmap.cpp @@ -187,7 +187,7 @@ file_mapping::file_mapping(file_handle file, open_mode_t const mode, std::int64_ #if TORRENT_USE_MADVISE if (file_size > 0) { - int const advise = ((mode & open_mode::random_access) ? 0 : MADV_SEQUENTIAL) + int const advise = ((mode & open_mode::random_access) ? MADV_RANDOM : MADV_SEQUENTIAL) #ifdef MADV_DONTDUMP // on versions of linux that support it, ask for this region to not be // included in coredumps (mostly to make the coredumps more manageable @@ -200,8 +200,7 @@ file_mapping::file_mapping(file_handle file, open_mode_t const mode, std::int64_ | MADV_NOCORE #endif ; - if (advise != 0) - madvise(m_mapping, static_cast(m_size), advise); + madvise(m_mapping, static_cast(m_size), advise); } #endif }