Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test merge #7780

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

2.0.11 not released

* fix performance bug in the file pool, evicting MRU instead of LRU (HanabishiRecca)
* fix bug where file_progress could sometimes be reported as >100%
* 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
Expand Down
3 changes: 2 additions & 1 deletion include/libtorrent/aux_/file_pool_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ namespace libtorrent::aux {
mi::indexed_by<
// look up files by (torrent, file) key
mi::ordered_unique<mi::member<FileEntry, file_id, &FileEntry::key>>,
// look up files by least recently used
// look up files by least recently used. New items are added to the
// back, and old items are removed from the front.
mi::sequenced<>
>
>;
Expand Down
21 changes: 15 additions & 6 deletions src/file_pool_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ namespace libtorrent::aux {
});

auto& lru_view = m_files. template get<1>();
lru_view.relocate(m_files. template project<1>(i), lru_view.begin());
lru_view.relocate(lru_view.end(), m_files. template project<1>(i));

#if TORRENT_USE_ASSERTS
// ensure the LRU index is maintained as we would expect it to be
TORRENT_ASSERT(lru_view.back().key == i->key);
#endif
return i->mapping;
}

Expand Down Expand Up @@ -145,7 +149,7 @@ namespace libtorrent::aux {

// there's an edge case where two threads are racing to insert a newly
// opened file, one thread is opening a file for writing and the other
// fore reading. If the reading thread wins, it's important that the
// for reading. If the reading thread wins, it's important that the
// thread opening for writing still overwrites the file in the pool,
// since a file opened for reading and writing can be used for both.
// So, we can't move e in here, because we may need it again of the
Expand All @@ -171,8 +175,13 @@ namespace libtorrent::aux {
}

auto& lru_view = m_files.template get<1>();
lru_view.relocate(m_files. template project<1>(i), lru_view.begin());
lru_view.relocate(lru_view.end(), m_files. template project<1>(i));
}
#if TORRENT_USE_ASSERTS
// ensure the LRU index is maintained as we would expect it to be
auto& lru_view = m_files. template get<1>();
TORRENT_ASSERT(lru_view.back().key == e.key);
#endif
notify_file_open(ofe, i->mapping, storage_error());
return i->mapping;
}
Expand Down Expand Up @@ -328,11 +337,11 @@ namespace libtorrent::aux {

#if TRACE_FILE_POOL
std::cout << std::this_thread::get_id() << " removing: ("
<< lru_view.back().key.first << ", " << lru_view.back().key.second << ")\n";
<< lru_view.front().key.first << ", " << lru_view.front().key.second << ")\n";
#endif

FileHandle mapping = std::move(lru_view.back().mapping);
lru_view.pop_back();
FileHandle mapping = std::move(lru_view.front().mapping);
lru_view.pop_front();

// closing a file may be long running operation (mac os x)
// let the caller destruct it once it has released the mutex
Expand Down
Loading