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

fix bug in auto disk cache size logic #4506

Merged
merged 1 commit into from
Apr 4, 2020
Merged
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
@@ -1,3 +1,4 @@
* fix bug in auto disk cache size logic
* fix issue with outgoing_interfaces setting, where bind() would be called twice
* add build option to disable share-mode
* support validation of HTTPS trackers
Expand Down
1 change: 1 addition & 0 deletions include/libtorrent/settings_pack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace aux {
, aux::session_settings_single_thread& sett
, std::vector<void(aux::session_impl::*)()>* callbacks = nullptr);
TORRENT_EXTRA_EXPORT void run_all_updates(aux::session_impl& ses);
TORRENT_EXTRA_EXPORT int default_int_value(int const name);

// converts a setting integer (from the enums string_types, int_types or
// bool_types) to a string, and vice versa.
Expand Down
2 changes: 1 addition & 1 deletion src/disk_buffer_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ namespace libtorrent {
if (cache_size < 0)
{
std::int64_t phys_ram = total_physical_ram();
if (phys_ram == 0) m_max_use = 1024;
if (phys_ram == 0) m_max_use = default_int_value(settings_pack::cache_size);
else
{
// this is the logic to calculate the automatic disk cache size
Expand Down
2 changes: 1 addition & 1 deletion src/platform_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace libtorrent {
MEMORYSTATUSEX ms;
ms.dwLength = sizeof(MEMORYSTATUSEX);
if (GlobalMemoryStatusEx(&ms))
ret = int(ms.ullTotalPhys);
ret = ms.ullTotalPhys;
Copy link
Contributor

@FranciscoPombal FranciscoPombal Apr 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, isn't there still an unsigned -> signed conversion happening here which could return a negative number? If the number is bigger than std::numeric_limits<int64_t>::max(), just truncate to that value, so that a negative number is never returned.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. I assumed DWORDLONG was signed

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestingly, there is no warning for this. I think it's safe to assume the amount of memory will not exceed the max for int64_t (given that current hardware only can address 48 bits)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still I think explicitly enforcing the the truncation to std::numeric_limits<int64_t>::max() better conveys the intent for humans, even if the machines don't need it.

else
ret = 0;
#elif defined TORRENT_LINUX
Expand Down
6 changes: 6 additions & 0 deletions src/settings_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,12 @@ constexpr int CLOSE_FILE_INTERVAL = 0;
return ret;
}

int default_int_value(int const name)
{
TORRENT_ASSERT((name & settings_pack::type_mask) == settings_pack::int_type_base);
return int_settings[name - settings_pack::int_type_base].default_value;
}

void apply_pack(settings_pack const* pack, aux::session_settings& sett
, aux::session_impl* ses)
{
Expand Down