瀏覽代碼

2007-12-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Changed Direct/IO enable/disable procesure in file allocation routine.
	* src/SingleFileAllocationIterator.cc
	(SingleFileAllocationIterator):
	Disable directIO if offset is not multiple of 512.
	(~SingleFileAllocationIterator): Removed a call to disableDirectIO.
	* src/MultiFileAllocationIterator.cc (allocateChunk):
	Enable created SingleFileAllocationIterator's directIO.
	* src/FileAllocationEntry.cc
	(FileAllocationEntry): Enable directIO here.
	(~FileAllocationEntry): Disable directIO here.
Tatsuhiro Tsujikawa 18 年之前
父節點
當前提交
68579bd2f4
共有 4 個文件被更改,包括 24 次插入6 次删除
  1. 13 0
      ChangeLog
  2. 6 2
      src/FileAllocationEntry.cc
  3. 1 0
      src/MultiFileAllocationIterator.cc
  4. 4 4
      src/SingleFileAllocationIterator.cc

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2007-12-06  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Changed Direct/IO enable/disable procesure in file allocation routine.
+	* src/SingleFileAllocationIterator.cc
+	(SingleFileAllocationIterator):
+	Disable directIO if offset is not multiple of 512.
+	(~SingleFileAllocationIterator): Removed a call to disableDirectIO.
+	* src/MultiFileAllocationIterator.cc (allocateChunk):
+	Enable created SingleFileAllocationIterator's directIO.
+	* src/FileAllocationEntry.cc
+	(FileAllocationEntry): Enable directIO here.
+	(~FileAllocationEntry): Disable directIO here.
+
 2007-12-06  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Fixed the bug: aria2 doesn't utilize fast set index offered by peer.

+ 6 - 2
src/FileAllocationEntry.cc

@@ -42,10 +42,14 @@
 FileAllocationEntry::FileAllocationEntry(RequestGroup* requestGroup, Command* nextCommand):
   RequestGroupEntry(requestGroup, nextCommand),
   _fileAllocationIterator(requestGroup->getPieceStorage()->getDiskAdaptor()->fileAllocationIterator())
-{}
+{
+  _requestGroup->getPieceStorage()->getDiskAdaptor()->enableDirectIO();
+}
 
 FileAllocationEntry:: ~FileAllocationEntry()
-{}
+{
+  _requestGroup->getPieceStorage()->getDiskAdaptor()->disableDirectIO();
+}
 
 int64_t FileAllocationEntry::getCurrentLength()
 {

+ 1 - 0
src/MultiFileAllocationIterator.cc

@@ -57,6 +57,7 @@ void MultiFileAllocationIterator::allocateChunk()
     _entries.pop_front();
     FileEntryHandle fileEntry = entry->getFileEntry();
     if(entry->size() < fileEntry->getLength()) {
+      entry->getDiskWriter()->enableDirectIO();
       _fileAllocationIterator =
 	new SingleFileAllocationIterator(entry->getDiskWriter().get(),
 					 entry->size(),

+ 4 - 4
src/SingleFileAllocationIterator.cc

@@ -38,24 +38,24 @@
 #include "a2io.h"
 
 #define BUFSIZE (256*1024)
+#define ALIGNMENT 512
 
 SingleFileAllocationIterator::SingleFileAllocationIterator(BinaryStream* stream, int64_t offset, int64_t totalLength):_stream(stream), _offset(offset), _totalLength(totalLength), _buffer(0)
 {
-  if(_offset%512 == 0) {
-    _stream->enableDirectIO();
+  if(_offset%ALIGNMENT != 0) {
+    _stream->disableDirectIO();
   }
 }
 
 SingleFileAllocationIterator::~SingleFileAllocationIterator()
 {
   delete [] _buffer;
-  _stream->disableDirectIO();
 }
 
 void SingleFileAllocationIterator::init()
 {
 #ifdef HAVE_POSIX_MEMALIGN
-  _buffer = (unsigned char*)Util::allocateAlignedMemory(512, BUFSIZE);
+  _buffer = (unsigned char*)Util::allocateAlignedMemory(ALIGNMENT, BUFSIZE);
 #else
   _buffer = new unsigned char[BUFSIZE];
 #endif // HAVE_POSIX_MEMALIGN