diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-07-16 13:57:31 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-07-16 13:57:31 +0900 |
| commit | 5bbfa742fcd43011c04fd053703d7c8835283d01 (patch) | |
| tree | 734b73502ea2b126e108c0bc9703e40a2f22ba4f | |
| parent | 5c4a52ad741c66b4aa263a542da2c1e5546ca6bf (diff) | |
Removed use of O_DIRECT because it performs bad.
| -rw-r--r-- | src/AbstractDiskWriter.cc | 23 | ||||
| -rw-r--r-- | src/AbstractDiskWriter.h | 8 | ||||
| -rw-r--r-- | src/AbstractSingleDiskAdaptor.cc | 10 | ||||
| -rw-r--r-- | src/AbstractSingleDiskAdaptor.h | 4 | ||||
| -rw-r--r-- | src/BinaryStream.h | 4 | ||||
| -rw-r--r-- | src/ByteArrayDiskWriter.h | 4 | ||||
| -rw-r--r-- | src/CheckIntegrityEntry.cc | 4 | ||||
| -rw-r--r-- | src/DefaultPieceStorage.cc | 7 | ||||
| -rw-r--r-- | src/DiskAdaptor.h | 4 | ||||
| -rw-r--r-- | src/DiskWriter.h | 6 | ||||
| -rw-r--r-- | src/FileAllocationEntry.cc | 13 | ||||
| -rw-r--r-- | src/FileAllocationEntry.h | 2 | ||||
| -rw-r--r-- | src/IteratableChecksumValidator.cc | 12 | ||||
| -rw-r--r-- | src/IteratableChunkChecksumValidator.cc | 14 | ||||
| -rw-r--r-- | src/MultiDiskAdaptor.cc | 42 | ||||
| -rw-r--r-- | src/MultiDiskAdaptor.h | 22 | ||||
| -rw-r--r-- | src/SingleFileAllocationIterator.cc | 6 |
17 files changed, 4 insertions, 181 deletions
diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index b1c54f3b..ae5c1b5a 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -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; diff --git a/src/AbstractDiskWriter.h b/src/AbstractDiskWriter.h index aa9de332..297c3b26 100644 --- a/src/AbstractDiskWriter.h +++ b/src/AbstractDiskWriter.h @@ -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(); diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc index 42448eae..ddf59059 100644 --- a/src/AbstractSingleDiskAdaptor.cc +++ b/src/AbstractSingleDiskAdaptor.cc @@ -114,16 +114,6 @@ AbstractSingleDiskAdaptor::fileAllocationIterator() } } -void AbstractSingleDiskAdaptor::enableDirectIO() -{ - diskWriter_->enableDirectIO(); -} - -void AbstractSingleDiskAdaptor::disableDirectIO() -{ - diskWriter_->disableDirectIO(); -} - void AbstractSingleDiskAdaptor::enableReadOnly() { diskWriter_->enableReadOnly(); diff --git a/src/AbstractSingleDiskAdaptor.h b/src/AbstractSingleDiskAdaptor.h index f967d3dc..47563d95 100644 --- a/src/AbstractSingleDiskAdaptor.h +++ b/src/AbstractSingleDiskAdaptor.h @@ -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(); diff --git a/src/BinaryStream.h b/src/BinaryStream.h index eee00d3e..4dee179b 100644 --- a/src/BinaryStream.h +++ b/src/BinaryStream.h @@ -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; diff --git a/src/ByteArrayDiskWriter.h b/src/ByteArrayDiskWriter.h index cba19b08..fee6ddfb 100644 --- a/src/ByteArrayDiskWriter.h +++ b/src/ByteArrayDiskWriter.h @@ -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; diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc index b07f5dac..eda0b2ab 100644 --- a/src/CheckIntegrityEntry.cc +++ b/src/CheckIntegrityEntry.cc @@ -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 diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 4f331d13..88d28d4b 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -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)); diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h index 91bc13b0..d7c06b90 100644 --- a/src/DiskAdaptor.h +++ b/src/DiskAdaptor.h @@ -81,10 +81,6 @@ public: virtual SharedHandle<FileAllocationIterator> fileAllocationIterator() = 0; - virtual void enableDirectIO() {} - - virtual void disableDirectIO() {} - virtual void enableReadOnly() {} virtual void disableReadOnly() {} diff --git a/src/DiskWriter.h b/src/DiskWriter.h index 20729f25..427380d4 100644 --- a/src/DiskWriter.h +++ b/src/DiskWriter.h @@ -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. diff --git a/src/FileAllocationEntry.cc b/src/FileAllocationEntry.cc index 2d873e4b..2d96f756 100644 --- a/src/FileAllocationEntry.cc +++ b/src/FileAllocationEntry.cc @@ -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 diff --git a/src/FileAllocationEntry.h b/src/FileAllocationEntry.h index ed564a3f..509a8a04 100644 --- a/src/FileAllocationEntry.h +++ b/src/FileAllocationEntry.h @@ -64,8 +64,6 @@ public: virtual void prepareForNextAction(std::vector<Command*>& commands, DownloadEngine* e) = 0; - - void disableDirectIO(); }; } // namespace aria2 diff --git a/src/IteratableChecksumValidator.cc b/src/IteratableChecksumValidator.cc index 26f75db7..7437683a 100644 --- a/src/IteratableChecksumValidator.cc +++ b/src/IteratableChecksumValidator.cc @@ -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()); } diff --git a/src/IteratableChunkChecksumValidator.cc b/src/IteratableChunkChecksumValidator.cc index acb4a08c..1382f37a 100644 --- a/src/IteratableChunkChecksumValidator.cc +++ b/src/IteratableChunkChecksumValidator.cc @@ -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; diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index 0c37c0df..f3672836 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -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; diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h index 901f72c0..4eecaae0 100644 --- a/src/MultiDiskAdaptor.h +++ b/src/MultiDiskAdaptor.h @@ -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); diff --git a/src/SingleFileAllocationIterator.cc b/src/SingleFileAllocationIterator.cc index 420ff699..a12df5db 100644 --- a/src/SingleFileAllocationIterator.cc +++ b/src/SingleFileAllocationIterator.cc @@ -56,11 +56,7 @@ SingleFileAllocationIterator::SingleFileAllocationIterator offset_(offset), totalLength_(totalLength), buffer_(0) -{ - if(offset_%ALIGNMENT != 0) { - stream_->disableDirectIO(); - } -} +{} SingleFileAllocationIterator::~SingleFileAllocationIterator() { |
