Skip to content

Commit

Permalink
Some fadvise changes.
Browse files Browse the repository at this point in the history
First this gets rid of DONTNEED advice. These calls a global, so in order for these to be safe in the MythTV context we'd need to make sure that no other process is currently accessing the file. This is complicated on 64 bit platforms where you can memory map the whole file and extreemely complicated on 32 bit platforms.. Instead lets leave this task to the OS.

Second we change some of the WILLNEED calls. On Linux these are unfortunately implemented as blocking calls; that is they block until the requested number of bytes have been read, instead of just telling the OS to start reading in those bytes in a kernel thread. Consequently, this drops the calls in some cases and reduces the number of bytes to read in other cases.
  • Loading branch information
daniel-kristjansson committed May 3, 2011
1 parent 5c30939 commit e4c5909
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 35 deletions.
9 changes: 0 additions & 9 deletions mythtv/libs/libmythtv/ThreadedFileWriter.cpp
Expand Up @@ -19,15 +19,6 @@
#include "ThreadedFileWriter.h"
#include "compat.h"
#include "mythverbose.h"
#include "mythconfig.h" // gives us HAVE_POSIX_FADVISE

#if HAVE_POSIX_FADVISE < 1
static int posix_fadvise(int, off_t, off_t, int) { return 0; }
#define POSIX_FADV_DONTNEED 0
# if defined(__linux__)
# warning "Not using fadvise on platform that supports it."
# endif
#endif

#define LOC QString("TFW(%1): ").arg(fd)
#define LOC_ERR QString("TFW(%1), Error: ").arg(fd)
Expand Down
17 changes: 4 additions & 13 deletions mythtv/libs/libmythtv/fileringbuffer.cpp
Expand Up @@ -14,6 +14,7 @@
#include "fileringbuffer.h"
#include "mythcontext.h"
#include "remotefile.h"
#include "mythconfig.h" // gives us HAVE_POSIX_FADVISE
#include "compat.h"
#include "util.h"

Expand Down Expand Up @@ -252,8 +253,8 @@ bool FileRingBuffer::OpenFile(const QString &lfilename, uint retry_ms)
{
if (0 == lseek(fd2, 0, SEEK_SET))
{
posix_fadvise(fd2, 0, 0, POSIX_FADV_SEQUENTIAL);
posix_fadvise(fd2, 0, 1*1024*1024, POSIX_FADV_WILLNEED);
posix_fadvise(fd2, 0, 0, POSIX_FADV_SEQUENTIAL);
posix_fadvise(fd2, 0, 128*1024, POSIX_FADV_WILLNEED);
lasterror = 0;
break;
}
Expand Down Expand Up @@ -601,10 +602,8 @@ long long FileRingBuffer::Seek(long long pos, int whence, bool has_lock)
else
{
ret = lseek64(fd2, internalreadpos, SEEK_SET);
posix_fadvise(fd2, 0,
internalreadpos, POSIX_FADV_DONTNEED);
posix_fadvise(fd2, internalreadpos,
1*1024*1024, POSIX_FADV_WILLNEED);
128*1024, POSIX_FADV_WILLNEED);
}
VERBOSE(VB_FILE, LOC +
QString("Seek to %1 from ignore pos %2 returned %3")
Expand Down Expand Up @@ -685,10 +684,7 @@ long long FileRingBuffer::Seek(long long pos, int whence, bool has_lock)
if (remotefile)
ret = remotefile->Seek(ignorereadpos, SEEK_SET);
else
{
ret = lseek64(fd2, ignorereadpos, SEEK_SET);
posix_fadvise(fd2, ignorereadpos, 250000, POSIX_FADV_WILLNEED);
}

if (ret < 0)
{
Expand Down Expand Up @@ -752,11 +748,6 @@ long long FileRingBuffer::Seek(long long pos, int whence, bool has_lock)
else
{
ret = lseek64(fd2, pos, whence);
if (ret >= 0)
{
posix_fadvise(fd2, 0, ret, POSIX_FADV_DONTNEED);
posix_fadvise(fd2, ret, 1*1024*1024, POSIX_FADV_WILLNEED);
}
}

if (ret >= 0)
Expand Down
13 changes: 0 additions & 13 deletions mythtv/libs/libmythtv/ringbuffer.cpp
Expand Up @@ -27,13 +27,6 @@
#include "compat.h"
#include "util.h"

#if ! HAVE_POSIX_FADVISE
static int posix_fadvise(int, off_t, off_t, int) { return 0; }
#define POSIX_FADV_SEQUENTIAL 0
#define POSIX_FADV_WILLNEED 0
#define POSIX_FADV_DONTNEED 0
#endif

// about one second at 35mbit
const uint RingBuffer::kBufferSize = 4 * 1024 * 1024;
const int RingBuffer::kDefaultOpenTimeout = 2000; // ms
Expand Down Expand Up @@ -800,9 +793,6 @@ void RingBuffer::run(void)
.arg(read_return/1024,3).arg(totfree/1024,3));
rbwlock.unlock();
poslock.unlock();

if (fd2 >=0 && donotneed > 0)
posix_fadvise(fd2, 0, donotneed, POSIX_FADV_DONTNEED);
}

int used = kBufferSize - ReadBufFree();
Expand Down Expand Up @@ -1017,10 +1007,7 @@ int RingBuffer::ReadDirect(void *buf, int count, bool peek)
if (remotefile)
remotefile->Seek(old_pos, SEEK_SET);
else
{
lseek64(fd2, old_pos, SEEK_SET);
posix_fadvise(fd2, old_pos, 1*1024*1024, POSIX_FADV_WILLNEED);
}
}
else
{
Expand Down

0 comments on commit e4c5909

Please sign in to comment.