sysresmonitoring/oommonitor/src/oomactionlist.cpp
branchRCL_3
changeset 18 0818dd463d41
parent 1 0fdb7f6b0309
child 19 924385140d98
equal deleted inserted replaced
17:5e7d68cc22e0 18:0818dd463d41
     1 /*
     1 /*
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   325     // Get the configured maximum number of applications that can be closed at one time
   325     // Get the configured maximum number of applications that can be closed at one time
   326     const COomGlobalConfig& globalConfig = CMemoryMonitor::GlobalConfig();
   326     const COomGlobalConfig& globalConfig = CMemoryMonitor::GlobalConfig();
   327     TInt maxBatchSize = globalConfig.iMaxCloseAppBatch;
   327     TInt maxBatchSize = globalConfig.iMaxCloseAppBatch;
   328     TInt numberOfRunningActions = 0;
   328     TInt numberOfRunningActions = 0;
   329     
   329     
   330     TInt memoryEstimate; // The amount of free memory we expect to be free after the currently initiated operations
   330     TInt freeRamEstimate = 0; // The amount of free memory we expect to be free after the currently initiated operations
   331     HAL::Get(HALData::EMemoryRAMFree, memoryEstimate); 
   331     HAL::Get(HALData::EMemoryRAMFree, freeRamEstimate);
   332     
   332     TUint64 freeSwapEstimate = 0;
   333      
   333     if (iSwapUsageMonitored)
       
   334         {
       
   335         SVMSwapInfo swapInfo;
       
   336         UserSvr::HalFunction(EHalGroupVM, EVMHalGetSwapInfo, &swapInfo, 0);
       
   337         freeSwapEstimate = swapInfo.iSwapFree;
       
   338         }
       
   339         
   334     while (iCurrentActionIndex < iActionRefs.Count() 
   340     while (iCurrentActionIndex < iActionRefs.Count() 
   335             && iActionRefs[iCurrentActionIndex].Priority() <= aMaxPriority)
   341             && iActionRefs[iCurrentActionIndex].Priority() <= aMaxPriority)
   336         {
   342         {
   337         TActionRef ref = iActionRefs[iCurrentActionIndex];
   343         TActionRef ref = iActionRefs[iCurrentActionIndex];
   338         COomAction* action = NULL;
   344         COomAction* action = NULL;
   349         iFreeingMemory = ETrue;
   355         iFreeingMemory = ETrue;
   350         TRACES2("COomActionList::FreeMemory: Running action %d which has priority %d", iCurrentActionIndex,ref.Priority());
   356         TRACES2("COomActionList::FreeMemory: Running action %d which has priority %d", iCurrentActionIndex,ref.Priority());
   351         
   357         
   352         iMonitor.SetMemoryMonitorStatusProperty(EFreeingMemory);
   358         iMonitor.SetMemoryMonitorStatusProperty(EFreeingMemory);
   353         
   359         
   354         action->FreeMemory(iCurrentTarget - memoryEstimate);
   360         // At the moment the actions don't make any difference between freeing
       
   361         // RAM and freeing swap. So we try to free the biggest of the two.
       
   362         // Until the plugins are updated to make a distinction between swap and RAM this is the best
       
   363         // we can do. For application close actions the amount to try to free is ignored anyway.
       
   364         TUint amountToTryToFree = 0;
       
   365 		if (iCurrentRamTarget > freeRamEstimate)
       
   366 			{
       
   367 			amountToTryToFree = iCurrentRamTarget - freeRamEstimate;
       
   368 			}
       
   369         if (iSwapUsageMonitored && (iCurrentSwapTarget > freeSwapEstimate) && ((iCurrentSwapTarget - freeSwapEstimate) > amountToTryToFree))
       
   370             {
       
   371             amountToTryToFree = iCurrentSwapTarget - freeSwapEstimate;
       
   372             }
       
   373         action->FreeMemory(amountToTryToFree, iMonitor.iDataPaged);
   355         memoryFreeingActionRun = ETrue;
   374         memoryFreeingActionRun = ETrue;
   356                 
   375                 
   357         // Actions with EContinueIgnoreMaxBatchSize don't add to the tally of running actions
   376         // Actions with EContinueIgnoreMaxBatchSize don't add to the tally of running actions
   358         if (ref.SyncMode() != EContinueIgnoreMaxBatchSize)
   377         if (ref.SyncMode() != EContinueIgnoreMaxBatchSize)
   359             numberOfRunningActions++;
   378             numberOfRunningActions++;
   360         
   379         
   361         // Update our estimate of how much RAM we think we'll have after this operation
   380         // Update our estimate of how much RAM we think we'll have after this operation
   362         memoryEstimate += ref.RamEstimate();
   381         freeRamEstimate += ref.RamEstimate();
   363          
   382          
   364         // Do we estimate that we are freeing enough memory (only applies if the sync mode is "esimtate" for this action)
   383         // Do we estimate that we are freeing enough memory (only applies if the sync mode is "esimtate" for this action)
   365         TBool estimatedEnoughMemoryFreed = EFalse;
   384         TBool estimatedEnoughMemoryFreed = EFalse;
   366         if ((ref.SyncMode() == EEstimate)
   385         if ((ref.SyncMode() == EEstimate)
   367             && (memoryEstimate >= iCurrentTarget))
   386             && (freeRamEstimate >= iCurrentRamTarget))
   368             {
   387             {
   369             estimatedEnoughMemoryFreed = ETrue;
   388             estimatedEnoughMemoryFreed = ETrue;
   370             }
   389             }
   371         
   390         
   372         if ((ref.SyncMode() == ECheckRam)
   391         if ((ref.SyncMode() == ECheckRam)
   389     if (!memoryFreeingActionRun)
   408     if (!memoryFreeingActionRun)
   390         {
   409         {
   391         // No usable memory freeing action has been found, so we give up
   410         // No usable memory freeing action has been found, so we give up
   392         TRACES("COomActionList::FreeMemory: No usable memory freeing action has been found");
   411         TRACES("COomActionList::FreeMemory: No usable memory freeing action has been found");
   393         iMonitor.ResetTargets();
   412         iMonitor.ResetTargets();
   394         TInt freeMemory;
   413         TInt freeMemory = 0;
   395         iMonitor.GetFreeMemory(freeMemory);
   414         iMonitor.GetFreeMemory(freeMemory);
   396         if (freeMemory >= iCurrentTarget)
   415         TInt freeSwap = 0;
       
   416         if (iSwapUsageMonitored)
       
   417             {
       
   418             iMonitor.GetFreeSwapSpace(freeSwap);
       
   419             }
       
   420         if ((freeMemory >= iCurrentRamTarget) &&
       
   421             ((!iSwapUsageMonitored) || (freeSwap >= iCurrentSwapTarget)))
   397             {
   422             {
   398             SwitchOffPlugins();
   423             SwitchOffPlugins();
   399             iMonitor.SetMemoryMonitorStatusProperty(EAboveTreshHold);
   424             iMonitor.SetMemoryMonitorStatusProperty(EAboveTreshHold);
   400             }
   425             }
   401         else
   426         else
   568         //SetMemoryMonitorStatusProperty will not change here because it is possible for the freeing actions to recommence
   593         //SetMemoryMonitorStatusProperty will not change here because it is possible for the freeing actions to recommence
   569         //in essence, all immediate actions have been completed but not all possible actions have been processed 
   594         //in essence, all immediate actions have been completed but not all possible actions have been processed 
   570         //and therefore we are still in a memory freeing state
   595         //and therefore we are still in a memory freeing state
   571         iFreeingMemory = EFalse;
   596         iFreeingMemory = EFalse;
   572         // If all of the actions are complete then check memory and run more if necessary
   597         // If all of the actions are complete then check memory and run more if necessary
   573         TInt freeMemory;
   598         TInt freeMemory = 0;
   574         iMonitor.GetFreeMemory(freeMemory);
   599         iMonitor.GetFreeMemory(freeMemory);
   575         if (freeMemory < iCurrentTarget)
   600         TInt freeSwap = 0;
       
   601         if (iSwapUsageMonitored)
       
   602             {
       
   603             iMonitor.GetFreeSwapSpace(freeSwap);
       
   604             }
       
   605         if ((freeMemory < iCurrentRamTarget) ||
       
   606             (iSwapUsageMonitored && (freeSwap < iCurrentSwapTarget)))
   576             // If we are still below the good-memory-threshold then continue running actions
   607             // If we are still below the good-memory-threshold then continue running actions
   577             {
   608             {
   578             iCurrentActionIndex++;
   609             iCurrentActionIndex++;
   579             
   610             
   580             if (iCurrentActionIndex >= iActionRefs.Count())
   611             if (iCurrentActionIndex >= iActionRefs.Count())
   581                 {
   612                 {
   582                 // There are no more actions to try, so we give up
   613                 // There are no more actions to try, so we give up
   583                 TRACES1("COomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory);
   614                 TRACES1("COomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory);
   584                 iMonitor.ResetTargets();
   615                 iMonitor.ResetTargets();
   585                 if (freeMemory >= iCurrentTarget)
   616                 if ((freeMemory >= iCurrentRamTarget) &&
       
   617                     ((!iSwapUsageMonitored) || (freeSwap >= iCurrentSwapTarget)))
   586                     {
   618                     {
   587                     SwitchOffPlugins();
   619                     SwitchOffPlugins();
   588                     iMonitor.SetMemoryMonitorStatusProperty(EAboveTreshHold);
   620                     iMonitor.SetMemoryMonitorStatusProperty(EAboveTreshHold);
   589                     }
   621                     }
   590                 else
   622                 else
   635 void COomActionList::ConstructL(COomConfig& aConfig)
   667 void COomActionList::ConstructL(COomConfig& aConfig)
   636     {
   668     {
   637     FUNC_LOG;
   669     FUNC_LOG;
   638     
   670     
   639     iCurrentActionIndex = 0;
   671     iCurrentActionIndex = 0;
       
   672     iSwapUsageMonitored = aConfig.GlobalConfig().iSwapUsageMonitored;
   640     iFreeingMemory = EFalse;
   673     iFreeingMemory = EFalse;
   641     
   674     
   642     // Get the list of V1 and V2 plugins available to the system
   675     // Get the list of V1 and V2 plugins available to the system
   643     iPluginList = COomPluginList<COomMonitorPlugin>::NewL(KOomPluginInterfaceUidValue);
   676     iPluginList = COomPluginList<COomMonitorPlugin>::NewL(KOomPluginInterfaceUidValue);
   644     iPluginListV2 = COomPluginList<COomMonitorPluginV2>::NewL(KOomPluginInterfaceV2UidValue);
   677     iPluginListV2 = COomPluginList<COomMonitorPluginV2>::NewL(KOomPluginInterfaceV2UidValue);
   661         {
   694         {
   662         // Get the config for this plugin
   695         // Get the config for this plugin
   663         COomRunPluginConfig& pluginConfig = aConfig.GetPluginConfig(iPluginListV2->Uid(pluginIndex));
   696         COomRunPluginConfig& pluginConfig = aConfig.GetPluginConfig(iPluginListV2->Uid(pluginIndex));
   664         
   697         
   665         // Create an action acording to the config
   698         // Create an action acording to the config
   666         COomRunPlugin* action = COomRunPlugin::NewL(iPluginList->Uid(pluginIndex), pluginConfig, *this, iPluginListV2->Implementation(pluginIndex), &(iPluginListV2->Implementation(pluginIndex)));
   699         COomRunPlugin* action = COomRunPlugin::NewL(iPluginListV2->Uid(pluginIndex), pluginConfig, *this, iPluginListV2->Implementation(pluginIndex), &(iPluginListV2->Implementation(pluginIndex)));
   667         
   700         
   668         iRunPluginActions.AppendL(action);
   701         iRunPluginActions.AppendL(action);
   669         }
   702         }
   670 
   703 
   671     //allocate empty COomCloseApp objects
   704     //allocate empty COomCloseApp objects