25#define DEBUG_CLONE_ACTION(td, numClones) \
26 printf("Cloned (%d):\t\t\t\t0x%X (clones: %d, users: %d, refs: %d)\n", \
27 numClones, td, td->m_clonesStack.size(), \
28 (int)td->m_usersCount, (int)td->m_refCount)
29#define DEBUG_SIMPLE_ACTION(action) \
30 printf("pooler: %s\n", action)
32#define RUNTIME_SANITY_CHECK(td) do { \
33 if(td->m_usersCount < td->m_refCount) { \
34 qInfo("**** Suspicious tiledata: 0x%X (clones: %d, users: %d, refs: %d) ****", \
35 td, td->m_clonesStack.size(), \
36 (int)td->m_usersCount, (int)td->m_refCount); \
38 if(td->m_usersCount <= 0) { \
39 qFatal("pooler: Tiledata 0x%X has zero users counter. Crashing...", td); \
43#define DEBUG_TILE_STATISTICS() debugTileStatistics()
45#define DEBUG_LISTS(mem, beggars, beggarsMem, donors, donorsMem) \
47 dbgKrita << "--- getLists finished ---"; \
48 dbgKrita << " memoryOccupied:" << mem << "/" << m_memoryLimit; \
49 dbgKrita << " donors:" << donors.size() \
50 << "(mem:" << donorsMem << ")"; \
51 dbgKrita << " beggars:" << beggars.size() \
52 << "(mem:" << beggarsMem << ")"; \
53 dbgKrita << "--- ----------------- ---"; \
56#define DEBUG_ALLOC_CLONE(mem, totalMem) \
57 dbgKrita << "Alloc mem for clones:" << mem \
58 << "\tMem usage:" << totalMem << "/" << m_memoryLimit
60#define DEBUG_FREE_CLONE(freed, demanded) \
61 dbgKrita << "Freed mem for clones:" << freed \
62 << "/" << qAbs(demanded)
65#define DEBUG_CLONE_ACTION(td, numClones)
66#define DEBUG_SIMPLE_ACTION(action)
67#define RUNTIME_SANITY_CHECK(td)
68#define DEBUG_TILE_STATISTICS()
69#define DEBUG_LISTS(mem, beggars, beggarsMem, donors, donorsMem) \
72 Q_UNUSED(beggarsMem); \
75#define DEBUG_ALLOC_CLONE(mem, totalMem)
76#define DEBUG_FREE_CLONE(freed, demanded)
91 if(memoryLimit >= 0) {
110 unsigned long exitTimeout = 100;
114 }
while(!wait(exitTimeout));
124 return totalClones - numPresentClones;
131 for (qint32 i = 0; i < numClones; i++) {
136 qint32 numUnneededClones = qAbs(numClones);
137 for (qint32 i = 0; i < numUnneededClones; i++) {
191 qint32 memoryOccupied;
193 qint32 statRealMemory;
194 qint32 statHistoricalMemory;
200 statHistoricalMemory);
223 qint32 memoryOccupied;
225 qint32 statRealMemory;
226 qint32 statHistoricalMemory;
232 statHistoricalMemory);
268 if(extraClones > 0) {
288 qint32 &memoryOccupied,
289 qint32 &statRealMemory,
290 qint32 &statHistoricalMemory)
294 statHistoricalMemory = 0;
296 qint32 needMemoryTotal = 0;
297 qint32 canDonorMemoryTotal = 0;
300 qint32 donoredMemory;
304 while(iter->hasNext()) {
310 needMemoryTotal += neededMemory;
311 beggars.append(item);
314 canDonorMemoryTotal += donoredMemory;
322 statHistoricalMemory += item->
pixelSize();
329 beggars, needMemoryTotal,
330 donors, canDonorMemoryTotal);
336 qint32 memoryFreed = 0;
338 QMutableListIterator<KisTileData*> iter(donors);
341 while(iter.hasPrevious() && memoryFreed < memoryMetric) {
356 qint32 &memoryOccupied)
358 bool hadWork =
false;
370 memoryOccupied -= freedMemory;
381 memoryOccupied += clonesMemory;
395 qint64 preallocatedTiles=0;
~KisTileDataPooler() override
static const qint32 MAX_NUM_CLONES
qint64 lastRealMemoryMetric() const
qint32 m_lastRealMemoryMetric
QAtomicInt m_shouldExitFlag
bool processLists(QList< KisTileData * > &beggars, QList< KisTileData * > &donors, qint32 &memoryOccupied)
qint32 numClonesNeeded(KisTileData *td) const
qint32 canDonorMemory(KisTileData *td)
static const qint32 TIMEOUT_FACTOR
void testingRereadConfig()
qint32 m_lastPoolMemoryMetric
void tryFreeOrphanedClones(KisTileData *td)
qint64 lastHistoricalMemoryMetric() const
qint32 needMemory(KisTileData *td)
void debugTileStatistics()
KisTileDataStore * m_store
static const qint32 MIN_TIMEOUT
qint64 lastPoolMemoryMetric() const
KisTileDataPooler(KisTileDataStore *store, qint32 memoryLimit=-1)
static const qint32 MAX_TIMEOUT
void getLists(Iter *iter, QList< KisTileData * > &beggars, QList< KisTileData * > &donors, qint32 &memoryOccupied, qint32 &statRealMemory, qint32 &statHistoricalMemory)
qint32 tryGetMemory(QList< KisTileData * > &donors, qint32 memoryMetric)
qint32 m_lastHistoricalMemoryMetric
void cloneTileData(KisTileData *td, qint32 numClones) const
int clonesMetric(KisTileData *td, int numClones)
void forceUpdateMemoryStats()
void endIteration(KisTileDataStoreIterator *iterator)
KisTileDataStoreIterator * beginIteration()
KisTileDataStoreReverseIterator * beginReverseIteration()
quint32 pixelSize() const
KisTileDataCache m_clonesStack
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define DEBUG_ALLOC_CLONE(mem, totalMem)
#define DEBUG_FREE_CLONE(freed, demanded)
#define DEBUG_TILE_STATISTICS()
#define DEBUG_SIMPLE_ACTION(action)
#define RUNTIME_SANITY_CHECK(td)
#define DEBUG_CLONE_ACTION(td, numClones)
#define DEBUG_LISTS(mem, beggars, beggarsMem, donors, donorsMem)