X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fio-hint.cpp;h=2bb924674c5202c1d4998c6cb78692aad0c6a012;hb=e8955cc64f0f5da0e90ab62fa3dd277a19fe3abf;hp=506f15de6b027114d6be1eabd6bfe85c092b8811;hpb=16ff37cb24f54719f0111bf9a8dbf577087a158a;p=lttng-tools.git diff --git a/src/common/io-hint.cpp b/src/common/io-hint.cpp index 506f15de6..2bb924674 100644 --- a/src/common/io-hint.cpp +++ b/src/common/io-hint.cpp @@ -54,7 +54,7 @@ int flush_range_async(int fd, off_t offset, off_t nbytes) } } /* namespace */ -#else +#else /* HAVE_SYNC_FILE_RANGE */ namespace { /* @@ -109,7 +109,44 @@ int flush_range_async(int fd, off_t offset, off_t nbytes) return flush_range(fd, offset, nbytes, MS_ASYNC); } } /* namespace */ -#endif +#endif /* !HAVE_SYNC_FILE_RANGE */ + +/* + * Use posix_fadvise when available. + */ +#ifdef HAVE_POSIX_FADVISE +namespace { +int hint_dont_need(int fd, off_t offset, off_t nbytes) +{ + const int ret = posix_fadvise(fd, offset, nbytes, POSIX_FADV_DONTNEED); + if (ret && ret != -ENOSYS) { + PERROR("Failed to mark region as DONTNEED with posix_fadvise: fd=%i, offset=%" PRIu64 + ", nbytes=%" PRIu64, + fd, + static_cast(offset), + static_cast(nbytes)); + errno = ret; + } + + return ret; +} +} /* namespace */ + +#else /* HAVE_POSIX_FADVISE */ + +/* + * Generic noop compat for platforms wihtout posix_fadvise, this is acceptable + * since we are only giving a hint to the kernel. + */ +namespace { +int hint_dont_need(int fd __attribute__((unused)), + off_t offset __attribute__((unused)), + off_t nbytes __attribute__((unused))) +{ + return 0; +} +} /* namespace */ +#endif /* !HAVE_POSIX_FADVISE */ /* * Give a hint to the kernel that we won't need the data at the specified range @@ -135,15 +172,7 @@ void lttng::io::hint_flush_range_dont_need_sync(int fd, off_t offset, off_t nbyt * defined. So it can be expected to lead to lower throughput in * streaming. */ - const int ret = posix_fadvise(fd, offset, nbytes, POSIX_FADV_DONTNEED); - if (ret && ret != -ENOSYS) { - PERROR("Failed to mark region as DONTNEED with posix_fadvise: fd=%i, offset=%" PRIu64 - ", nbytes=%" PRIu64, - fd, - static_cast(offset), - static_cast(nbytes)); - errno = ret; - } + hint_dont_need(fd, offset, nbytes); } /*