support O_NOATIME on linux and use it by default

This commit is contained in:
Arvid Norberg 2010-02-02 19:44:52 +00:00
parent 859f412189
commit 1b2798970c
5 changed files with 18 additions and 1 deletions

View File

@ -177,6 +177,7 @@ namespace libtorrent
no_buffer = 4,
mode_mask = rw_mask | no_buffer,
sparse = 8,
no_atime = 16,
attribute_hidden = 0x1000,
attribute_executable = 0x2000,

View File

@ -190,6 +190,7 @@ namespace libtorrent
, guided_read_cache(true)
, default_cache_min_age(1)
, num_optimistic_unchoke_slots(0)
, no_atime_storage(true)
{}
// this is the user agent that will be sent to the tracker
@ -709,6 +710,10 @@ namespace libtorrent
// the global number of optimistic unchokes
// 0 means automatic
int num_optimistic_unchoke_slots;
// if set to true, files won't have their atime updated
// on disk reads. This works on linux
bool no_atime_storage;
};
#ifndef TORRENT_DISABLE_DHT

View File

@ -769,8 +769,17 @@ namespace libtorrent
static const int no_buffer_flag[] = {0, 0};
#endif
#ifdef O_NOATIME
static const int no_atime_flag[] = {0, O_NOATIME};
#endif
m_fd = ::open(convert_to_native(path).c_str()
, mode_array[mode & rw_mask] | no_buffer_flag[(mode & no_buffer) >> 2], permissions);
, mode_array[mode & rw_mask]
| no_buffer_flag[(mode & no_buffer) >> 2]
#ifdef O_NOATIME
| no_atime_flag[(mode & no_atime) >> 4]
#endif
, permissions);
#ifdef TORRENT_LINUX
// workaround for linux bug

View File

@ -1021,6 +1021,7 @@ namespace aux {
|| m_settings.allow_reordered_disk_operations != s.allow_reordered_disk_operations
|| m_settings.file_pool_size != s.file_pool_size
|| m_settings.volatile_read_cache != s.volatile_read_cache
|| m_settings.no_atime_storage!= s.no_atime_storage
|| m_settings.low_prio_disk != s.low_prio_disk)
update_disk_io_thread = true;

View File

@ -1304,6 +1304,7 @@ ret:
&& ((fe.offset + fe.file_base) & (m_page_size-1)) == 0))
mode |= file::no_buffer;
if (!m_allocate_files) mode |= file::sparse;
if (m_settings && settings().no_atime_storage) mode |= file::no_atime;
return m_pool.open_file(const_cast<storage*>(this), combine_path(m_save_path, fe.path), mode, ec);
}