183 void CMemoryMonitor::FreeMemThresholdCrossedL() |
184 void CMemoryMonitor::FreeMemThresholdCrossedL() |
184 { |
185 { |
185 FUNC_LOG; |
186 FUNC_LOG; |
186 |
187 |
187 iActionTrigger = ERamRotation; |
188 iActionTrigger = ERamRotation; |
188 StartFreeSomeRamL(iGoodThreshold); |
189 StartFreeSomeRamL(iGoodRamThreshold, iGoodSwapThreshold); |
189 } |
190 } |
190 |
191 |
191 void CMemoryMonitor::HandleFocusedWgChangeL() |
192 void CMemoryMonitor::HandleFocusedWgChangeL() |
192 { |
193 { |
193 FUNC_LOG; |
194 FUNC_LOG; |
194 |
195 |
195 TInt oldGoodThreshold = iGoodThreshold; |
196 TInt oldGoodRamThreshold = iGoodRamThreshold; |
196 TInt oldLowThreshold = iLowThreshold; |
197 TInt oldLowRamThreshold = iLowRamThreshold; |
197 |
198 TInt oldGoodSwapThreshold = iGoodSwapThreshold; |
|
199 TInt oldLowSwapThreshold = iLowSwapThreshold; |
|
200 |
198 // Refresh the low and good memory thresholds as they may have changed due to the new foreground application |
201 // Refresh the low and good memory thresholds as they may have changed due to the new foreground application |
199 RefreshThresholds(); |
202 RefreshThresholds(); |
200 |
203 |
201 if ((oldGoodThreshold != iGoodThreshold) |
204 if ((oldGoodRamThreshold != iGoodRamThreshold) |
202 || (oldLowThreshold != iLowThreshold)) |
205 || (oldLowRamThreshold != iLowRamThreshold) |
|
206 || (oldGoodSwapThreshold != iGoodSwapThreshold) |
|
207 || (oldLowSwapThreshold != iLowSwapThreshold)) |
203 // If the thresholds have changed then update the memory watched |
208 // If the thresholds have changed then update the memory watched |
204 { |
209 { |
205 iOOMWatcher->UpdateThresholds(iLowThreshold, iGoodThreshold); |
210 iOOMWatcher->UpdateThresholds(iLowRamThreshold, iGoodRamThreshold, iLowSwapThreshold, iGoodSwapThreshold); |
206 } |
211 } |
207 |
212 |
208 // If the available memory is less than the low memory threshold then free some RAM |
213 // If the available memory is less than the low memory threshold then free some RAM |
209 User::CompressAllHeaps(); |
214 User::CompressAllHeaps(); |
210 TInt current = 0; |
215 TInt currentFreeRam = 0; |
211 HAL::Get( HALData::EMemoryRAMFree, current ); |
216 HAL::Get( HALData::EMemoryRAMFree, currentFreeRam ); |
212 |
217 TInt currentFreeSwap = 0; |
213 if (current < iLowThreshold) |
218 if (iConfig->GlobalConfig().iSwapUsageMonitored) |
|
219 { |
|
220 SVMSwapInfo swapInfo; |
|
221 UserSvr::HalFunction(EHalGroupVM, EVMHalGetSwapInfo, &swapInfo, 0); |
|
222 currentFreeSwap = swapInfo.iSwapFree; |
|
223 } |
|
224 |
|
225 if ((currentFreeRam < iLowRamThreshold) || |
|
226 (iConfig->GlobalConfig().iSwapUsageMonitored && (currentFreeSwap < iLowSwapThreshold))) |
214 { |
227 { |
215 iActionTrigger = ERamRotation; |
228 iActionTrigger = ERamRotation; |
216 StartFreeSomeRamL(iGoodThreshold); |
229 StartFreeSomeRamL(iGoodRamThreshold, iGoodSwapThreshold); |
217 } |
230 } |
218 } |
231 } |
219 |
232 |
220 void CMemoryMonitor::StartFreeSomeRamL(TInt aTargetFree) |
233 void CMemoryMonitor::StartFreeSomeRamL(TInt aFreeRamTarget, TInt aFreeSwapTarget) |
221 { |
234 { |
222 StartFreeSomeRamL(aTargetFree, KOomPriorityInfinate - 1); |
235 StartFreeSomeRamL(aFreeRamTarget, aFreeSwapTarget, KOomPriorityInfinate - 1); |
223 } |
236 } |
224 |
237 |
225 void CMemoryMonitor::StartFreeSomeRamL(TInt aTargetFree, TInt aMaxPriority) // The maximum priority of action to run |
238 void CMemoryMonitor::StartFreeSomeRamL(TInt aFreeRamTarget, TInt aFreeSwapTarget, TInt aMaxPriority) // The maximum priority of action to run |
226 { |
239 { |
227 FUNC_LOG; |
240 FUNC_LOG; |
228 |
241 |
229 TRACES2("MemoryMonitor::StartFreeSomeRamL: aTargetFree = %d, iCurrentTarget = %d", aTargetFree, iCurrentTarget); |
242 TRACES4("MemoryMonitor::StartFreeSomeRamL: aFreeRamTarget = %d, iCurrentRamTarget = %d, aFreeSwapSpaceTarget = %d, iCurrentSwapTarget = %d", aFreeRamTarget, iCurrentRamTarget, aFreeSwapTarget, iCurrentSwapTarget); |
230 |
243 |
231 // Update the target if new target is higher. If the target is lower than the current target and memory |
244 // Update the target if new target is higher. If the target is lower than the current target and memory |
232 // is currently being freed then we do not want to reduce the amount of memory this operation frees. |
245 // is currently being freed then we do not want to reduce the amount of memory this operation frees. |
233 if (aTargetFree > iCurrentTarget) |
246 if (aFreeRamTarget > iCurrentRamTarget) |
234 iCurrentTarget = aTargetFree; |
247 { |
|
248 iCurrentRamTarget = aFreeRamTarget; |
|
249 } |
|
250 |
|
251 if (aFreeSwapTarget > iCurrentSwapTarget) |
|
252 { |
|
253 iCurrentSwapTarget = aFreeSwapTarget; |
|
254 } |
235 |
255 |
236 // check if there is enough free memory already. |
256 // check if there is enough free memory already. |
237 TInt freeMemory; |
257 TInt freeMemory = 0; |
238 GetFreeMemory(freeMemory); |
258 GetFreeMemory(freeMemory); |
239 |
259 TInt freeSwap = 0; |
240 TRACES1("MemoryMonitor::StartFreeSomeRamL, freeMemory = %d", freeMemory); |
260 if (iConfig->GlobalConfig().iSwapUsageMonitored) |
241 |
261 { |
242 if (freeMemory >= iCurrentTarget) |
262 GetFreeSwapSpace(freeSwap); |
|
263 } |
|
264 |
|
265 TRACES2("MemoryMonitor::StartFreeSomeRamL, freeMemory = %d, freeSwap = %d", freeMemory, freeSwap); |
|
266 |
|
267 if ((freeMemory >= iCurrentRamTarget) && |
|
268 ((!iConfig->GlobalConfig().iSwapUsageMonitored) || (freeSwap >= iCurrentSwapTarget))) |
243 { |
269 { |
244 if (iLastMemoryMonitorStatusProperty != EFreeingMemory) |
270 if (iLastMemoryMonitorStatusProperty != EFreeingMemory) |
245 { |
271 { |
246 ResetTargets(); |
272 ResetTargets(); |
247 iOomActionList->SwitchOffPlugins(); |
273 iOomActionList->SwitchOffPlugins(); |
260 #endif |
286 #endif |
261 |
287 |
262 // Build the list of memory freeing actions |
288 // Build the list of memory freeing actions |
263 iOomActionList->BuildActionListL(*iOomWindowGroupList, *iConfig); |
289 iOomActionList->BuildActionListL(*iOomWindowGroupList, *iConfig); |
264 |
290 |
265 iOomActionList->SetCurrentTarget(iCurrentTarget); |
291 iOomActionList->SetCurrentTargets(iCurrentRamTarget, iCurrentSwapTarget); |
266 |
292 |
267 // Run the memory freeing actions |
293 // Run the memory freeing actions |
268 iOomActionList->FreeMemory(aMaxPriority); |
294 iOomActionList->FreeMemory(aMaxPriority); |
269 } |
295 } |
270 |
296 |
271 void CMemoryMonitor::RequestFreeMemoryPandSL(TInt aBytesRequested) |
297 void CMemoryMonitor::RequestFreeMemoryPandSL(TInt aBytesRequested) |
272 { |
298 { |
273 FUNC_LOG; |
299 FUNC_LOG; |
274 |
300 |
275 iActionTrigger = EPublishAndSubscribe; |
301 iActionTrigger = EPublishAndSubscribe; |
276 StartFreeSomeRamL(aBytesRequested + iLowThreshold); |
302 StartFreeSomeRamL(aBytesRequested + iLowRamThreshold, iLowSwapThreshold); |
277 } |
303 } |
278 |
304 |
279 void CMemoryMonitor::RequestFreeMemoryL(TInt aBytesRequested) |
305 void CMemoryMonitor::RequestFreeMemoryL(TInt aBytesRequested, TBool aDataPaged) |
280 { |
306 { |
281 FUNC_LOG; |
307 FUNC_LOG; |
282 |
308 |
283 iActionTrigger = EClientServerRequestFreeMemory; |
309 iActionTrigger = EClientServerRequestFreeMemory; |
284 StartFreeSomeRamL(aBytesRequested + iLowThreshold); |
310 iDataPaged = aDataPaged; |
285 } |
311 StartFreeSomeRamL(iLowRamThreshold, aBytesRequested + iLowSwapThreshold); |
286 |
312 } |
287 void CMemoryMonitor::FreeOptionalRamL(TInt aBytesRequested, TInt aPluginId) // The ID of the plugin that will clear up the allocation, used to determine the priority of the allocation |
313 |
|
314 void CMemoryMonitor::FreeOptionalRamL(TInt aBytesRequested, TInt aPluginId, TBool aDataPaged) // The ID of the plugin that will clear up the allocation, used to determine the priority of the allocation |
288 { |
315 { |
289 FUNC_LOG; |
316 FUNC_LOG; |
290 |
317 |
291 iActionTrigger = EClientServerRequestOptionalRam; |
318 iActionTrigger = EClientServerRequestOptionalRam; |
292 |
319 |
|
320 iDataPaged = aDataPaged; |
|
321 |
293 // Calculate the priority of the allocation (the priority of the plugin that will clear it up - 1) |
322 // Calculate the priority of the allocation (the priority of the plugin that will clear it up - 1) |
294 TInt priorityOfAllocation = iConfig->GetPluginConfig(aPluginId).CalculatePluginPriority(*iOomWindowGroupList) - 1; |
323 TInt priorityOfAllocation = iConfig->GetPluginConfig(aPluginId).CalculatePluginPriority(*iOomWindowGroupList) - 1; |
295 |
324 |
296 StartFreeSomeRamL(aBytesRequested + iGoodThreshold, priorityOfAllocation); |
325 StartFreeSomeRamL(aBytesRequested + iGoodRamThreshold, iLowSwapThreshold, priorityOfAllocation); |
297 } |
326 } |
298 |
327 |
299 void CMemoryMonitor::GetFreeMemory(TInt& aCurrentFreeMemory) |
328 void CMemoryMonitor::GetFreeMemory(TInt& aCurrentFreeMemory) |
300 { |
329 { |
301 FUNC_LOG; |
330 FUNC_LOG; |
356 FUNC_LOG; |
396 FUNC_LOG; |
357 |
397 |
358 iOomWindowGroupList->Refresh(); |
398 iOomWindowGroupList->Refresh(); |
359 |
399 |
360 // Calculate the desired good threshold, this could be the globally configured value... |
400 // Calculate the desired good threshold, this could be the globally configured value... |
361 iGoodThreshold = CMemoryMonitor::GlobalConfig().iGoodRamThreshold; |
401 iGoodRamThreshold = CMemoryMonitor::GlobalConfig().iGoodRamThreshold; |
362 iLowThreshold = CMemoryMonitor::GlobalConfig().iLowRamThreshold; |
402 iLowRamThreshold = CMemoryMonitor::GlobalConfig().iLowRamThreshold; |
363 TRACES2("CMemoryMonitor::RefreshThresholds: Global Good Threshold = %d, Global Low Threshold = %d", iGoodThreshold, iLowThreshold); |
403 iGoodSwapThreshold = CMemoryMonitor::GlobalConfig().iGoodSwapThreshold; |
|
404 iLowSwapThreshold = CMemoryMonitor::GlobalConfig().iLowSwapThreshold; |
|
405 TRACES4("CMemoryMonitor::RefreshThresholds: Global Good Ram Threshold = %d, Global Low Ram Threshold = %d, Global Good Swap Threshold = %d, Global Low Swap Threshold = %d", iGoodRamThreshold, iLowRamThreshold, iGoodSwapThreshold, iLowSwapThreshold); |
364 |
406 |
365 #ifdef _DEBUG |
407 #ifdef _DEBUG |
366 TRACES("CMemoryMonitor::RefreshThresholds: Dumping Window Group List"); |
408 TRACES("CMemoryMonitor::RefreshThresholds: Dumping Window Group List"); |
367 TInt wgIndex = iOomWindowGroupList->Count() - 1; |
409 TInt wgIndex = iOomWindowGroupList->Count() - 1; |
368 while (wgIndex >= 0) |
410 while (wgIndex >= 0) |
391 } |
433 } |
392 |
434 |
393 // If this application configuration overrides the good_ram_threshold then set it |
435 // If this application configuration overrides the good_ram_threshold then set it |
394 if (iConfig->GetApplicationConfig(foregroundAppId).iGoodRamThreshold != KOomThresholdUnset) |
436 if (iConfig->GetApplicationConfig(foregroundAppId).iGoodRamThreshold != KOomThresholdUnset) |
395 { |
437 { |
396 iGoodThreshold = iConfig->GetApplicationConfig(foregroundAppId).iGoodRamThreshold; |
438 iGoodRamThreshold = iConfig->GetApplicationConfig(foregroundAppId).iGoodRamThreshold; |
397 TRACES2("CMemoryMonitor::RefreshThresholds: For foreground app %x, Good Threshold = %d", foregroundAppId, iGoodThreshold); |
439 TRACES2("CMemoryMonitor::RefreshThresholds: For foreground app %x, Good Ram Threshold = %d", foregroundAppId, iGoodRamThreshold); |
398 } |
440 } |
399 // If this application configuration overrides the low_ram_threshold then set it |
441 // If this application configuration overrides the low_ram_threshold then set it |
400 if (iConfig->GetApplicationConfig(foregroundAppId).iLowRamThreshold != KOomThresholdUnset) |
442 if (iConfig->GetApplicationConfig(foregroundAppId).iLowRamThreshold != KOomThresholdUnset) |
401 { |
443 { |
402 iLowThreshold = iConfig->GetApplicationConfig(foregroundAppId).iLowRamThreshold; |
444 iLowRamThreshold = iConfig->GetApplicationConfig(foregroundAppId).iLowRamThreshold; |
403 TRACES2("CMemoryMonitor::RefreshThresholds: For foreground app %x, Low Threshold = %d", foregroundAppId, iLowThreshold); |
445 TRACES2("CMemoryMonitor::RefreshThresholds: For foreground app %x, Low Ram Threshold = %d", foregroundAppId, iLowRamThreshold); |
404 } |
446 } |
405 |
447 |
|
448 if (iConfig->GetApplicationConfig(foregroundAppId).iGoodSwapThreshold != KOomThresholdUnset) |
|
449 { |
|
450 iGoodSwapThreshold = iConfig->GetApplicationConfig(foregroundAppId).iGoodSwapThreshold; |
|
451 TRACES2("CMemoryMonitor::RefreshThresholds: For foreground app %x, Good Swap Threshold = %d", foregroundAppId, iGoodSwapThreshold); |
|
452 } |
|
453 // If this application configuration overrides the low_swap_threshold then set it |
|
454 if (iConfig->GetApplicationConfig(foregroundAppId).iLowSwapThreshold != KOomThresholdUnset) |
|
455 { |
|
456 iLowSwapThreshold = iConfig->GetApplicationConfig(foregroundAppId).iLowSwapThreshold; |
|
457 TRACES2("CMemoryMonitor::RefreshThresholds: For foreground app %x, Low Swap Threshold = %d", foregroundAppId, iLowSwapThreshold); |
|
458 } |
406 } |
459 } |
407 } |
460 } |
408 |
461 |
409 // SetMemoryMonitorStatusProperty - updates the property value only if it has changed |
462 // SetMemoryMonitorStatusProperty - updates the property value only if it has changed |
410 void CMemoryMonitor::SetMemoryMonitorStatusProperty(const TMemoryMonitorStatusPropertyValues aValue) |
463 void CMemoryMonitor::SetMemoryMonitorStatusProperty(const TMemoryMonitorStatusPropertyValues aValue) |