Ticket #9458: 101-posix_fadvise_fixes.patch

File 101-posix_fadvise_fixes.patch, 5.6 KB (added by jiri.fojtasek@…, 9 years ago)

the patch

  • libs/libmythtv/fileringbuffer.cpp

    diff -u -r -p mythtv.100/libs/libmythtv/fileringbuffer.cpp mythtv/libs/libmythtv/fileringbuffer.cpp
    old new FileRingBuffer::~FileRingBuffer() 
    100100
    101101    if (fd2 >= 0)
    102102    {
     103        posix_fadvise(fd2, 0, 0, POSIX_FADV_DONTNEED);
    103104        close(fd2);
    104105        fd2 = -1;
    105106    }
    bool FileRingBuffer::OpenFile(const QStr 
    252253                {
    253254                    if (0 == lseek(fd2, 0, SEEK_SET))
    254255                    {
    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);
    257257                        lasterror = 0;
    258258                        break;
    259259                    }
    long long FileRingBuffer::Seek(long long 
    601601                else
    602602                {
    603603                    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);
    608604                }
    609605                VERBOSE(VB_FILE, LOC +
    610606                        QString("Seek to %1 from ignore pos %2 returned %3")
    long long FileRingBuffer::Seek(long long 
    687683            else
    688684            {
    689685                ret = lseek64(fd2, ignorereadpos, SEEK_SET);
    690                 posix_fadvise(fd2, ignorereadpos, 250000, POSIX_FADV_WILLNEED);
    691686            }
    692687
    693688            if (ret < 0)
    long long FileRingBuffer::Seek(long long 
    752747    else
    753748    {
    754749        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         }
    760750    }
    761751
    762752    if (ret >= 0)
    763753    {
    764754        readpos = ret;
    765        
     755
    766756        ignorereadpos = -1;
    767757
    768758        if (readaheadrunning)
  • libs/libmythtv/ringbuffer.cpp

    diff -u -r -p mythtv.100/libs/libmythtv/ringbuffer.cpp mythtv/libs/libmythtv/ringbuffer.cpp
    old new void RingBuffer::run(void) 
    783783        {
    784784            poslock.lockForWrite();
    785785            rbwlock.lockForWrite();
     786            off_t read_position = internalreadpos;
    786787            internalreadpos += read_return;
    787             off_t donotneed = internalreadpos;
    788788            rbwpos = (rbwpos + read_return) % kBufferSize;
    789789            VERBOSE(VB_FILE|VB_EXTRA,
    790790                    LOC + QString("rbwpos += %1K requested %2K in read")
    void RingBuffer::run(void) 
    792792            rbwlock.unlock();
    793793            poslock.unlock();
    794794
    795             if (fd2 >=0 && donotneed > 0)
    796                 posix_fadvise(fd2, 0, donotneed, POSIX_FADV_DONTNEED);
     795            if (fd2 >=0)
     796            {
     797                posix_fadvise(fd2, read_position, read_return, POSIX_FADV_DONTNEED);
     798            }
    797799        }
    798800
    799801        int used = kBufferSize - ReadBufFree();
    int RingBuffer::ReadDirect(void *buf, in 
    10171019            else
    10181020            {
    10191021                lseek64(fd2, old_pos, SEEK_SET);
    1020                 posix_fadvise(fd2, old_pos, 1*1024*1024, POSIX_FADV_WILLNEED);
    10211022            }
    10221023        }
    10231024        else
    int RingBuffer::ReadPriv(void *buf, int  
    11061107            VERBOSE(VB_FILE|VB_EXTRA, LOC + loc_desc +
    11071108                    QString(": ReadDirect checksum %1")
    11081109                    .arg(qChecksum((char*)buf,count)));
     1110
     1111            if (fd2 >=0 && ret > 0)
     1112            {
     1113                posix_fadvise(fd2, rbrpos, ret, POSIX_FADV_DONTNEED);
     1114            }
     1115
    11091116            rwlock.unlock();
    11101117            return ret;
    11111118        }
  • libs/libmythtv/ThreadedFileWriter.cpp

    diff -u -r -p mythtv.100/libs/libmythtv/ThreadedFileWriter.cpp mythtv/libs/libmythtv/ThreadedFileWriter.cpp
    old new ThreadedFileWriter::~ThreadedFileWriter( 
    217217        Flush();
    218218        in_dtor = true; /* tells child thread to exit */
    219219
     220        bufferHasData.wakeAll();
     221        pthread_join(writer, NULL);
     222
    220223        bufferSyncWait.wakeAll();
    221224        pthread_join(syncer, NULL);
    222225
    223         bufferHasData.wakeAll();
    224         pthread_join(writer, NULL);
    225226        close(fd);
    226227        fd = -1;
    227228    }
    void ThreadedFileWriter::Sync(void) 
    385386{
    386387    if (fd >= 0)
    387388    {
    388         /// Toss any data the kernel wrote to disk on it's own from
    389         /// the cache, so we don't get penalized for preserving it
    390         /// during the sync.
    391         (void) posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
    392 
    393389#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
    394390        // fdatasync tries to avoid updating metadata, but will in
    395391        // practice always update metadata if any data is written
    void ThreadedFileWriter::Sync(void) 
    398394#else
    399395        fsync(fd);
    400396#endif
     397        // Toss writen data from the page cache
     398        buflock.lock();
     399        off_t write_position = m_file_wpos;
     400        buflock.unlock();
    401401
    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);
     402        posix_fadvise(fd, m_file_sync, write_position - m_file_sync,
     403                        POSIX_FADV_DONTNEED);
     404        m_file_sync = write_position;
    405405    }
    406406}
    407407