diff options
author | Tor Egge <Tor.Egge@yahoo-inc.com> | 2016-11-23 13:24:25 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@yahoo-inc.com> | 2016-11-23 13:52:40 +0000 |
commit | 2eb3eef2762aed251184a6fa9eaad03dc90c9ce1 (patch) | |
tree | 7a13d31d2672d3d0f4ffdfd711fea980de96e1e8 /searchlib | |
parent | 8d83e70bc447ae4797105cdd7c953ca9c6637329 (diff) |
Test data store buffer growth with minSize being 0.
Test initial resizing of first buffer for type.
Test initial memory usage for data store.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/datastore/datastore/datastore_test.cpp | 76 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/datastore/bufferstate.cpp | 4 |
2 files changed, 64 insertions, 16 deletions
diff --git a/searchlib/src/tests/datastore/datastore/datastore_test.cpp b/searchlib/src/tests/datastore/datastore/datastore_test.cpp index e1a9ccd6fe9..5ce9caae833 100644 --- a/searchlib/src/tests/datastore/datastore/datastore_test.cpp +++ b/searchlib/src/tests/datastore/datastore/datastore_test.cpp @@ -68,30 +68,34 @@ class GrowStore using Store = DataStoreT<EntryRefT<22>>; using RefType = Store::RefType; Store _store; + BufferType<int> _firstType; BufferType<int> _type; uint32_t _typeId; public: - GrowStore(size_t minSwitch) + GrowStore(size_t minSize, size_t minSwitch) : _store(), - _type(1, 4, 64, minSwitch), + _firstType(1, 1, 64, 0), + _type(1, minSize, 64, minSwitch), _typeId(0) { + (void) _store.addType(&_firstType); _typeId = _store.addType(&_type); _store.initActiveBuffers(); } - GrowStore() : GrowStore(0) { } ~GrowStore() { _store.dropBuffers(); } GrowthStats getGrowthStats(size_t bufs) { GrowthStats sizes; int i = 0; + int previ = 0; int prevBuffer = -1; while (sizes.size() < bufs) { RefType iRef = _store.allocNewEntry<int>(_typeId).first; int buffer = iRef.bufferId(); if (buffer != prevBuffer) { if (prevBuffer >= 0) { - sizes.push_back(i); + sizes.push_back(i - previ); + previ = i; } prevBuffer = buffer; } @@ -99,6 +103,28 @@ public: } return sizes; } + GrowthStats getFirstBufGrowStats() { + GrowthStats sizes; + int i = 0; + int prevBuffer = -1; + size_t prevAllocated = _store.getMemoryUsage().allocatedBytes(); + for (;;) { + RefType iRef = _store.allocNewEntry<int>(_typeId).first; + size_t allocated = _store.getMemoryUsage().allocatedBytes(); + if (allocated != prevAllocated) { + sizes.push_back(i); + prevAllocated = allocated; + } + int buffer = iRef.bufferId(); + if (buffer != prevBuffer) { + if (prevBuffer >= 0) { + return sizes; + } + prevBuffer = buffer; + } + ++i; + } + } MemoryUsage getMemoryUsage() const { return _store.getMemoryUsage(); } }; @@ -448,19 +474,41 @@ Test::requireThatWecanDisableElemHoldList(void) s.trimHoldLists(101); } +namespace +{ + +void assertGrowStats(GrowthStats expSizes, + GrowthStats expFirstBufSizes, + size_t expInitMemUsage, + size_t minSize, size_t minSwitch) +{ + EXPECT_EQUAL(expSizes, GrowStore(minSize, minSwitch).getGrowthStats(9)); + EXPECT_EQUAL(expFirstBufSizes, GrowStore(minSize, minSwitch).getFirstBufGrowStats()); + EXPECT_EQUAL(expInitMemUsage, GrowStore(minSize, minSwitch).getMemoryUsage().allocatedBytes()); +} + +} void Test::requireThatBufferGrowthWorks() { - // Always switch to new buffer - // Buffer sizes: 4, 8, 16, 32, 64, 64, 64, 64 - // First element in first buffer reserved - EXPECT_EQUAL(GrowthStats({ 3, 11, 27, 59, 123, 187,251, 315}), GrowStore().getGrowthStats(8)); - EXPECT_EQUAL(16u, GrowStore().getMemoryUsage().allocatedBytes()); - // Resize current buffer if buffer size is less than 16 - // Buffer sizes: 16, 32, 64, 64, 64, 64, 64, 64 - // First element in first buffer reserved - EXPECT_EQUAL(GrowthStats({ 15, 47, 111, 175, 239, 303, 367, 431}), GrowStore(16).getGrowthStats(8)); - EXPECT_EQUAL(16u, GrowStore(16).getMemoryUsage().allocatedBytes()); + // Always switch to new buffer, min size 4 + TEST_DO(assertGrowStats({ 4, 8, 16, 32, 64, 64, 64, 64, 64 }, + { 4 }, 20, 4, 0)); + // Resize if buffer size is less than 4, min size 0 + TEST_DO(assertGrowStats({ 4, 8, 16, 32, 64, 64, 64, 64, 64 }, + { 0, 1, 2, 4 }, 4, 0, 4)); + // Alwais switch to new buffer, min size 16 + TEST_DO(assertGrowStats({ 16, 32, 64, 64, 64, 64, 64, 64, 64 }, + { 16 }, 68, 16, 0)); + // Resize if buffer size is less than 16, min size 0 + TEST_DO(assertGrowStats({ 16, 32, 64, 64, 64, 64, 64, 64, 64 }, + { 0, 1, 2, 4, 8, 16 }, 4, 0, 16)); + // Resize if buffer size is less than 16, min size 4 + TEST_DO(assertGrowStats({ 16, 32, 64, 64, 64, 64, 64, 64, 64 }, + { 4, 8, 16 }, 20, 4, 16)); + // Always switch to new buffer, min size 0 + TEST_DO(assertGrowStats({ 1, 1, 2, 4, 8, 16, 32, 64, 64}, + { 0, 1 }, 4, 0, 0)); } int diff --git a/searchlib/src/vespa/searchlib/datastore/bufferstate.cpp b/searchlib/src/vespa/searchlib/datastore/bufferstate.cpp index 9161fed94ee..ab45a5e7f3d 100644 --- a/searchlib/src/vespa/searchlib/datastore/bufferstate.cpp +++ b/searchlib/src/vespa/searchlib/datastore/bufferstate.cpp @@ -75,7 +75,7 @@ BufferState::onActive(uint32_t bufferId, uint32_t typeId, assert(allocSize >= reservedElements + sizeNeeded); _buffer.create(allocSize * typeHandler->elementSize()).swap(_buffer); buffer = _buffer.get(); - assert(buffer != NULL); + assert(buffer != NULL || allocSize == 0u); _allocElems = allocSize; _state = ACTIVE; _typeHandler = typeHandler; @@ -144,7 +144,7 @@ BufferState::dropBuffer(void *&buffer) assert(buffer == NULL); return; } - assert(buffer != NULL); + assert(buffer != NULL || _allocElems == 0); if (_state == ACTIVE) { onHold(); } |