remove unused O_DIRECT mode, and relax/simplify alignment requirements for coalesce_buffers
This commit is contained in:
parent
e9b334ce63
commit
139fb29647
|
@ -271,10 +271,6 @@ namespace libtorrent
|
||||||
// leaving running applications in the page cache
|
// leaving running applications in the page cache
|
||||||
no_cache = 0x40,
|
no_cache = 0x40,
|
||||||
|
|
||||||
// this corresponds to Linux' O_DIRECT flag
|
|
||||||
// and may impose alignment restrictions
|
|
||||||
direct_io = 0x80,
|
|
||||||
|
|
||||||
// this is only used for readv/writev flags
|
// this is only used for readv/writev flags
|
||||||
coalesce_buffers = 0x100,
|
coalesce_buffers = 0x100,
|
||||||
|
|
||||||
|
|
35
src/file.cpp
35
src/file.cpp
|
@ -1408,7 +1408,6 @@ namespace libtorrent
|
||||||
DWORD flags = ((mode & random_access) ? 0 : FILE_FLAG_SEQUENTIAL_SCAN)
|
DWORD flags = ((mode & random_access) ? 0 : FILE_FLAG_SEQUENTIAL_SCAN)
|
||||||
| (a ? a : FILE_ATTRIBUTE_NORMAL)
|
| (a ? a : FILE_ATTRIBUTE_NORMAL)
|
||||||
| FILE_FLAG_OVERLAPPED
|
| FILE_FLAG_OVERLAPPED
|
||||||
| ((mode & direct_io) ? FILE_FLAG_NO_BUFFERING : 0)
|
|
||||||
| ((mode & no_cache) ? FILE_FLAG_WRITE_THROUGH : 0);
|
| ((mode & no_cache) ? FILE_FLAG_WRITE_THROUGH : 0);
|
||||||
|
|
||||||
handle_type handle = CreateFile_(file_path.c_str(), m.rw_mode
|
handle_type handle = CreateFile_(file_path.c_str(), m.rw_mode
|
||||||
|
@ -1456,16 +1455,13 @@ namespace libtorrent
|
||||||
#ifdef O_NOATIME
|
#ifdef O_NOATIME
|
||||||
| ((mode & no_atime) ? O_NOATIME : 0)
|
| ((mode & no_atime) ? O_NOATIME : 0)
|
||||||
#endif
|
#endif
|
||||||
#ifdef O_DIRECT
|
|
||||||
| ((mode & direct_io) ? O_DIRECT : 0)
|
|
||||||
#endif
|
|
||||||
#ifdef O_SYNC
|
#ifdef O_SYNC
|
||||||
| ((mode & no_cache) ? O_SYNC: 0)
|
| ((mode & no_cache) ? O_SYNC: 0)
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
handle_type handle = ::open(convert_to_native(path).c_str()
|
handle_type handle = ::open(convert_to_native(path).c_str()
|
||||||
, mode_array[mode & rw_mask] | open_mode
|
, mode_array[mode & rw_mask] | open_mode
|
||||||
, permissions);
|
, permissions);
|
||||||
|
|
||||||
#ifdef O_NOATIME
|
#ifdef O_NOATIME
|
||||||
|
@ -1668,12 +1664,11 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TORRENT_USE_PREADV
|
#if !TORRENT_USE_PREADV
|
||||||
bool coalesce_read_buffers(file::iovec_t const*& bufs, int& num_bufs, file::iovec_t* tmp)
|
bool coalesce_read_buffers(file::iovec_t const*& bufs, int& num_bufs
|
||||||
|
, file::iovec_t* tmp)
|
||||||
{
|
{
|
||||||
int buf_size = bufs_size(bufs, num_bufs);
|
int const buf_size = bufs_size(bufs, num_bufs);
|
||||||
// this is page aligned since it's used in APIs which
|
char* buf = static_cast<char*>(malloc(buf_size));
|
||||||
// are likely to require that (depending on OS)
|
|
||||||
char* buf = static_cast<char*>(page_aligned_allocator::malloc(buf_size));
|
|
||||||
if (!buf) return false;
|
if (!buf) return false;
|
||||||
tmp->iov_base = buf;
|
tmp->iov_base = buf;
|
||||||
tmp->iov_len = buf_size;
|
tmp->iov_len = buf_size;
|
||||||
|
@ -1682,20 +1677,18 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void coalesce_read_buffers_end(file::iovec_t const* bufs, int num_bufs, char* buf, bool copy)
|
void coalesce_read_buffers_end(file::iovec_t const* bufs, int const num_bufs
|
||||||
|
, char* const buf, bool const copy)
|
||||||
{
|
{
|
||||||
if (copy) scatter_copy(bufs, num_bufs, buf);
|
if (copy) scatter_copy(bufs, num_bufs, buf);
|
||||||
page_aligned_allocator::free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool coalesce_write_buffers(file::iovec_t const*& bufs, int& num_bufs, file::iovec_t* tmp)
|
bool coalesce_write_buffers(file::iovec_t const*& bufs, int& num_bufs
|
||||||
|
, file::iovec_t* tmp)
|
||||||
{
|
{
|
||||||
// coalesce buffers means allocate a temporary buffer and
|
int const buf_size = bufs_size(bufs, num_bufs);
|
||||||
// issue a single write operation instead of using a vector
|
char* buf = static_cast<char*>(malloc(buf_size));
|
||||||
// operation
|
|
||||||
int buf_size = 0;
|
|
||||||
for (int i = 0; i < num_bufs; ++i) buf_size += bufs[i].iov_len;
|
|
||||||
char* buf = static_cast<char*>(page_aligned_allocator::malloc(buf_size));
|
|
||||||
if (!buf) return false;
|
if (!buf) return false;
|
||||||
gather_copy(bufs, num_bufs, buf);
|
gather_copy(bufs, num_bufs, buf);
|
||||||
tmp->iov_base = buf;
|
tmp->iov_base = buf;
|
||||||
|
@ -2243,7 +2236,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
||||||
|
|
||||||
// return the offset to the next allocated region
|
// return the offset to the next allocated region
|
||||||
return buffer.FileOffset.QuadPart;
|
return buffer.FileOffset.QuadPart;
|
||||||
|
|
||||||
#elif defined SEEK_DATA
|
#elif defined SEEK_DATA
|
||||||
// this is supported on solaris
|
// this is supported on solaris
|
||||||
boost::int64_t ret = lseek(native_handle(), start, SEEK_DATA);
|
boost::int64_t ret = lseek(native_handle(), start, SEEK_DATA);
|
||||||
|
|
Loading…
Reference in New Issue