Skip to content

Commit

Permalink
Merge pull request #50 from AntelopeIO/better_mlock_err_msg
Browse files Browse the repository at this point in the history
Provide detailed error message for mlock failure
  • Loading branch information
linh2931 authored Jul 11, 2024
2 parents 23070be + 70085d2 commit 5275ccc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/pinnable_mapped_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sys/vfs.h>
#include <linux/magic.h>
#include <sys/sysinfo.h>
#include <sys/resource.h>
#endif

// use mlock2() on Linux to avoid a noop intercept of mlock() when ASAN is enabled (still present in compiler-rt 18.1)
Expand Down Expand Up @@ -224,7 +225,22 @@ pinnable_mapped_file::pinnable_mapped_file(const std::filesystem::path& dir, boo
#ifndef _WIN32
if(mode == locked) {
if(MLOCK(_non_file_mapped_mapping, _non_file_mapped_mapping_size)) {
std::string what_str("Failed to mlock database \"" + _database_name + "\"");
struct rlimit resouce_limit;
std::string details;

// Query the current locked memory limit and build detailed error message
if (getrlimit(RLIMIT_MEMLOCK, &resouce_limit) == 0) {
details = "Current locked memory ";
details += "soft limit: " + std::to_string(resouce_limit.rlim_cur) + " bytes, ";
details += "hard limit: " + std::to_string(resouce_limit.rlim_max) + " bytes. ";
} else {
details = "getrlimit for RLIMIT_MEMLOCK failed: ";
details += std::strerror(errno);
details += ".";
}
details += "Run \"ulimit -l\" to increase locked memory limit.";

std::string what_str("Failed to mlock database \"" + _database_name + "\". " + details);
BOOST_THROW_EXCEPTION(std::system_error(make_error_code(db_error_code::no_mlock), what_str));
}
std::cerr << "CHAINBASE: Database \"" << _database_name << "\" has been successfully locked in memory" << '\n';
Expand Down

0 comments on commit 5275ccc

Please sign in to comment.