VeloGraphX
High-performance dynamic graph analytics in C++20
Loading...
Searching...
No Matches
file_prefetch.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <filesystem>
5
6#if defined(__linux__)
7#include <fcntl.h>
8#include <unistd.h>
9#endif
10
11namespace velographx {
12
14 bool supported{false};
15 bool advised{false};
16};
17
19 public:
20 static FilePrefetchResult advise_will_need(const std::filesystem::path& path) noexcept {
21#if defined(__linux__)
22 const int fd = ::open(path.c_str(), O_RDONLY | O_CLOEXEC);
23 if (fd < 0) return {true, false};
24 const int rc = ::posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED);
25 ::close(fd);
26 return {true, rc == 0};
27#else
28 (void)path;
29 return {false, false};
30#endif
31 }
32
33 [[nodiscard]] static constexpr bool supported() noexcept {
34#if defined(__linux__)
35 return true;
36#else
37 return false;
38#endif
39 }
40};
41
42} // namespace velographx
static FilePrefetchResult advise_will_need(const std::filesystem::path &path) noexcept
static constexpr bool supported() noexcept