Skip to content

Commit

Permalink
don't hint POSIX_FADV_RANDOM. Normal piece sizes, of 2 or 4 MiB, prob…
Browse files Browse the repository at this point in the history
…ably warrants read-ahead. Some antecdotes suggests this improve read speed in some circumstances
  • Loading branch information
arvidn committed Oct 20, 2024
1 parent 911011e commit 07b2574
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

2.0.11 not released

* don't hint FADV_RANDOM on posix systems. May improve seeding performance
* allow boost connect while checking resume data if no_verify_files flag is set
* fix BEP-40 peer priority for IPv6
* limit piece size in torrent creator
Expand Down
2 changes: 1 addition & 1 deletion include/libtorrent/aux_/open_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace aux {
constexpr open_mode_t no_cache = 1_bit;
constexpr open_mode_t truncate = 2_bit;
constexpr open_mode_t no_atime = 3_bit;
constexpr open_mode_t random_access = 4_bit;
constexpr open_mode_t sequential_access = 4_bit;
constexpr open_mode_t hidden = 5_bit;
constexpr open_mode_t sparse = 6_bit;
constexpr open_mode_t executable = 7_bit;
Expand Down
4 changes: 2 additions & 2 deletions include/libtorrent/disk_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ namespace file_open_mode {
// this generally improves disk performance.
constexpr file_open_mode_t no_atime = 3_bit;

// open the file for random access. This disables read-ahead
// logic
// When this is not set, the kernel is hinted that access to this file will
// be made sequentially.
constexpr file_open_mode_t random_access = 5_bit;

#if TORRENT_ABI_VERSION == 1
Expand Down
10 changes: 5 additions & 5 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
DWORD file_flags(open_mode_t const mode)
{
return ((mode & open_mode::no_cache) ? FILE_FLAG_WRITE_THROUGH : 0)
| ((mode & open_mode::random_access) ? 0 : FILE_FLAG_SEQUENTIAL_SCAN)
| ((mode & open_mode::sequential_access) ? FILE_FLAG_SEQUENTIAL_SCAN : 0)
;
}

Expand Down Expand Up @@ -349,7 +349,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
// http://support.microsoft.com/kb/2549369
return ((mode & open_mode::hidden) ? FILE_ATTRIBUTE_HIDDEN : FILE_ATTRIBUTE_NORMAL)
| ((mode & open_mode::no_cache) ? FILE_FLAG_WRITE_THROUGH : 0)
| ((mode & open_mode::random_access) ? 0 : FILE_FLAG_SEQUENTIAL_SCAN)
| ((mode & open_mode::sequential_access) ? FILE_FLAG_SEQUENTIAL_SCAN : 0)
;
}

Expand Down Expand Up @@ -563,11 +563,11 @@ file_handle::file_handle(string_view name, std::int64_t const size
}
#endif

#if (TORRENT_HAS_FADVISE && defined POSIX_FADV_RANDOM)
if (mode & aux::open_mode::random_access)
#if (TORRENT_HAS_FADVISE && defined POSIX_FADV_SEQUENTIAL)
if (mode & aux::open_mode::sequential_access)
{
// disable read-ahead
::posix_fadvise(m_fd, 0, 0, POSIX_FADV_RANDOM);
::posix_fadvise(m_fd, 0, 0, POSIX_FADV_SEQUENTIAL);
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::sequential_access) ? MADV_SEQUENTIAL : 0)
#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
Expand Down
2 changes: 1 addition & 1 deletion src/mmap_disk_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace {
aux::open_mode_t file_mode_for_job(aux::mmap_disk_job* j)
{
aux::open_mode_t ret = aux::open_mode::read_only;
if (!(j->flags & disk_interface::sequential_access)) ret |= aux::open_mode::random_access;
if (j->flags & disk_interface::sequential_access) ret |= aux::open_mode::sequential_access;
return ret;
}

Expand Down

0 comments on commit 07b2574

Please sign in to comment.