evict_writes (struct rw_file *rwf, uint64_t offset, size_t len)
{
  static __thread struct write_window window[NR_WINDOWS];

  /* Evict the oldest window from the page cache. */
  if (window[0].len > 0) {
    sync_file_range (rwf->fd, window[0].offset, window[0].len,
                     SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE|
                     SYNC_FILE_RANGE_WAIT_AFTER);
    posix_fadvise (rwf->fd, window[0].offset, window[0].len,
                   POSIX_FADV_DONTNEED);
  }

  /* Move the Nth window to N-1. */
  memmove (&window[0], &window[1], sizeof window[0] * (NR_WINDOWS-1));

  /* Set up the current window and tell Linux to start writing it out
   * to disk (asynchronously).
   */
  sync_file_range (rwf->fd, offset, len, SYNC_FILE_RANGE_WRITE);
  window[NR_WINDOWS-1].offset = offset;
  window[NR_WINDOWS-1].len = len;
}
evict_writes (struct rw_file *rwf, uint64_t offset, size_t len)
{
  static __thread struct write_window window[NR_WINDOWS];

   
  if (window[0].len > 0) {
    sync_file_range (rwf->fd, window[0].offset, window[0].len,
                     SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE|
                     SYNC_FILE_RANGE_WAIT_AFTER);
    posix_fadvise (rwf->fd, window[0].offset, window[0].len,
                   POSIX_FADV_DONTNEED);
  }

   
  memmove (&window[0], &window[1], sizeof window[0] * (NR_WINDOWS-1));

   
  sync_file_range (rwf->fd, offset, len, SYNC_FILE_RANGE_WRITE);
  window[NR_WINDOWS-1].offset = offset;
  window[NR_WINDOWS-1].len = len;
}