aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-02-28 21:33:09 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2017-03-04 00:31:32 +0000
commitb29a254662a0a0b6ca85b97afb82c441cfabe5ff (patch)
treeecc6e268899c4efdfbd69a692761b7c75c4efa37 /searchlib
parent2df3b95a695c003f937338b86f373f2880bcdd98 (diff)
Align code and GC some unused code.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/datastore/buffer_type.h2
-rw-r--r--searchlib/src/vespa/searchlib/datastore/bufferstate.h34
-rw-r--r--searchlib/src/vespa/searchlib/datastore/datastore.hpp8
-rw-r--r--searchlib/src/vespa/searchlib/datastore/datastorebase.cpp19
-rw-r--r--searchlib/src/vespa/searchlib/datastore/datastorebase.h17
5 files changed, 31 insertions, 49 deletions
diff --git a/searchlib/src/vespa/searchlib/datastore/buffer_type.h b/searchlib/src/vespa/searchlib/datastore/buffer_type.h
index d937a60209b..b89aaa1bf84 100644
--- a/searchlib/src/vespa/searchlib/datastore/buffer_type.h
+++ b/searchlib/src/vespa/searchlib/datastore/buffer_type.h
@@ -2,7 +2,7 @@
#pragma once
-#include <assert.h>
+#include <cassert>
#include <cstdint>
#include <sys/types.h>
diff --git a/searchlib/src/vespa/searchlib/datastore/bufferstate.h b/searchlib/src/vespa/searchlib/datastore/bufferstate.h
index cd765b22a40..173d74b9e63 100644
--- a/searchlib/src/vespa/searchlib/datastore/bufferstate.h
+++ b/searchlib/src/vespa/searchlib/datastore/bufferstate.h
@@ -2,14 +2,11 @@
#pragma once
-#include <vector>
-#include <deque>
-#include <vespa/vespalib/util/alloc.h>
-#include <vespa/vespalib/util/array.h>
-
#include "buffer_type.h"
#include "entryref.h"
#include <vespa/vespalib/util/generationhandler.h>
+#include <vespa/vespalib/util/alloc.h>
+#include <vespa/vespalib/util/array.h>
namespace search {
namespace datastore {
@@ -40,24 +37,24 @@ public:
};
private:
- size_t _usedElems;
- size_t _allocElems;
- uint64_t _deadElems;
- State _state;
- bool _disableElemHoldList;
- uint64_t _holdElems;
+ size_t _usedElems;
+ size_t _allocElems;
+ uint64_t _deadElems;
+ State _state;
+ bool _disableElemHoldList;
+ uint64_t _holdElems;
// Number of bytes that are heap allocated by elements that are stored in this buffer.
// For simple types this is 0.
- size_t _extraUsedBytes;
+ size_t _extraUsedBytes;
// Number of bytes that are heap allocated by elements that are stored in this buffer and is now on hold.
// For simple types this is 0.
- size_t _extraHoldBytes;
- FreeList _freeList;
+ size_t _extraHoldBytes;
+ FreeList _freeList;
FreeListList *_freeListList; // non-NULL if free lists are enabled
// NULL pointers if not on circular list of buffer states with free elems
- BufferState *_nextHasFree;
- BufferState *_prevHasFree;
+ BufferState *_nextHasFree;
+ BufferState *_prevHasFree;
BufferTypeBase *_typeHandler;
uint32_t _typeId;
@@ -83,9 +80,8 @@ public:
* @param sizeNeeded Number of elements needed to be free
* @param buffer start of buffer.
*/
- void
- onActive(uint32_t bufferId, uint32_t typeId, BufferTypeBase *typeHandler,
- size_t sizeNeeded, void *&buffer);
+ void onActive(uint32_t bufferId, uint32_t typeId, BufferTypeBase *typeHandler,
+ size_t sizeNeeded, void *&buffer);
/**
* Transition from ACTIVE to HOLD state.
diff --git a/searchlib/src/vespa/searchlib/datastore/datastore.hpp b/searchlib/src/vespa/searchlib/datastore/datastore.hpp
index 56db025c28c..f4d80795c87 100644
--- a/searchlib/src/vespa/searchlib/datastore/datastore.hpp
+++ b/searchlib/src/vespa/searchlib/datastore/datastore.hpp
@@ -30,7 +30,7 @@ void
DataStoreT<RefT>::freeElem(EntryRef ref, uint64_t len)
{
RefType intRef(ref);
- BufferState &state = _states[intRef.bufferId()];
+ BufferState &state = getBufferState(intRef.bufferId());
if (state.isActive()) {
if (state.freeListList() != NULL && len == state.getClusterSize()) {
if (state.freeList().empty()) {
@@ -54,7 +54,7 @@ DataStoreT<RefT>::holdElem(EntryRef ref, uint64_t len, size_t extraBytes)
{
RefType intRef(ref);
uint64_t alignedLen = RefType::align(len);
- BufferState &state = _states[intRef.bufferId()];
+ BufferState &state = getBufferState(intRef.bufferId());
assert(state.isActive());
if (state.hasDisabledElemHoldList()) {
state.incDeadElems(alignedLen);
@@ -79,7 +79,7 @@ DataStoreT<RefT>::trimElemHoldList(generation_t usedGen)
if (static_cast<sgeneration_t>(it->_generation - usedGen) >= 0)
break;
RefType intRef(it->_ref);
- BufferState &state = _states[intRef.bufferId()];
+ BufferState &state = getBufferState(intRef.bufferId());
freeElem(it->_ref, it->_len);
state.decHoldElems(it->_len);
++freed;
@@ -100,7 +100,7 @@ DataStoreT<RefT>::clearElemHoldList(void)
ElemHold2List::iterator ite(elemHold2List.end());
for (; it != ite; ++it) {
RefType intRef(it->_ref);
- BufferState &state = _states[intRef.bufferId()];
+ BufferState &state = getBufferState(intRef.bufferId());
freeElem(it->_ref, it->_len);
state.decHoldElems(it->_len);
}
diff --git a/searchlib/src/vespa/searchlib/datastore/datastorebase.cpp b/searchlib/src/vespa/searchlib/datastore/datastorebase.cpp
index 5a99db4c305..e73dcb2d43a 100644
--- a/searchlib/src/vespa/searchlib/datastore/datastorebase.cpp
+++ b/searchlib/src/vespa/searchlib/datastore/datastorebase.cpp
@@ -75,9 +75,9 @@ public:
};
-DataStoreBase::DataStoreBase(uint32_t numBuffers,
- size_t maxClusters)
+DataStoreBase::DataStoreBase(uint32_t numBuffers, size_t maxClusters)
: _buffers(numBuffers),
+ _typeIds(numBuffers),
_activeBufferIds(),
_states(numBuffers),
_typeHandlers(),
@@ -160,18 +160,6 @@ DataStoreBase::addType(BufferTypeBase *typeHandler)
return typeId;
}
-uint32_t
-DataStoreBase::getNumActiveBuffers() const
-{
- uint32_t result = 0;
- for (const auto &state : _states) {
- if (state.isActive()) {
- ++result;
- }
- }
- return result;
-}
-
void
DataStoreBase::transferElemHoldList(generation_t generation)
{
@@ -373,8 +361,7 @@ DataStoreBase::getAddressSpaceUsage() const
}
void
-DataStoreBase::onActive(uint32_t bufferId, uint32_t typeId,
- size_t sizeNeeded)
+DataStoreBase::onActive(uint32_t bufferId, uint32_t typeId, size_t sizeNeeded)
{
assert(typeId < _typeHandlers.size());
assert(bufferId < _numBuffers);
diff --git a/searchlib/src/vespa/searchlib/datastore/datastorebase.h b/searchlib/src/vespa/searchlib/datastore/datastorebase.h
index ed28cf0fa8c..c6aa098cb9f 100644
--- a/searchlib/src/vespa/searchlib/datastore/datastorebase.h
+++ b/searchlib/src/vespa/searchlib/datastore/datastorebase.h
@@ -7,6 +7,7 @@
#include <vespa/searchlib/util/memoryusage.h>
#include <vespa/searchlib/common/address_space.h>
#include <vector>
+#include <deque>
namespace search {
namespace datastore {
@@ -36,6 +37,9 @@ protected:
typedef vespalib::GenerationHandler::sgeneration_t sgeneration_t;
std::vector<void *> _buffers; // For fast mapping with known types
+private:
+ std::vector<uint32_t> _typeIds; // Cached,compact access to frequently used typeId
+protected:
std::vector<uint32_t> _activeBufferIds; // typeId -> active buffer
// Hold list at freeze, when knowing how long elements must be held
@@ -121,8 +125,9 @@ public:
}
};
-protected:
+private:
std::vector<BufferState> _states;
+protected:
std::vector<BufferTypeBase *> _typeHandlers; // TypeId -> handler
std::vector<BufferState::FreeListList> _freeListLists;
@@ -132,8 +137,8 @@ protected:
ElemHold1List _elemHold1List;
ElemHold2List _elemHold2List;
- uint32_t _numBuffers;
- size_t _maxClusters;
+ const uint32_t _numBuffers;
+ const size_t _maxClusters;
vespalib::GenerationHolder _genHolder;
@@ -220,15 +225,9 @@ public:
* Get active buffer id for the given type id.
*/
uint32_t getActiveBufferId(uint32_t typeId) const { return _activeBufferIds[typeId]; }
-
const BufferState &getBufferState(uint32_t bufferId) const { return _states[bufferId]; }
-
BufferState &getBufferState(uint32_t bufferId) { return _states[bufferId]; }
-
uint32_t getNumBuffers() const { return _numBuffers; }
-
- uint32_t getNumActiveBuffers() const;
-
bool hasElemHold1() const { return !_elemHold1List.empty(); }
/**