26 Eviction Queues
Up to 8 eviction queues for each CSpace
A single CSpace supports up to 8 distinct eviction queues for the DGS nodes. This has been done to allow for independent LRU eviction in distinct memory spaces, for example there may be an eviction queue associated with system memory and another for video card memory.
It doesn't make sense to evict objects only using system memory when video memory is running short, and vice versa.
// DGNode.h
const ssize_t DGS_NUM_RESERVED_EVICTION_QUEUES = 8;
const ssize_t DgsEvictionQueueIndex_SystemMemory = 0;
const ssize_t DgsEvictionQueueIndex_VideoCardTextures = 1;
// DGSystem.h
$class DGSystem isa IObject
{
public:
DGEvictionQueue& GetEvictionQueue(ssize_t evictionQueueIndex)
{
cxAssert(0 <= evictionQueueIndex && evictionQueueIndex < DGS_NUM_RESERVED_EVICTION_QUEUES);
return evictionQueues_[evictionQueueIndex];
}
private:
DGEvictionQueue evictionQueues_[DGS_NUM_RESERVED_EVICTION_QUEUES];
};
Double linked list
Each eviction queue is implemented using a double linked list. A double linked list allows for fast removal of elements from any position.
A given eviction queue can hold both independent and dependent nodes (they are treated equally as far as the LRU eviction system is concerned).
A node can belong to at most one eviction queue, therefore the 'prev' and 'next' pointers for a double linked list are (inherited) members of class DGBaseNode.
#include "Ceda/cxUtils/DoubleLinkedList.h"
// DGNode.h
class DGBaseNode : public DoubleLinkedList<DGBaseNode>::NodeBase
{
friend class DGEvictionQueue;
};
// DGEvictionQueue.h
class DGEvictionQueue
{
...
private:
typedef DoubleLinkedList<DGBaseNode> LIST;
LIST list_;
};
Which eviction queue is assigned to a DGS node?
The eviction queue associated with a given DGS node is determined by the virtual method EvictionQueueIndex on DGBaseNode.
This has a default implementation that associates the node with the eviction queue for objects consuming system memory.
// DGNode.h
class DGBaseNode
{
public:
virtual ssize_t EvictionQueueIndex() const { return DgsEvictionQueueIndex_SystemMemory; }
...
}
// DGNode.cpp
inline DGEvictionQueue& GetEvictionQueue(DGSystem& system, const DGBaseNode* node)
{
cxAssert(node);
ssize_t index = node->EvictionQueueIndex();
return system.GetEvictionQueue(index);
}