Krita Source Code Documentation
Loading...
Searching...
No Matches
KisChunkAllocator Class Reference

#include <kis_chunk_allocator.h>

Public Member Functions

void debugChunks ()
 
qreal debugFragmentation (bool toStderr=true)
 
void freeChunk (KisChunk chunk)
 
KisChunk getChunk (quint64 size)
 
 KisChunkAllocator (quint64 slabSize=DEFAULT_SLAB_SIZE, quint64 storeSize=DEFAULT_STORE_SIZE)
 
quint64 numChunks () const
 
bool sanityCheck (bool pleaseCrash=true)
 
 ~KisChunkAllocator ()
 

Private Member Functions

bool tryInsertChunk (KisChunkDataList &list, KisChunkDataListIterator &iterator, quint64 size)
 

Private Attributes

KisChunkDataListIterator m_iterator
 
KisChunkDataList m_list
 
quint64 m_storeMaxSize
 
quint64 m_storeSize
 
quint64 m_storeSlabSize
 

Detailed Description

Definition at line 116 of file kis_chunk_allocator.h.

Constructor & Destructor Documentation

◆ KisChunkAllocator()

KisChunkAllocator::KisChunkAllocator ( quint64 slabSize = DEFAULT_SLAB_SIZE,
quint64 storeSize = DEFAULT_STORE_SIZE )

Definition at line 21 of file kis_chunk_allocator.cpp.

22{
23 m_storeMaxSize = storeSize;
24 m_storeSlabSize = slabSize;
25
26 m_iterator = m_list.begin();
29}
KisChunkDataList m_list
KisChunkDataListIterator m_iterator
#define INIT_FAIL_COUNTER()

References INIT_FAIL_COUNTER, m_iterator, m_list, m_storeMaxSize, m_storeSize, and m_storeSlabSize.

◆ ~KisChunkAllocator()

KisChunkAllocator::~KisChunkAllocator ( )

Definition at line 31 of file kis_chunk_allocator.cpp.

32{
33}

Member Function Documentation

◆ debugChunks()

void KisChunkAllocator::debugChunks ( )

Definition at line 122 of file kis_chunk_allocator.cpp.

123{
124 quint64 idx = 0;
126
127 for(i = m_list.begin(); i != m_list.end(); ++i) {
128 qInfo("chunk #%lld: [%lld %lld]", idx++, i->m_begin, i->m_end);
129 }
130}
KisChunkDataList::iterator KisChunkDataListIterator

References m_list.

◆ debugFragmentation()

qreal KisChunkAllocator::debugFragmentation ( bool toStderr = true)

Definition at line 161 of file kis_chunk_allocator.cpp.

162{
164
165 quint64 totalSize = 0;
166 quint64 allocated = 0;
167 quint64 free = 0;
168 qreal fragmentation = 0;
169
170 for(i = m_list.begin(); i != m_list.end(); ++i) {
171 allocated += i->m_end - i->m_begin + 1;
172
173 if(HAS_PREVIOUS(m_list, i))
174 free += GAP_SIZE(PEEK_PREVIOUS(i).m_end, i->m_begin);
175 else
176 free += i->m_begin;
177 }
178
179 i = m_list.end();
180 if(HAS_PREVIOUS(m_list, i))
181 totalSize = PEEK_PREVIOUS(i).m_end + 1;
182
183 if(totalSize)
184 fragmentation = qreal(free) / totalSize;
185
186 if(toStderr) {
187 qInfo() << "Hard store limit:\t" << m_storeMaxSize;
188 qInfo() << "Slab size:\t\t" << m_storeSlabSize;
189 qInfo() << "Num slabs:\t\t" << m_storeSize / m_storeSlabSize;
190 qInfo() << "Store size:\t\t" << m_storeSize;
191 qInfo() << "Total used:\t\t" << totalSize;
192 qInfo() << "Allocated:\t\t" << allocated;
193 qInfo() << "Free:\t\t\t" << free;
194 qInfo() << "Fragmentation:\t\t" << fragmentation;
196 }
197
198 Q_ASSERT(totalSize == allocated + free);
199
200 return fragmentation;
201}
#define GAP_SIZE(low, high)
#define HAS_PREVIOUS(list, iter)
#define PEEK_PREVIOUS(iter)
#define DEBUG_FAIL_COUNTER()

References DEBUG_FAIL_COUNTER, GAP_SIZE, HAS_PREVIOUS, m_list, m_storeMaxSize, m_storeSize, m_storeSlabSize, and PEEK_PREVIOUS.

◆ freeChunk()

void KisChunkAllocator::freeChunk ( KisChunk chunk)

Definition at line 104 of file kis_chunk_allocator.cpp.

105{
106 if(m_iterator != m_list.end() && m_iterator == chunk.position()) {
108 return;
109 }
110
111 Q_ASSERT(chunk.position()->m_begin == chunk.begin());
112 m_list.erase(chunk.position());
113}
quint64 begin() const
KisChunkDataListIterator position()

References KisChunk::begin(), m_iterator, m_list, and KisChunk::position().

◆ getChunk()

KisChunk KisChunkAllocator::getChunk ( quint64 size)

Definition at line 35 of file kis_chunk_allocator.cpp.

36{
39
40 forever {
43
44 if(m_iterator == m_list.end())
45 break;
46
47 m_iterator++;
49 }
50
52 m_iterator = m_list.begin();
53
54 forever {
57
58 if(m_iterator == m_list.end() || m_iterator == startPosition)
59 break;
60
61 m_iterator++;
63 }
64
66 m_iterator = m_list.end();
67
71 }
72
73 qFatal("KisChunkAllocator: out of swap space");
74
75 // just let gcc be happy! :)
76 return KisChunk(m_list.end());
77}
bool tryInsertChunk(KisChunkDataList &list, KisChunkDataListIterator &iterator, quint64 size)
#define WRAP_PREVIOUS_CHUNK_DATA(iter)
#define REGISTER_STEP()
#define START_COUNTING()
#define REGISTER_FAIL()

References m_iterator, m_list, m_storeMaxSize, m_storeSize, m_storeSlabSize, REGISTER_FAIL, REGISTER_STEP, START_COUNTING, tryInsertChunk(), and WRAP_PREVIOUS_CHUNK_DATA.

◆ numChunks()

quint64 KisChunkAllocator::numChunks ( ) const
inline

Definition at line 123 of file kis_chunk_allocator.h.

123 {
124 return m_list.size();
125 }

◆ sanityCheck()

bool KisChunkAllocator::sanityCheck ( bool pleaseCrash = true)

Definition at line 132 of file kis_chunk_allocator.cpp.

133{
134 bool failed = false;
136
137 for(i = m_list.begin(); i != m_list.end(); ++i) {
138 if(HAS_PREVIOUS(m_list, i)) {
139 if(PEEK_PREVIOUS(i).m_end >= i->m_begin) {
140 qWarning("Chunks overlapped: [%lld %lld], [%lld %lld]", PEEK_PREVIOUS(i).m_begin, PEEK_PREVIOUS(i).m_end, i->m_begin, i->m_end);
141 failed = true;
142 break;
143 }
144 }
145 }
146
147 i = m_list.end();
148 if(HAS_PREVIOUS(m_list, i)) {
149 if(PEEK_PREVIOUS(i).m_end >= m_storeSize) {
150 warnKrita << "Last chunk exceeds the store size!";
151 failed = true;
152 }
153 }
154
155 if(failed && pleaseCrash)
156 qFatal("KisChunkAllocator: sanity check failed!");
157
158 return !failed;
159}
#define warnKrita
Definition kis_debug.h:87

References HAS_PREVIOUS, m_list, m_storeSize, PEEK_PREVIOUS, and warnKrita.

◆ tryInsertChunk()

bool KisChunkAllocator::tryInsertChunk ( KisChunkDataList & list,
KisChunkDataListIterator & iterator,
quint64 size )
private

Definition at line 79 of file kis_chunk_allocator.cpp.

82{
83 bool result = false;
84 quint64 highBound = m_storeSize;
85 quint64 lowBound = 0;
86 quint64 shift = 0;
87
88 if(HAS_NEXT(list, iterator))
89 highBound = PEEK_NEXT(iterator).m_begin;
90
91 if(HAS_PREVIOUS(list, iterator)) {
92 lowBound = PEEK_PREVIOUS(iterator).m_end;
93 shift = 1;
94 }
95
96 if(GAP_SIZE(lowBound, highBound) >= size) {
97 list.insert(iterator, KisChunkData(lowBound + shift, size));
98 result = true;
99 }
100
101 return result;
102}
#define HAS_NEXT(list, iter)
#define PEEK_NEXT(iter)

References GAP_SIZE, HAS_NEXT, HAS_PREVIOUS, m_storeSize, PEEK_NEXT, and PEEK_PREVIOUS.

Member Data Documentation

◆ m_iterator

KisChunkDataListIterator KisChunkAllocator::m_iterator
private

Definition at line 145 of file kis_chunk_allocator.h.

◆ m_list

KisChunkDataList KisChunkAllocator::m_list
private

Definition at line 144 of file kis_chunk_allocator.h.

◆ m_storeMaxSize

quint64 KisChunkAllocator::m_storeMaxSize
private

Definition at line 140 of file kis_chunk_allocator.h.

◆ m_storeSize

quint64 KisChunkAllocator::m_storeSize
private

Definition at line 146 of file kis_chunk_allocator.h.

◆ m_storeSlabSize

quint64 KisChunkAllocator::m_storeSlabSize
private

Definition at line 141 of file kis_chunk_allocator.h.


The documentation for this class was generated from the following files: