summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-08-02 12:41:31 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-08-02 12:41:31 +0000
commita7f519c046f78ace59ec04e6e737568658773178 (patch)
tree0ef3700c136a031164d1db5bac3ef381466d2b1f /vespalib
parent5aca1810c365f29ddafb7c3252678ad36cb5e494 (diff)
Provide more information when failing to mmap files
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp16
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)));