diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-02-13 23:59:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-13 23:59:02 +0100 |
commit | b51ce665456070fb6b59001558309fcb8429d509 (patch) | |
tree | 75998f42eedef44f28019035ca070b4331bfa2c0 | |
parent | ecee339b9aa8793a8689b1916821027ae1f48503 (diff) | |
parent | 3ecf2e1b0aeed121fa8b588bbe3e50a70386c91d (diff) |
Merge pull request #16505 from vespa-engine/toregge/add-alloc-aligned-member-function
Add alloc_aligned member function.
5 files changed, 10 insertions, 6 deletions
diff --git a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp index 321f9345791..711a764abaf 100644 --- a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp +++ b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp @@ -4,7 +4,6 @@ #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/stllike/hash_set.h> #include <vespa/vespalib/stllike/asciistream.h> -#include <vespa/vespalib/util/memory_allocator.h> #include <vespa/fastlib/io/bufferedfile.h> #include <vespa/fastos/app.h> #include <iostream> @@ -67,7 +66,7 @@ shafile(const string &baseDir, string fullFile(prependBaseDir(baseDir, file)); FastOS_File f; std::ostringstream os; - Alloc buf = Alloc::alloc(65536, MemoryAllocator::HUGEPAGE_SIZE, 0x1000); + Alloc buf = Alloc::alloc_aligned(65536, 0x1000); f.EnableDirectIO(); bool openres = f.OpenReadOnly(fullFile.c_str()); if (!openres) { diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 8ba4232a5c6..9e8203f352e 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -14,7 +14,6 @@ #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/test/insertion_operators.h> #include <vespa/vespalib/util/exceptions.h> -#include <vespa/vespalib/util/memory_allocator.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <iomanip> @@ -139,7 +138,7 @@ TEST("test that DirectIOPadding works accordng to spec") { FastOS_File file("directio.test"); file.EnableDirectIO(); EXPECT_TRUE(file.OpenReadWrite()); - Alloc buf(Alloc::alloc(FILE_SIZE, MemoryAllocator::HUGEPAGE_SIZE, 4096)); + Alloc buf(Alloc::alloc_aligned(FILE_SIZE, 4096)); memset(buf.get(), 'a', buf.size()); EXPECT_EQUAL(FILE_SIZE, file.Write2(buf.get(), FILE_SIZE)); size_t padBefore(0); diff --git a/searchlib/src/vespa/searchlib/util/comprbuffer.cpp b/searchlib/src/vespa/searchlib/util/comprbuffer.cpp index 35c4abafca4..4a3e79fdb76 100644 --- a/searchlib/src/vespa/searchlib/util/comprbuffer.cpp +++ b/searchlib/src/vespa/searchlib/util/comprbuffer.cpp @@ -2,7 +2,6 @@ #include "comprbuffer.h" #include <vespa/fastos/file.h> -#include <vespa/vespalib/util/memory_allocator.h> #include <cassert> #include <cstring> @@ -74,7 +73,7 @@ ComprBuffer::allocComprBuf() } size_t fullpadding = paddingAfter + paddingBefore; size_t allocLen = _comprBufSize * _unitSize + fullpadding; - _comprAlloc = Alloc::alloc(allocLen, vespalib::alloc::MemoryAllocator::HUGEPAGE_SIZE, memalign); + _comprAlloc = Alloc::alloc_aligned(allocLen, memalign); void *alignedBuf = _comprAlloc.get(); memset(alignedBuf, 0, allocLen); /* diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp index 511593ba1d6..3cd8844dd73 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.cpp +++ b/vespalib/src/vespa/vespalib/util/alloc.cpp @@ -546,6 +546,12 @@ Alloc::alloc(size_t sz) noexcept } Alloc +Alloc::alloc_aligned(size_t sz, size_t alignment) noexcept +{ + return Alloc(&AutoAllocator::getAllocator(MemoryAllocator::HUGEPAGE_SIZE, alignment), sz); +} + +Alloc Alloc::alloc(size_t sz, size_t mmapLimit, size_t alignment) noexcept { return Alloc(&AutoAllocator::getAllocator(mmapLimit, alignment), sz); diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h index 5e71180f9be..71a3bd2407a 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.h +++ b/vespalib/src/vespa/vespalib/util/alloc.h @@ -60,6 +60,7 @@ public: * is always used when size is above limit. */ static Alloc alloc(size_t sz) noexcept; + static Alloc alloc_aligned(size_t sz, size_t alignment) noexcept; static Alloc alloc(size_t sz, size_t mmapLimit, size_t alignment=0) noexcept; static Alloc alloc() noexcept; static Alloc alloc_with_allocator(const MemoryAllocator* allocator) noexcept; |