diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-08-02 20:14:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-02 20:14:43 +0200 |
commit | 9a42c276022c98ce49077a3fa4d5413eea367703 (patch) | |
tree | 05b62e9a5822e6f916d22d33b591407481dc1de9 | |
parent | ce018c9aee7a80ac40bcc54a82c0cff2ab97ef92 (diff) | |
parent | a7f519c046f78ace59ec04e6e737568658773178 (diff) |
Merge pull request #27954 from vespa-engine/balder/add-better-error-detection
Provide more information when failing to mmap files
-rw-r--r-- | vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp index 2c0d0f4339d..51a639a3c4e 100644 --- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp +++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp @@ -2,12 +2,16 @@ #include "mmap_file_allocator.h" #include "round_up_to_page_size.h" +#include "exceptions.h" +#include "stringfmt.h" #include <vespa/vespalib/stllike/hash_map.hpp> #include <fcntl.h> #include <sys/mman.h> #include <cassert> #include <filesystem> +using vespalib::make_string_short::fmt; + namespace vespalib::alloc { MmapFileAllocator::MmapFileAllocator(const vespalib::string& dir_name) @@ -50,12 +54,12 @@ MmapFileAllocator::alloc(size_t sz) const } sz = round_up_to_page_size(sz); uint64_t offset = alloc_area(sz); - void *buf = mmap(nullptr, sz, - PROT_READ | PROT_WRITE, - MAP_SHARED, - _file.getFileDescriptor(), - offset); - assert(buf != MAP_FAILED); + void *buf = mmap(nullptr, sz, PROT_READ | PROT_WRITE, MAP_SHARED, _file.getFileDescriptor(), offset); + if (buf == MAP_FAILED) { + throw IoException(fmt("Failed mmap(nullptr, %zu, PROT_READ | PROT_WRITE, MAP_SHARED, %s(fd=%d), %lu). Reason given by OS = '%s'", + sz, _file.getFilename().c_str(), _file.getFileDescriptor(), offset, getLastErrorString().c_str()), + IoException::getErrorType(errno), VESPA_STRLOC); + } assert(buf != nullptr); // Register allocation auto ins_res = _allocations.insert(std::make_pair(buf, SizeAndOffset(sz, offset))); |