From: Josh F. <jf...@pv...> - 2008-09-29 14:12:53
|
Brice Figureau wrote: > Hi, > > I was looking to the 2.4.2 SD spooling code lately (this was part of > understanding why despooling performances were not that good on my > hardware), when I noticed the following usage of posix_fadvise while > sequentially reading the spool file (despool_data): > > #if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED) > posix_fadvise(rdcr->spool_fd, 0, 0, POSIX_FADV_WILLNEED); > #endif > > I don't understand why we're telling the kernel to page cache the spool > file we're reading since we won't reuse those data. > Moreover, there is no "DONTNEED" call after despool_data to let the > kernel know it can trash what we read. > It allows a non-blocking asynchronous read ahead of the spool file while the SD is working on the previous buffer. > I thought that something along the line of this in despool_data: > #if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_SEQUENTIAL) > posix_fadvise(rdcr->spool_fd, 0, 0, POSIX_FADV_SEQUENTIAL); > #endif > #if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_NOREUSE) > posix_fadvise(rdcr->spool_fd, 0, 0, POSIX_FADV_NOREUSE); > #endif > > The POSIX_FADV_SEQUENTIAL doubles the size of the readahead window. I don't know if that is good or bad. I suspect it depends on the hardware, amount of RAM, etc. The POSIX_FADV_NOREUSE is definitely not helpful. From the posix_fadvise() man page: In kernels before 2.6.18, POSIX_FADV_NOREUSE had the same semantics as POSIX_FADV_WILLNEED. This was probably a bug; since kernel 2.6.18, this flag is a no-op. > And a few POSIX_FADV_DONTNEED after each block read with the correct > offset and length to tell the pagecache we don't need this part anymore. > > Does it make sense? > Or did I miss something? > I agree that the POSIX_FADV_DONTNEED could be useful when reading the spool file. The kernel probably will see the spool file pages as being more recently used. So when cache space is needed, it could cause the kernel to free useful pages just to keep the spool file pages. It has no way to know they will never be used again. The use of POSIX_FADV_DONTNEED could help keep the cache more efficiently used. Regards, Josh Fisher |