27 DGS node effective size

In order for LRU eviction to work well there needs to be a reasonably accurate estimate of the memory usage of each DGS node.

Every DGS node (whether independent, dependent or asynchronous) must implement the virtual function ByteSize(). This should return the effective size of the node:


class DGBaseNode
{
public:
    ...
    virtual ssize_t ByteSize() const = 0;
private:
    mutable int32 lastByteSize_;
}

The eviction queue records the total bytes taken up by the nodes in the queue. Eviction is based on hitting a target size.

Generated implementation of ByteSize() for $dep members

Consider that struct X has a $dep member variable named y1:


$struct X :
    model
    {
        int x1;
        int x2;
    }
{
    $dep int y1 = x1 + x2;
};

Xcpp generates the following implementation of ByteSize():


virtual ceda::ssize_t ByteSize() const
{
    X const* _self = CONST_ATTRIB_CAST(X,y1);
    return ceda::CacheValueAdditionalSize(_self->_y1_);
}

CacheValueAdditionalSize

CacheValueAdditionalSize(const T& x) returns the additional size - i.e. the size of additional buffers associated with the given cached value x (i.e. in addition to sizeof(T)).


template <typename T>
ssize_t CacheValueAdditionalSize(const T&)

For simple POD data types like bool, int32 and float64, CacheValueAdditionalSize() returns 0.

CacheValueAdditionalSize has been specialised for the following types:


std::pair<U,V>
std::array<T,N>
std::basic_string<T>
std::vector<T,A>
std::deque<T,A>
std::list<T,A>
std::set<K,P,A>
std::multiset<K,P,A>
std::map<K,T,P,A>
std::multimap<K,T,P,A>
std::shared_ptr<T>
std::unique_ptr<T>
ceda::Array<T,N>
ceda::DynArray<T>
ceda::basic_xstring<T>
ceda::xvector<T>
ceda::xdeque<T,pageSize>

todo: implement for std::unordered_map and std::optional.

In order to be accurate, CacheValueAdditionalSize() accounts for the overheads of heap allocations and the overheads of linked list nodes, red-black tree nodes etc.

The implementation is retained as supporting/eviction/CacheValueAdditionalSize.cpp.

CacheValueSize

CacheValueSize is implemented in terms of CacheValueAdditionalSize as follows:


template <typename T>
ssize_t CacheValueSize(const T& x)
{
    return sizeof(T) + CacheValueAdditionalSize(x);
}