234 else//if aThreshold == EGL_PROF_TOTAL_MEMORY_USAGE_GT_NOK |
234 else//if aThreshold == EGL_PROF_TOTAL_MEMORY_USAGE_GT_NOK |
235 { |
235 { |
236 TRACES1("FreeMemThresholdCrossedL : crossed low threshold %d", iLowThreshold); |
236 TRACES1("FreeMemThresholdCrossedL : crossed low threshold %d", iLowThreshold); |
237 iMemAllocationsGrowing->Stop(); |
237 iMemAllocationsGrowing->Stop(); |
238 iMemAllocationsGoingDown->Continue(); |
238 iMemAllocationsGoingDown->Continue(); |
239 StartFreeSomeRamL(iGoodThreshold, EGOomThresholdCrossed); |
239 if(iTrigger == EGOomTriggerNone) |
|
240 StartFreeSomeRamL(iGoodThreshold, EGOomTriggerThresholdCrossed); |
240 } |
241 } |
241 #endif |
242 #endif |
242 } |
243 } |
243 |
244 |
244 void CMemoryMonitor::HandleFocusedWgChangeL(TInt aForegroundAppUid) |
245 void CMemoryMonitor::HandleFocusedWgChangeL(TInt aForegroundAppUid) |
255 |
256 |
256 // Refresh the low and good memory thresholds as they may have changed due to the new foreground application |
257 // Refresh the low and good memory thresholds as they may have changed due to the new foreground application |
257 RefreshThresholds(aForegroundAppUid); |
258 RefreshThresholds(aForegroundAppUid); |
258 // Not very elegant, now we poll on each window group change |
259 // Not very elegant, now we poll on each window group change |
259 // Should have better trigger e.g. from window server |
260 // Should have better trigger e.g. from window server |
260 StartFreeSomeRamL(iCurrentTarget, EGOomFocusChanged); |
261 StartFreeSomeRamL(iCurrentTarget, EGOomTriggerFocusChanged); |
261 } |
262 } |
262 |
263 |
263 void CMemoryMonitor::StartFreeSomeRamL(TInt aTargetFree, TInt aMaxPriority, TGOomTrigger aTrigger) // The maximum priority of action to run |
264 void CMemoryMonitor::StartFreeSomeRamL(TInt aTargetFree, TInt aMaxPriority, TGOomTrigger aTrigger) // The maximum priority of action to run |
264 { |
265 { |
265 FUNC_LOG; |
266 FUNC_LOG; |
331 |
332 |
332 void CMemoryMonitor::RequestFreeMemoryL(TInt aTargetFree, TBool aUseAbsolute) |
333 void CMemoryMonitor::RequestFreeMemoryL(TInt aTargetFree, TBool aUseAbsolute) |
333 { |
334 { |
334 FUNC_LOG; |
335 FUNC_LOG; |
335 |
336 |
336 StartFreeSomeRamL(aUseAbsolute?aTargetFree:(aTargetFree + iLowThreshold), KGOomPriorityInfinate - 1, EGOomRequestMemory); |
337 StartFreeSomeRamL(aUseAbsolute?aTargetFree:(aTargetFree + iLowThreshold), KGOomPriorityInfinate - 1, EGOomTriggerRequestMemory); |
337 } |
338 } |
338 |
339 |
339 void CMemoryMonitor::FreeOptionalRamL(TInt aTargetFree, TInt aPluginId, TBool aUseAbsolute) // The ID of the plugin that will clear up the allocation, used to determine the priority of the allocation |
340 void CMemoryMonitor::FreeOptionalRamL(TInt aTargetFree, TInt aPluginId, TBool aUseAbsolute) // The ID of the plugin that will clear up the allocation, used to determine the priority of the allocation |
340 { |
341 { |
341 FUNC_LOG; |
342 FUNC_LOG; |
342 |
343 |
343 // Calculate the priority of the allocation (the priority of the plugin that will clear it up - 1) |
344 // Calculate the priority of the allocation (the priority of the plugin that will clear it up - 1) |
344 TInt priorityOfAllocation = iConfig->GetPluginConfig(aPluginId).CalculatePluginPriority(*iGOomWindowGroupList) - 1; |
345 TInt priorityOfAllocation = iConfig->GetPluginConfig(aPluginId).CalculatePluginPriority(*iGOomWindowGroupList) - 1; |
345 StartFreeSomeRamL(aUseAbsolute?aTargetFree:(aTargetFree + iGoodThreshold), priorityOfAllocation, EGOomRequestMemory); |
346 StartFreeSomeRamL(aUseAbsolute?aTargetFree:(aTargetFree + iGoodThreshold), priorityOfAllocation, EGOomTriggerRequestMemory); |
346 } |
347 } |
347 |
348 |
348 // Does the EGL extension return the amount of memory in bits? |
349 // Does the EGL extension return the amount of memory in bits? |
349 // If yes, int is clearly not enough |
350 // If yes, int is clearly not enough |
350 // Note that this function reserves memory so it can fail if the "standard" memory |
351 // Note that this function reserves memory so it can fail if the "standard" memory |
381 TInt origLow = iLowThreshold; |
382 TInt origLow = iLowThreshold; |
382 |
383 |
383 // Calculate the desired good threshold, this could be the globally configured value... |
384 // Calculate the desired good threshold, this could be the globally configured value... |
384 iGoodThreshold = CMemoryMonitor::GlobalConfig().iGoodRamThreshold; |
385 iGoodThreshold = CMemoryMonitor::GlobalConfig().iGoodRamThreshold; |
385 iLowThreshold = CMemoryMonitor::GlobalConfig().iLowRamThreshold; |
386 iLowThreshold = CMemoryMonitor::GlobalConfig().iLowRamThreshold; |
386 iCurrentTarget = iGoodThreshold; |
387 if(iCurrentTarget < iLowThreshold) |
|
388 iCurrentTarget = iLowThreshold; |
387 |
389 |
388 TRACES2("CMemoryMonitor::RefreshThresholds: Global Good Threshold = %d, Global Low Threshold = %d", iGoodThreshold, iLowThreshold); |
390 TRACES2("CMemoryMonitor::RefreshThresholds: Global Good Threshold = %d, Global Low Threshold = %d", iGoodThreshold, iLowThreshold); |
389 |
391 |
390 // The global value can be overridden by an app specific value |
392 // The global value can be overridden by an app specific value |
391 // Find the application config entry for the foreground application |
393 // Find the application config entry for the foreground application |
467 |
469 |
468 //we reset the target when a memory free operation completes, to deal with the case |
470 //we reset the target when a memory free operation completes, to deal with the case |
469 //where the operation was initiated with a target larger than the current good threshold |
471 //where the operation was initiated with a target larger than the current good threshold |
470 iCurrentTarget = aTarget; |
472 iCurrentTarget = aTarget; |
471 iGOomActionList->SetCurrentTarget(iCurrentTarget); |
473 iGOomActionList->SetCurrentTarget(iCurrentTarget); |
|
474 if(!aTarget) |
|
475 iTrigger = EGOomTriggerNone; //reset the trigger condition |
472 } |
476 } |
473 |
477 |
474 void CMemoryMonitor::SetPriorityBusy(TInt aWgId) |
478 void CMemoryMonitor::SetPriorityBusy(TInt aWgId) |
475 { |
479 { |
476 FUNC_LOG; |
480 FUNC_LOG; |
619 TInt current = GetFreeMemory(); |
623 TInt current = GetFreeMemory(); |
620 if(current >= iGoodThreshold) |
624 if(current >= iGoodThreshold) |
621 { |
625 { |
622 if(!NeedToPostponeMemGood()) |
626 if(!NeedToPostponeMemGood()) |
623 { |
627 { |
624 TRACES("DoPostponedMemoryGood calling MemoryGOOD"); |
628 TRACES2("DoPostponedMemoryGood calling MemoryGOOD current %d, iGoodThreshold %d",current, iGoodThreshold); |
625 iGOomActionList->MemoryGood(); |
629 iGOomActionList->MemoryGood(); |
626 } |
630 } |
627 else |
631 else |
628 { |
632 { |
629 iMemAllocationsGoingDown->Continue(); |
633 iMemAllocationsGoingDown->Continue(); |
715 { |
719 { |
716 FUNC_LOG; |
720 FUNC_LOG; |
717 |
721 |
718 switch (iTrigger) |
722 switch (iTrigger) |
719 { |
723 { |
720 case EGOomThresholdCrossed: |
724 case EGOomTriggerThresholdCrossed: |
721 { |
725 { |
722 //Call memory good if we are good. |
726 //Call memory good if we are good. |
723 DoPostponedMemoryGood(); |
727 DoPostponedMemoryGood(); |
724 break; |
728 break; |
725 } |
729 } |
726 case EGOomFocusChanged: |
730 case EGOomTriggerFocusChanged: |
727 case EGOomRequestMemory: |
731 case EGOomTriggerRequestMemory: |
728 { |
732 { |
729 //start timer |
733 //start timer |
730 //cancel timer if end critical allocations request |
734 //cancel timer if end critical allocations request -TODO |
731 //end critical allocations when timer expires |
735 //end critical allocations when timer expires -TODO |
732 if ( iSynchTimer && //exists |
736 if ( iSynchTimer && //exists |
733 !iSynchTimer->IsActive() ) // keep it simple |
737 !iSynchTimer->IsActive() ) // keep it simple |
734 { |
738 { |
735 iSynchTimer->After(KGoomWaitTimeToSynch); |
739 iSynchTimer->Cancel(); |
|
740 iSynchTimer->After(KGoomWaitTimeToSynch); |
736 } |
741 } |
737 break; |
742 break; |
738 } |
743 } |
739 } |
744 } |
|
745 ResetTargets(); |
740 } |
746 } |
741 |
747 |
742 void CMemoryMonitor::SynchroniseMemoryState() |
748 void CMemoryMonitor::SynchroniseMemoryState() |
743 { |
749 { |
744 FUNC_LOG; |
750 FUNC_LOG; |