[MPlayer-dev-eng] [PATCH] Use posix_fadvise in stream_file if available

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sat Nov 7 20:06:17 CET 2009


On Sat, Nov 07, 2009 at 07:37:30PM +0100, Tobias Diedrich wrote:
>  static int fill_buffer(stream_t *s, char* buffer, int max_len){
> +  struct stream_priv_s *p = s->priv;
>    int r = read(s->fd,buffer,max_len);
> +  if (s->pos > p->prefetch_last_pos + PREFETCH_LEN/2) {
> +    p->prefetch_last_pos = s->pos;
> +    fadvise(s->fd, s->pos, PREFETCH_LEN, POSIX_FADV_WILLNEED);
> +  }

Also I don't think this is supposed to be s->pos, like this you'll
advise the kernel to read ahead the data it just read while almost
certainly it would make more sense to tell the kernel to drop that part.
off_t pos = lseek(s->fd, 0, SEEK_CUR);
int r = read(s->fd,buffer,max_len);
#ifdef POSIX_FADV_WILLNEED
posix_fadvise(s->fd, pos, max_len, POSIX_FADV_DONTNEED);
posix_fadvise(s->fd, pos + max_len, PREFETCH_LEN, POSIX_FADV_WILLNEED);
#endif

should make more sense.



More information about the MPlayer-dev-eng mailing list