Ticket #9458: 100-posix_fadvise_fixes_v2.patch
File 100-posix_fadvise_fixes_v2.patch, 6.4 KB (added by , 13 years ago) |
---|
-
libs/libmythtv/fileringbuffer.cpp
diff -u -r -p mythtv.old/libs/libmythtv/fileringbuffer.cpp mythtv/libs/libmythtv/fileringbuffer.cpp
old new FileRingBuffer::~FileRingBuffer() 100 100 101 101 if (fd2 >= 0) 102 102 { 103 posix_fadvise(fd2, 0, 0, POSIX_FADV_DONTNEED); 103 104 close(fd2); 104 105 fd2 = -1; 105 106 } … … bool FileRingBuffer::OpenFile(const QStr 252 253 { 253 254 if (0 == lseek(fd2, 0, SEEK_SET)) 254 255 { 255 posix_fadvise(fd2, 0, 0, POSIX_FADV_SEQUENTIAL); 256 posix_fadvise(fd2, 0, 1*1024*1024, POSIX_FADV_WILLNEED); 256 posix_fadvise(fd2, 0, 0, POSIX_FADV_SEQUENTIAL); 257 257 lasterror = 0; 258 258 break; 259 259 } … … long long FileRingBuffer::Seek(long long 601 601 else 602 602 { 603 603 ret = lseek64(fd2, internalreadpos, SEEK_SET); 604 posix_fadvise(fd2, 0,605 internalreadpos, POSIX_FADV_DONTNEED);606 posix_fadvise(fd2, internalreadpos,607 1*1024*1024, POSIX_FADV_WILLNEED);608 604 } 609 605 VERBOSE(VB_FILE, LOC + 610 606 QString("Seek to %1 from ignore pos %2 returned %3") … … long long FileRingBuffer::Seek(long long 687 683 else 688 684 { 689 685 ret = lseek64(fd2, ignorereadpos, SEEK_SET); 690 posix_fadvise(fd2, ignorereadpos, 250000, POSIX_FADV_WILLNEED);691 686 } 692 687 693 688 if (ret < 0) … … long long FileRingBuffer::Seek(long long 752 747 else 753 748 { 754 749 ret = lseek64(fd2, pos, whence); 755 if (ret >= 0)756 {757 posix_fadvise(fd2, 0, ret, POSIX_FADV_DONTNEED);758 posix_fadvise(fd2, ret, 1*1024*1024, POSIX_FADV_WILLNEED);759 }760 750 } 761 751 762 752 if (ret >= 0) 763 753 { 764 754 readpos = ret; 765 755 766 756 ignorereadpos = -1; 767 757 768 758 if (readaheadrunning) -
libs/libmythtv/ringbuffer.cpp
diff -u -r -p mythtv.old/libs/libmythtv/ringbuffer.cpp mythtv/libs/libmythtv/ringbuffer.cpp
old new void RingBuffer::run(void) 784 784 poslock.lockForWrite(); 785 785 rbwlock.lockForWrite(); 786 786 internalreadpos += read_return; 787 off_t donotneed = internalreadpos;788 787 rbwpos = (rbwpos + read_return) % kBufferSize; 789 788 VERBOSE(VB_FILE|VB_EXTRA, 790 789 LOC + QString("rbwpos += %1K requested %2K in read") … … void RingBuffer::run(void) 792 791 rbwlock.unlock(); 793 792 poslock.unlock(); 794 793 795 if (fd2 >=0 && donotneed > 0) 796 posix_fadvise(fd2, 0, donotneed, POSIX_FADV_DONTNEED); 794 if (fd2 >=0 && read_return > 0) 795 { 796 posix_fadvise(fd2, (lseek(fd2, 0, SEEK_CUR) - read_return), 797 read_return, POSIX_FADV_DONTNEED); 798 } 797 799 } 798 800 799 801 int used = kBufferSize - ReadBufFree(); … … int RingBuffer::ReadDirect(void *buf, in 1017 1019 else 1018 1020 { 1019 1021 lseek64(fd2, old_pos, SEEK_SET); 1020 posix_fadvise(fd2, old_pos, 1*1024*1024, POSIX_FADV_WILLNEED);1021 1022 } 1022 1023 } 1023 1024 else … … int RingBuffer::ReadPriv(void *buf, int 1106 1107 VERBOSE(VB_FILE|VB_EXTRA, LOC + loc_desc + 1107 1108 QString(": ReadDirect checksum %1") 1108 1109 .arg(qChecksum((char*)buf,count))); 1110 1111 if (fd2 >=0 && ret > 0) 1112 { 1113 posix_fadvise(fd2, (lseek(fd2, 0, SEEK_CUR) - ret), 1114 ret, POSIX_FADV_DONTNEED); 1115 } 1116 1109 1117 rwlock.unlock(); 1110 1118 return ret; 1111 1119 } -
libs/libmythtv/ThreadedFileWriter.cpp
diff -u -r -p mythtv.old/libs/libmythtv/ThreadedFileWriter.cpp mythtv/libs/libmythtv/ThreadedFileWriter.cpp
old new ThreadedFileWriter::~ThreadedFileWriter( 217 217 Flush(); 218 218 in_dtor = true; /* tells child thread to exit */ 219 219 220 bufferHasData.wakeAll(); 221 pthread_join(writer, NULL); 222 220 223 bufferSyncWait.wakeAll(); 221 224 pthread_join(syncer, NULL); 222 225 223 bufferHasData.wakeAll();224 pthread_join(writer, NULL);225 226 close(fd); 226 227 fd = -1; 227 228 } … … void ThreadedFileWriter::Sync(void) 385 386 { 386 387 if (fd >= 0) 387 388 { 388 /// Toss any data the kernel wrote to disk on it's own from389 /// the cache, so we don't get penalized for preserving it390 /// during the sync.391 (void) posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);392 393 389 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 394 390 // fdatasync tries to avoid updating metadata, but will in 395 391 // practice always update metadata if any data is written … … void ThreadedFileWriter::Sync(void) 398 394 #else 399 395 fsync(fd); 400 396 #endif 397 buflock.lock(); 398 off_t write_position = m_file_wpos; 399 buflock.unlock(); 401 400 402 // Toss any data we just synced from cache, so we don't 403 // get penalized for it between now and the next sync. 404 (void) posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED); 401 const int may_need = (5 * 4 * 1024 *1024); 402 if (in_dtor) 403 { 404 // invalidate remaining portion of the pagecache 405 posix_fadvise(fd, m_file_sync, 406 write_position - m_file_sync, 407 POSIX_FADV_DONTNEED); 408 } 409 else if (write_position > may_need) 410 { 411 // leave portion of the file in pagecache because livetv 412 // playback may need it very soon. This will reduce disk 413 // io during livetv playback and decrease time required 414 // to open next file when player switching/jumping 415 // to next program. The size of may_need has been choosed 416 // as 5 seconds of 35mbit playback. 417 posix_fadvise(fd, m_file_sync, 418 write_position - may_need - m_file_sync, 419 POSIX_FADV_DONTNEED); 420 m_file_sync = write_position - may_need; 421 } 405 422 } 406 423 } 407 424