Skip to content

Commit

Permalink
allocate_large_pages: Fix incorrect check for mmap failure, and use c…
Browse files Browse the repository at this point in the history
…orrect flags for Mac OS.
  • Loading branch information
ned14 committed Sep 7, 2022
1 parent 07488e1 commit 90fdf0e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
6 changes: 3 additions & 3 deletions include/llfio/revision.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define LLFIO_PREVIOUS_COMMIT_REF fa0940ef959827831f6bbb5ddc7c53c04514d8a6
#define LLFIO_PREVIOUS_COMMIT_DATE "2022-09-05 16:26:47 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE fa0940ef
#define LLFIO_PREVIOUS_COMMIT_REF 1714505e3cb9e9547bd45faaefcea1b9ad0506ae
#define LLFIO_PREVIOUS_COMMIT_DATE "2022-09-06 18:54:18 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 1714505e
33 changes: 19 additions & 14 deletions include/llfio/v2.0/detail/impl/posix/utils.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Distributed under the Boost Software License, Version 1.0.

#include "../../../utils.hpp"

#include <cinttypes> // for SCNu64
#include <mutex> // for lock_guard
#include <cinttypes> // for SCNu64
#include <mutex> // for lock_guard

#include <sys/mman.h>

Expand Down Expand Up @@ -220,7 +220,8 @@ namespace utils
#ifdef __linux__
try
{
auto fill_buffer = [](std::vector<char> &buffer, const char *path) -> result<void> {
auto fill_buffer = [](std::vector<char> &buffer, const char *path) -> result<void>
{
for(;;)
{
int ih = ::open(path, O_RDONLY);
Expand Down Expand Up @@ -253,7 +254,8 @@ namespace utils
}
return success();
};
auto parse = [](string_view item, string_view what) -> result<uint64_t> {
auto parse = [](string_view item, string_view what) -> result<uint64_t>
{
auto idx = item.find(what);
if(string_view::npos == idx)
{
Expand Down Expand Up @@ -417,7 +419,8 @@ namespace utils
std::vector<string_view> anon_entries, non_anon_entries;
anon_entries.reserve(32);
non_anon_entries.reserve(32);
auto find_item = [&](size_t idx) -> string_view {
auto find_item = [&](size_t idx) -> string_view
{
auto x = totalview.rfind("\nSize:", idx);
if(x == string_view::npos)
{
Expand Down Expand Up @@ -601,7 +604,8 @@ namespace utils
cpu <user> <user-nice> <kernel> <idle>
*/
std::vector<char> buffer1(65536), buffer2(65536);
auto fill_buffer = [](std::vector<char> &buffer, const char *path) -> result<void> {
auto fill_buffer = [](std::vector<char> &buffer, const char *path) -> result<void>
{
for(;;)
{
int ih = ::open(path, O_RDONLY);
Expand Down Expand Up @@ -638,8 +642,7 @@ namespace utils
OUTCOME_TRY(fill_buffer(buffer1, "/proc/self/stat"));
OUTCOME_TRY(fill_buffer(buffer2, "/proc/stat"));
if(sscanf(buffer1.data(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %" SCNu64 " %" SCNu64, &ret.process_ns_in_user_mode,
&ret.process_ns_in_kernel_mode) <
2)
&ret.process_ns_in_kernel_mode) < 2)
{
return errc::protocol_error;
}
Expand Down Expand Up @@ -705,9 +708,9 @@ namespace utils
return (double) timebase.numer / timebase.denom;
}();*/
10000000.0; // no idea why, but apparently this is the multiplier according to Mac CI runners
ret.system_ns_in_user_mode = (uint64_t)(ts_multiplier * ret.system_ns_in_user_mode);
ret.system_ns_in_kernel_mode = (uint64_t)(ts_multiplier * ret.system_ns_in_kernel_mode);
ret.system_ns_in_idle_mode = (uint64_t)(ts_multiplier * ret.system_ns_in_idle_mode);
ret.system_ns_in_user_mode = (uint64_t) (ts_multiplier * ret.system_ns_in_user_mode);
ret.system_ns_in_kernel_mode = (uint64_t) (ts_multiplier * ret.system_ns_in_kernel_mode);
ret.system_ns_in_idle_mode = (uint64_t) (ts_multiplier * ret.system_ns_in_idle_mode);
return ret;
#else
#error Unknown platform
Expand All @@ -721,6 +724,7 @@ namespace utils
{
large_page_allocation ret(calculate_large_page_allocation(bytes));
int flags = MAP_SHARED | MAP_ANON;
int fd_to_use = -1;
if(ret.page_size_used > 65536)
{
#ifdef MAP_HUGETLB
Expand All @@ -730,18 +734,19 @@ namespace utils
flags |= MAP_ALIGNED_SUPER;
#endif
#ifdef VM_FLAGS_SUPERPAGE_SIZE_ANY
flags |= VM_FLAGS_SUPERPAGE_SIZE_ANY;
fd_to_use = VM_FLAGS_SUPERPAGE_SIZE_ANY;
#endif
}
if((ret.p = mmap(nullptr, ret.actual_size, PROT_WRITE, flags, -1, 0)) == nullptr)
if((ret.p = mmap(nullptr, ret.actual_size, PROT_READ | PROT_WRITE, flags, fd_to_use, 0)) == MAP_FAILED)
{
if(ENOMEM == errno)
{
if((ret.p = mmap(nullptr, ret.actual_size, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0)) != nullptr)
if((ret.p = mmap(nullptr, ret.actual_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, fd_to_use, 0)) != MAP_FAILED)
{
return ret;
}
}
ret.p = nullptr;
}
#ifndef NDEBUG
else if(ret.page_size_used > 65536)
Expand Down
2 changes: 1 addition & 1 deletion include/llfio/v2.0/path_discovery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace path_discovery

//! \brief The default regex used to determine what temporary directories are backed by storage not memory.
static constexpr const char storage_backed_regex[] =
"btrfs|cifs|exfat|ext[2-4]|f2fs|hfs|apfs|jfs|lxfs|nfs|nilf2|ufs|vfat|xfs|zfs|msdosfs|newnfs|ntfs|smbfs|unionfs|fat|fat32|overlayfs";
"btrfs|cifs|exfat|ext[2-4]|f2fs|hfs|apfs|jfs|lxfs|nfs|nilf2|ufs|vfat|xfs|zfs|msdosfs|newnfs|ntfs|smbfs|unionfs|fat|fat32|overlay2?";
//! \brief The default regex used to determine what temporary directories are backed by memory not storage.
static constexpr const char memory_backed_regex[] = "tmpfs|ramfs";

Expand Down

0 comments on commit 90fdf0e

Please sign in to comment.