mkdir munmap putenv realpath rmdir socket strchr strcspn strdup \
strncasecmp strndup strnlen strpbrk strrchr strstr strtol strtoul \
strtoull dirfd gethostbyname2 getipnodebyname epoll_create1 \
- sched_getcpu sysconf sync_file_range getrandom
+ sched_getcpu sysconf sync_file_range getrandom posix_fadvise
])
# Check for pthread_setname_np and pthread_getname_np
}
} /* namespace */
-#else
+#else /* HAVE_SYNC_FILE_RANGE */
namespace {
/*
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<uint64_t>(offset),
+ static_cast<uint64_t>(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
* 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<uint64_t>(offset),
- static_cast<uint64_t>(nbytes));
- errno = ret;
- }
+ hint_dont_need(fd, offset, nbytes);
}
/*