diff -r 5e7d68cc22e0 -r 0818dd463d41 sysresmonitoring/oommonitor/src/oomactionlist.cpp --- a/sysresmonitoring/oommonitor/src/oomactionlist.cpp Thu Jul 15 18:49:38 2010 +0300 +++ b/sysresmonitoring/oommonitor/src/oomactionlist.cpp Thu Aug 19 10:05:08 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -327,10 +327,16 @@ TInt maxBatchSize = globalConfig.iMaxCloseAppBatch; TInt numberOfRunningActions = 0; - TInt memoryEstimate; // The amount of free memory we expect to be free after the currently initiated operations - HAL::Get(HALData::EMemoryRAMFree, memoryEstimate); - - + TInt freeRamEstimate = 0; // The amount of free memory we expect to be free after the currently initiated operations + HAL::Get(HALData::EMemoryRAMFree, freeRamEstimate); + TUint64 freeSwapEstimate = 0; + if (iSwapUsageMonitored) + { + SVMSwapInfo swapInfo; + UserSvr::HalFunction(EHalGroupVM, EVMHalGetSwapInfo, &swapInfo, 0); + freeSwapEstimate = swapInfo.iSwapFree; + } + while (iCurrentActionIndex < iActionRefs.Count() && iActionRefs[iCurrentActionIndex].Priority() <= aMaxPriority) { @@ -351,7 +357,20 @@ iMonitor.SetMemoryMonitorStatusProperty(EFreeingMemory); - action->FreeMemory(iCurrentTarget - memoryEstimate); + // At the moment the actions don't make any difference between freeing + // RAM and freeing swap. So we try to free the biggest of the two. + // Until the plugins are updated to make a distinction between swap and RAM this is the best + // we can do. For application close actions the amount to try to free is ignored anyway. + TUint amountToTryToFree = 0; + if (iCurrentRamTarget > freeRamEstimate) + { + amountToTryToFree = iCurrentRamTarget - freeRamEstimate; + } + if (iSwapUsageMonitored && (iCurrentSwapTarget > freeSwapEstimate) && ((iCurrentSwapTarget - freeSwapEstimate) > amountToTryToFree)) + { + amountToTryToFree = iCurrentSwapTarget - freeSwapEstimate; + } + action->FreeMemory(amountToTryToFree, iMonitor.iDataPaged); memoryFreeingActionRun = ETrue; // Actions with EContinueIgnoreMaxBatchSize don't add to the tally of running actions @@ -359,12 +378,12 @@ numberOfRunningActions++; // Update our estimate of how much RAM we think we'll have after this operation - memoryEstimate += ref.RamEstimate(); + freeRamEstimate += ref.RamEstimate(); // Do we estimate that we are freeing enough memory (only applies if the sync mode is "esimtate" for this action) TBool estimatedEnoughMemoryFreed = EFalse; if ((ref.SyncMode() == EEstimate) - && (memoryEstimate >= iCurrentTarget)) + && (freeRamEstimate >= iCurrentRamTarget)) { estimatedEnoughMemoryFreed = ETrue; } @@ -391,9 +410,15 @@ // No usable memory freeing action has been found, so we give up TRACES("COomActionList::FreeMemory: No usable memory freeing action has been found"); iMonitor.ResetTargets(); - TInt freeMemory; + TInt freeMemory = 0; iMonitor.GetFreeMemory(freeMemory); - if (freeMemory >= iCurrentTarget) + TInt freeSwap = 0; + if (iSwapUsageMonitored) + { + iMonitor.GetFreeSwapSpace(freeSwap); + } + if ((freeMemory >= iCurrentRamTarget) && + ((!iSwapUsageMonitored) || (freeSwap >= iCurrentSwapTarget))) { SwitchOffPlugins(); iMonitor.SetMemoryMonitorStatusProperty(EAboveTreshHold); @@ -570,9 +595,15 @@ //and therefore we are still in a memory freeing state iFreeingMemory = EFalse; // If all of the actions are complete then check memory and run more if necessary - TInt freeMemory; + TInt freeMemory = 0; iMonitor.GetFreeMemory(freeMemory); - if (freeMemory < iCurrentTarget) + TInt freeSwap = 0; + if (iSwapUsageMonitored) + { + iMonitor.GetFreeSwapSpace(freeSwap); + } + if ((freeMemory < iCurrentRamTarget) || + (iSwapUsageMonitored && (freeSwap < iCurrentSwapTarget))) // If we are still below the good-memory-threshold then continue running actions { iCurrentActionIndex++; @@ -582,7 +613,8 @@ // There are no more actions to try, so we give up TRACES1("COomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory); iMonitor.ResetTargets(); - if (freeMemory >= iCurrentTarget) + if ((freeMemory >= iCurrentRamTarget) && + ((!iSwapUsageMonitored) || (freeSwap >= iCurrentSwapTarget))) { SwitchOffPlugins(); iMonitor.SetMemoryMonitorStatusProperty(EAboveTreshHold); @@ -637,6 +669,7 @@ FUNC_LOG; iCurrentActionIndex = 0; + iSwapUsageMonitored = aConfig.GlobalConfig().iSwapUsageMonitored; iFreeingMemory = EFalse; // Get the list of V1 and V2 plugins available to the system @@ -663,7 +696,7 @@ COomRunPluginConfig& pluginConfig = aConfig.GetPluginConfig(iPluginListV2->Uid(pluginIndex)); // Create an action acording to the config - COomRunPlugin* action = COomRunPlugin::NewL(iPluginList->Uid(pluginIndex), pluginConfig, *this, iPluginListV2->Implementation(pluginIndex), &(iPluginListV2->Implementation(pluginIndex))); + COomRunPlugin* action = COomRunPlugin::NewL(iPluginListV2->Uid(pluginIndex), pluginConfig, *this, iPluginListV2->Implementation(pluginIndex), &(iPluginListV2->Implementation(pluginIndex))); iRunPluginActions.AppendL(action); }