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
11
namespace
velographx
{
12
13
struct
FilePrefetchResult
{
14
bool
supported
{
false
};
15
bool
advised
{
false
};
16
};
17
18
class
FilePrefetchAdvisor
{
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
velographx::FilePrefetchAdvisor
Definition
file_prefetch.hpp:18
velographx::FilePrefetchAdvisor::advise_will_need
static FilePrefetchResult advise_will_need(const std::filesystem::path &path) noexcept
Definition
file_prefetch.hpp:20
velographx::FilePrefetchAdvisor::supported
static constexpr bool supported() noexcept
Definition
file_prefetch.hpp:33
velographx
Definition
algorithms.hpp:6
velographx::FilePrefetchResult
Definition
file_prefetch.hpp:13
velographx::FilePrefetchResult::advised
bool advised
Definition
file_prefetch.hpp:15
velographx::FilePrefetchResult::supported
bool supported
Definition
file_prefetch.hpp:14
include
velographx
storage
file_prefetch.hpp
Generated by
1.9.8