Removed use of O_DIRECT because it performs bad.

pull/1/head
Tatsuhiro Tsujikawa 2011-07-16 13:57:31 +09:00
parent 5c4a52ad74
commit 5bbfa742fc
17 changed files with 4 additions and 181 deletions

View File

@ -58,8 +58,7 @@ namespace aria2 {
AbstractDiskWriter::AbstractDiskWriter(const std::string& filename)
: filename_(filename),
fd_(-1),
readOnly_(false),
directIOAllowed_(false)
readOnly_(false)
{}
AbstractDiskWriter::~AbstractDiskWriter()
@ -281,26 +280,6 @@ uint64_t AbstractDiskWriter::size()
return File(filename_).size();
}
void AbstractDiskWriter::enableDirectIO()
{
#ifdef ENABLE_DIRECT_IO
if(directIOAllowed_) {
int flg;
while((flg = fcntl(fd_, F_GETFL)) == -1 && errno == EINTR);
while(fcntl(fd_, F_SETFL, flg|O_DIRECT) == -1 && errno == EINTR);
}
#endif // ENABLE_DIRECT_IO
}
void AbstractDiskWriter::disableDirectIO()
{
#ifdef ENABLE_DIRECT_IO
int flg;
while((flg = fcntl(fd_, F_GETFL)) == -1 && errno == EINTR);
while(fcntl(fd_, F_SETFL, flg&(~O_DIRECT)) == -1 && errno == EINTR);
#endif // ENABLE_DIRECT_IO
}
void AbstractDiskWriter::enableReadOnly()
{
readOnly_ = true;

View File

@ -47,8 +47,6 @@ private:
bool readOnly_;
bool directIOAllowed_;
ssize_t writeDataInternal(const unsigned char* data, size_t len);
ssize_t readDataInternal(unsigned char* data, size_t len);
@ -76,12 +74,6 @@ public:
virtual uint64_t size();
virtual void enableDirectIO();
virtual void disableDirectIO();
virtual void allowDirectIO() { directIOAllowed_ = true; }
virtual void enableReadOnly();
virtual void disableReadOnly();

View File

@ -114,16 +114,6 @@ AbstractSingleDiskAdaptor::fileAllocationIterator()
}
}
void AbstractSingleDiskAdaptor::enableDirectIO()
{
diskWriter_->enableDirectIO();
}
void AbstractSingleDiskAdaptor::disableDirectIO()
{
diskWriter_->disableDirectIO();
}
void AbstractSingleDiskAdaptor::enableReadOnly()
{
diskWriter_->enableReadOnly();

View File

@ -73,10 +73,6 @@ public:
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
virtual void enableDirectIO();
virtual void disableDirectIO();
// Make sure that DiskWriter is set before calling this function.
virtual void enableReadOnly();

View File

@ -58,10 +58,6 @@ public:
// Allocates given length bytes of disk space from given offset. The
// default implementation does nothing.
virtual void allocate(off_t offset, uint64_t length) {}
virtual void enableDirectIO() = 0;
virtual void disableDirectIO() = 0;
};
typedef SharedHandle<BinaryStream> BinaryStreamHandle;

View File

@ -62,10 +62,6 @@ public:
virtual uint64_t size();
virtual void enableDirectIO() {}
virtual void disableDirectIO() {}
void setString(const std::string& s);
std::string getString() const;

View File

@ -94,10 +94,6 @@ void CheckIntegrityEntry::proceedFileAllocation
} else {
entry->prepareForNextAction(commands, e);
}
// Disable directIO when fallocation() is going to be used.
if(getRequestGroup()->getOption()->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
entry->disableDirectIO();
}
}
void CheckIntegrityEntry::setValidator

View File

@ -610,10 +610,6 @@ void DefaultPieceStorage::initStorage()
DiskWriterHandle writer =
diskWriterFactory_->newDiskWriter(directDiskAdaptor->getFilePath());
if(option_->getAsBool(PREF_ENABLE_DIRECT_IO)) {
writer->allowDirectIO();
}
directDiskAdaptor->setDiskWriter(writer);
diskAdaptor_ = directDiskAdaptor;
} else {
@ -621,9 +617,6 @@ void DefaultPieceStorage::initStorage()
MultiDiskAdaptorHandle multiDiskAdaptor(new MultiDiskAdaptor());
multiDiskAdaptor->setFileEntries(downloadContext_->getFileEntries().begin(),
downloadContext_->getFileEntries().end());
if(option_->getAsBool(PREF_ENABLE_DIRECT_IO)) {
multiDiskAdaptor->allowDirectIO();
}
multiDiskAdaptor->setPieceLength(downloadContext_->getPieceLength());
multiDiskAdaptor->setMaxOpenFiles
(option_->getAsInt(PREF_BT_MAX_OPEN_FILES));

View File

@ -81,10 +81,6 @@ public:
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator() = 0;
virtual void enableDirectIO() {}
virtual void disableDirectIO() {}
virtual void enableReadOnly() {}
virtual void disableReadOnly() {}

View File

@ -70,12 +70,6 @@ public:
// Returns file length
virtual uint64_t size() = 0;
virtual void enableDirectIO() = 0;
virtual void disableDirectIO() = 0;
virtual void allowDirectIO() {}
// Enables read-only mode. After this call, openExistingFile() opens
// file in read-only mode. This is an optional functionality. The
// default implementation is do nothing.

View File

@ -44,14 +44,10 @@ namespace aria2 {
FileAllocationEntry::FileAllocationEntry(RequestGroup* requestGroup, Command* nextCommand):
RequestGroupEntry(requestGroup, nextCommand),
fileAllocationIterator_(requestGroup->getPieceStorage()->getDiskAdaptor()->fileAllocationIterator())
{
getRequestGroup()->getPieceStorage()->getDiskAdaptor()->enableDirectIO();
}
{}
FileAllocationEntry:: ~FileAllocationEntry()
{
getRequestGroup()->getPieceStorage()->getDiskAdaptor()->disableDirectIO();
}
{}
off_t FileAllocationEntry::getCurrentLength()
{
@ -73,9 +69,4 @@ void FileAllocationEntry::allocateChunk()
fileAllocationIterator_->allocateChunk();
}
void FileAllocationEntry::disableDirectIO()
{
getRequestGroup()->getPieceStorage()->getDiskAdaptor()->disableDirectIO();
}
} // namespace aria2

View File

@ -64,8 +64,6 @@ public:
virtual void prepareForNextAction(std::vector<Command*>& commands,
DownloadEngine* e) = 0;
void disableDirectIO();
};
} // namespace aria2

View File

@ -61,11 +61,7 @@ IteratableChecksumValidator::IteratableChecksumValidator
IteratableChecksumValidator::~IteratableChecksumValidator()
{
#ifdef HAVE_POSIX_MEMALIGN
free(buffer_);
#else // !HAVE_POSIX_MEMALIGN
delete [] buffer_;
#endif // !HAVE_POSIX_MEMALIGN
}
void IteratableChecksumValidator::validateChunk()
@ -91,7 +87,6 @@ void IteratableChecksumValidator::validateChunk()
bool IteratableChecksumValidator::finished() const
{
if((uint64_t)currentOffset_ >= dctx_->getTotalLength()) {
pieceStorage_->getDiskAdaptor()->disableDirectIO();
return true;
} else {
return false;
@ -105,15 +100,8 @@ uint64_t IteratableChecksumValidator::getTotalLength() const
void IteratableChecksumValidator::init()
{
#ifdef HAVE_POSIX_MEMALIGN
free(buffer_);
buffer_ = reinterpret_cast<unsigned char*>
(util::allocateAlignedMemory(ALIGNMENT, BUFSIZE));
#else // !HAVE_POSIX_MEMALIGN
delete [] buffer_;
buffer_ = new unsigned char[BUFSIZE];
#endif // !HAVE_POSIX_MEMALIGN
pieceStorage_->getDiskAdaptor()->enableDirectIO();
currentOffset_ = 0;
ctx_ = MessageDigest::create(dctx_->getChecksumHashAlgo());
}

View File

@ -69,11 +69,7 @@ IteratableChunkChecksumValidator::IteratableChunkChecksumValidator
IteratableChunkChecksumValidator::~IteratableChunkChecksumValidator()
{
#ifdef HAVE_POSIX_MEMALIGN
free(buffer_);
#else // !HAVE_POSIX_MEMALIGN
delete [] buffer_;
#endif // !HAVE_POSIX_MEMALIGN
}
@ -124,17 +120,8 @@ std::string IteratableChunkChecksumValidator::calculateActualChecksum()
void IteratableChunkChecksumValidator::init()
{
#ifdef HAVE_POSIX_MEMALIGN
free(buffer_);
buffer_ = reinterpret_cast<unsigned char*>
(util::allocateAlignedMemory(ALIGNMENT, BUFSIZE));
#else // !HAVE_POSIX_MEMALIGN
delete [] buffer_;
buffer_ = new unsigned char[BUFSIZE];
#endif // !HAVE_POSIX_MEMALIGN
if(dctx_->getFileEntries().size() == 1) {
pieceStorage_->getDiskAdaptor()->enableDirectIO();
}
ctx_ = MessageDigest::create(dctx_->getPieceHashAlgo());
bitfield_->clearAllBit();
currentIndex_ = 0;
@ -176,7 +163,6 @@ std::string IteratableChunkChecksumValidator::digest(off_t offset, size_t length
bool IteratableChunkChecksumValidator::finished() const
{
if(currentIndex_ >= dctx_->getNumPieces()) {
pieceStorage_->getDiskAdaptor()->disableDirectIO();
return true;
} else {
return false;

View File

@ -56,7 +56,6 @@ namespace aria2 {
DiskWriterEntry::DiskWriterEntry(const SharedHandle<FileEntry>& fileEntry)
: fileEntry_(fileEntry),
open_(false),
directIO_(false),
needsFileAllocation_(false)
{}
@ -69,9 +68,6 @@ void DiskWriterEntry::initAndOpenFile()
{
if(diskWriter_) {
diskWriter_->initAndOpenFile(fileEntry_->getLength());
if(directIO_) {
diskWriter_->enableDirectIO();
}
open_ = true;
}
}
@ -80,9 +76,6 @@ void DiskWriterEntry::openFile()
{
if(diskWriter_) {
diskWriter_->openFile(fileEntry_->getLength());
if(directIO_) {
diskWriter_->enableDirectIO();
}
open_ = true;
}
}
@ -91,9 +84,6 @@ void DiskWriterEntry::openExistingFile()
{
if(diskWriter_) {
diskWriter_->openExistingFile(fileEntry_->getLength());
if(directIO_) {
diskWriter_->enableDirectIO();
}
open_ = true;
}
}
@ -126,26 +116,9 @@ bool DiskWriterEntry::operator<(const DiskWriterEntry& entry) const
return *fileEntry_ < *entry.fileEntry_;
}
void DiskWriterEntry::enableDirectIO()
{
if(open_) {
diskWriter_->enableDirectIO();
}
directIO_ = true;
}
void DiskWriterEntry::disableDirectIO()
{
if(open_) {
diskWriter_->disableDirectIO();
}
directIO_ = false;
}
MultiDiskAdaptor::MultiDiskAdaptor()
: pieceLength_(0),
maxOpenFiles_(DEFAULT_MAX_OPEN_FILES),
directIOAllowed_(false),
readOnly_(false)
{}
@ -253,9 +226,6 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
A2_LOG_DEBUG(fmt("Creating DiskWriter for filename=%s",
(*i)->getFilePath().c_str()));
(*i)->setDiskWriter(dwFactory.newDiskWriter((*i)->getFilePath()));
if(directIOAllowed_) {
(*i)->getDiskWriter()->allowDirectIO();
}
if(readOnly_) {
(*i)->getDiskWriter()->enableReadOnly();
}
@ -474,18 +444,6 @@ SharedHandle<FileAllocationIterator> MultiDiskAdaptor::fileAllocationIterator()
(new MultiFileAllocationIterator(this));
}
void MultiDiskAdaptor::enableDirectIO()
{
std::for_each(diskWriterEntries_.begin(), diskWriterEntries_.end(),
mem_fun_sh(&DiskWriterEntry::enableDirectIO));
}
void MultiDiskAdaptor::disableDirectIO()
{
std::for_each(diskWriterEntries_.begin(), diskWriterEntries_.end(),
mem_fun_sh(&DiskWriterEntry::disableDirectIO));
}
void MultiDiskAdaptor::enableReadOnly()
{
readOnly_ = true;

View File

@ -48,7 +48,6 @@ private:
SharedHandle<FileEntry> fileEntry_;
SharedHandle<DiskWriter> diskWriter_;
bool open_;
bool directIO_;
bool needsFileAllocation_;
public:
DiskWriterEntry(const SharedHandle<FileEntry>& fileEntry);
@ -86,16 +85,6 @@ public:
bool operator<(const DiskWriterEntry& entry) const;
// Set directIO_ to true.
// Additionally, if diskWriter is opened, diskWriter->enableDirectIO() is
// called.
void enableDirectIO();
// Set directIO_ to false.
// Additionally, if diskWriter is opened, diskWriter->disableDirectIO() is
// called.
void disableDirectIO();
bool needsFileAllocation() const
{
return needsFileAllocation_;
@ -122,8 +111,6 @@ private:
size_t maxOpenFiles_;
bool directIOAllowed_;
bool readOnly_;
void resetDiskWriterEntries();
@ -156,10 +143,6 @@ public:
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
virtual void enableDirectIO();
virtual void disableDirectIO();
virtual void enableReadOnly();
virtual void disableReadOnly();
@ -175,11 +158,6 @@ public:
return pieceLength_;
}
void allowDirectIO()
{
directIOAllowed_ = true;
}
virtual void cutTrailingGarbage();
void setMaxOpenFiles(size_t maxOpenFiles);

View File

@ -56,11 +56,7 @@ SingleFileAllocationIterator::SingleFileAllocationIterator
offset_(offset),
totalLength_(totalLength),
buffer_(0)
{
if(offset_%ALIGNMENT != 0) {
stream_->disableDirectIO();
}
}
{}
SingleFileAllocationIterator::~SingleFileAllocationIterator()
{