summaryrefslogtreecommitdiffstats
path: root/memfilepersistence
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-10-02 19:59:41 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-10-03 16:52:36 +0000
commit6a0ea2d5fce1967927cf1f4f319fb0209ac2eb1e (patch)
treecdf844359ac298e85d5ffc4e15f467964a8c7593 /memfilepersistence
parent74d9d289d9b9ffd5f9f427a1fb7abf176bae4abe (diff)
Checkpoint 1
Diffstat (limited to 'memfilepersistence')
-rw-r--r--memfilepersistence/src/tests/spi/buffer_test.cpp5
-rw-r--r--memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp11
-rw-r--r--memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h8
-rw-r--r--memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h4
4 files changed, 14 insertions, 14 deletions
diff --git a/memfilepersistence/src/tests/spi/buffer_test.cpp b/memfilepersistence/src/tests/spi/buffer_test.cpp
index a2d917301fc..fdbd7a32f17 100644
--- a/memfilepersistence/src/tests/spi/buffer_test.cpp
+++ b/memfilepersistence/src/tests/spi/buffer_test.cpp
@@ -36,9 +36,8 @@ BufferTest::getSizeReturnsInitiallyAllocatedSize()
void
BufferTest::getSizeReturnsUnAlignedSizeForMMappedAllocs()
{
- Buffer buf(vespalib::MMapAlloc::HUGEPAGE_SIZE + 1);
- CPPUNIT_ASSERT_EQUAL(size_t(vespalib::MMapAlloc::HUGEPAGE_SIZE + 1),
- buf.getSize());
+ Buffer buf(vespalib::alloc::MMapAllocator::HUGEPAGE_SIZE + 1);
+ CPPUNIT_ASSERT_EQUAL(size_t(vespalib::alloc::MMapAllocator::HUGEPAGE_SIZE + 1), buf.getSize());
}
void
diff --git a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
index 5ecb439b3f0..886c2a35c13 100644
--- a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
+++ b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
@@ -5,11 +5,18 @@
#include <algorithm>
#include <stdlib.h>
+using vespalib::DefaultAlloc;
+using vespalib::alloc::MMapAllocator;
+using vespalib::alloc::Alloc;
+
namespace storage {
namespace memfile {
+// Use AutoAlloc to transparently use mmap for large buffers.
+// It is crucial that any backing buffer type returns an address that is
+// 512-byte aligned, or direct IO will scream at us and fail everything.
Buffer::Buffer(size_t size)
- : _buffer(size),
+ : _buffer(DefaultAlloc::create(size, MMapAllocator::HUGEPAGE_SIZE, 512)),
_size(size)
{
}
@@ -17,7 +24,7 @@ Buffer::Buffer(size_t size)
void
Buffer::resize(size_t size)
{
- BackingType buffer(size);
+ Alloc buffer = _buffer.create(size);
size_t commonSize(std::min(size, _size));
memcpy(buffer.get(), _buffer.get(), commonSize);
_buffer.swap(buffer);
diff --git a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h
index d097a078af9..26f4a644d0c 100644
--- a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h
+++ b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h
@@ -19,13 +19,7 @@ namespace memfile {
class Buffer
{
- // Use AutoAlloc to transparently use mmap for large buffers.
- // It is crucial that any backing buffer type returns an address that is
- // 512-byte aligned, or direct IO will scream at us and fail everything.
- static constexpr size_t MMapLimit = vespalib::MMapAlloc::HUGEPAGE_SIZE;
- using BackingType = vespalib::AutoAlloc<MMapLimit, 512>;
-
- BackingType _buffer;
+ vespalib::alloc::Alloc _buffer;
// Actual, non-aligned size (as opposed to _buffer.size()).
size_t _size;
diff --git a/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h b/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h
index 8dbffcaf795..c564893a154 100644
--- a/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h
+++ b/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h
@@ -77,7 +77,7 @@ public:
typedef vespalib::LinkedPtr<SharedBuffer> LP;
explicit SharedBuffer(size_t totalSize)
- : _buf(totalSize),
+ : _buf(vespalib::alloc::MMapAllocFactory::create(totalSize)),
_usedSize(0)
{
}
@@ -115,7 +115,7 @@ public:
return static_cast<const char*>(_buf.get());
}
private:
- vespalib::MMapAlloc _buf;
+ vespalib::alloc::Alloc _buf;
size_t _usedSize;
};