diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2021-02-11 13:14:08 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2021-02-11 13:14:08 +0100 |
commit | 4cb8c98d334e993f6c9187909324768e658e9f76 (patch) | |
tree | 550fd51a21c82b49183961c06cc9246ee6ae0f2a /vespalib | |
parent | 3f49fca252a0a7ddc5524c0daba04c0ddb86bda2 (diff) |
Use vespalib::hash_map instead of std::map.
Simplify rounding function.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp | 11 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/mmap_file_allocator.h | 3 |
2 files changed, 8 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 821e3c86a67..f410a1f6362 100644 --- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp +++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp @@ -1,6 +1,7 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "mmap_file_allocator.h" +#include <vespa/vespalib/stllike/hash_map.hpp> #include <fcntl.h> #include <sys/mman.h> #include <cassert> @@ -9,10 +10,10 @@ namespace vespalib::alloc { namespace { -const size_t page_size = std::max(getpagesize(), 4096); +const size_t mmap_alignment = getpagesize(); -size_t round_to_page_size(size_t size) { - return (size + ((-size) & (page_size - 1))); +size_t round_to_mmap_alignment(size_t size) { + return ((size + (mmap_alignment - 1)) & ~(mmap_alignment - 1)); } } @@ -41,7 +42,7 @@ MmapFileAllocator::alloc(size_t sz) const return PtrAndSize(nullptr, 0); // empty allocation } uint64_t offset = _end_offset; - sz = round_to_page_size(sz); + sz = round_to_mmap_alignment(sz); _end_offset += sz; _file.resize(_end_offset); void *buf = mmap(nullptr, sz, @@ -52,7 +53,7 @@ MmapFileAllocator::alloc(size_t sz) const assert(buf != MAP_FAILED); assert(buf != nullptr); // Register allocation - auto ins_res = _allocations.emplace(buf, sz); + auto ins_res = _allocations.insert(std::make_pair(buf, sz)); assert(ins_res.second); return PtrAndSize(buf, sz); } diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h index 84f63c8fc61..dc400dda59a 100644 --- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h +++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h @@ -4,6 +4,7 @@ #include "alloc.h" #include <vespa/vespalib/io/fileutil.h> +#include <vespa/vespalib/stllike/hash_map.h> #include <vespa/vespalib/stllike/string.h> #include <map> @@ -18,7 +19,7 @@ class MmapFileAllocator : public MemoryAllocator { vespalib::string _dir_name; mutable File _file; mutable uint64_t _end_offset; - mutable std::map<void *, size_t> _allocations; + mutable hash_map<void *, size_t> _allocations; public: MmapFileAllocator(const vespalib::string& dir_name); ~MmapFileAllocator(); |