webengine/osswebengine/MemoryManager/Src/StopScheduler.cpp
branchRCL_3
changeset 46 30342f40acbf
parent 0 dd21522fd290
child 48 79859ed3eea9
equal deleted inserted replaced
44:800203832575 46:30342f40acbf
    16 *
    16 *
    17 */
    17 */
    18 #include "StopScheduler.h"
    18 #include "StopScheduler.h"
    19 #include "MemoryPool.h"
    19 #include "MemoryPool.h"
    20 #include "fast_malloc.h"
    20 #include "fast_malloc.h"
       
    21 #include "MemoryLogger.h"
       
    22 #include <hal.h>
    21 
    23 
    22 // MEMBER FUNCTIONS
    24 // MEMBER FUNCTIONS
    23 static const TUint KLessRAM = ( 2*1024*1024 );
       
    24 static const TUint KMinimumRAM = (1024 * 1024);
       
    25 static const TTimeIntervalMicroSeconds32 KMemoryCheckIntervalSlow = 1000000;        // 1 second
    25 static const TTimeIntervalMicroSeconds32 KMemoryCheckIntervalSlow = 1000000;        // 1 second
    26 static const TTimeIntervalMicroSeconds32 KMemoryCheckIntervalFast = 500000;         // 0.5 second
    26 static const TTimeIntervalMicroSeconds32 KMemoryCheckIntervalFast = 500000;         // 0.5 second
    27 
    27 
    28 //-----------------------------------------------------------------------------
    28 //-----------------------------------------------------------------------------
    29 // CStopScheduler::CStopScheduler
    29 // CStopScheduler::CStopScheduler
    79         iNextStop &= ~ENormalStop;
    79         iNextStop &= ~ENormalStop;
    80         CheckMemoryDefered( KMemoryCheckIntervalFast );
    80         CheckMemoryDefered( KMemoryCheckIntervalFast );
    81         }
    81         }
    82     else if( iState == ECheckMemory )
    82     else if( iState == ECheckMemory )
    83         {
    83         {
    84         TFreeMem freeMem;
    84     
    85         TInt total = iMemoryPool.FreeMemory( freeMem );
    85         TInt systemFreeRAM; 
    86 
    86         if(HAL::Get(HALData::EMemoryRAMFree, systemFreeRAM) != KErrNone) 
    87         // see if free memory is enough to restore all collectors
    87             return;        
    88         if( freeMem.iHal >= KLessRAM )
    88         
       
    89         // case 1: Good memory levels - no worry
       
    90         if( systemFreeRAM > KGoodMemoryThreshold ) // Above 4MB
    89             {
    91             {
    90             iMemoryPool.RestoreCollectors( EOOM_PriorityLow );
    92             iMemoryPool.RestoreCollectors( EOOM_PriorityLow ); // restore all collectors
    91             iState = EIdle;
    93             iState = EIdle;
    92             iNextStop = EAllStop;
    94             iNextStop = EAllStop;
    93 
    95 
    94             // recover the rescue buffer, if it is already released.
    96             // recover the rescue buffer, if it is already released.
    95             iMemoryPool.RestoreRescueBuffer();
    97             iMemoryPool.RestoreRescueBuffer();
       
    98             return;
    96             }
    99             }
    97         else if( freeMem.iHal >= KMinimumRAM/2 )
   100         
       
   101         // case 2: Going low - keep checking
       
   102         if( systemFreeRAM > KLowMemoryThreshold ) // Between 4MB to 2MB
    98             {
   103             {
    99             iMemoryPool.RestoreCollectors( EOOM_PriorityMiddle );
       
   100             CheckMemoryDefered( KMemoryCheckIntervalSlow );
   104             CheckMemoryDefered( KMemoryCheckIntervalSlow );
   101             iNextStop = EAllStop;
   105             iNextStop = EAllStop;
       
   106             return;
   102             }
   107             }
   103         else if( freeMem.iHal >= KMinimumRAM/4 )
   108          
       
   109         // case 3: Below normal levels - stop low priority activites
       
   110         if( systemFreeRAM > KStopThreshold )  // Between 2MB to 1MB
   104             {
   111             {
   105             if( iNextStop & ENormalStop ) 
   112             if( iNextStop & ENormalStop ) 
   106                 {
   113                 {
   107                 StopLoading( EOOM_PriorityLow );
   114                 StopLoading( EOOM_PriorityLow );
   108                 iNextStop &= ~ENormalStop;
   115                 iNextStop &= ~ENormalStop;
   109                 }
   116                 }
   110             CheckMemoryDefered( KMemoryCheckIntervalFast );
   117             CheckMemoryDefered( KMemoryCheckIntervalFast );
   111             }
   118             }        
   112         else
   119         else // case 4: Really low - stop in emergency (all activites), below 1MB
   113             {
   120             {
   114             if( iNextStop & EEmergencyStop ) 
   121             if( iNextStop & EEmergencyStop ) 
   115                 {
   122                 {
   116                 StopLoading( EOOM_PriorityHigh );
   123                 StopLoading( EOOM_PriorityHigh );
   117                 iNextStop &= ~EEmergencyStop;
   124                 iNextStop &= ~EEmergencyStop;
   118                 }
   125                 }
   119             CheckMemoryDefered( KMemoryCheckIntervalFast );
   126             CheckMemoryDefered( KMemoryCheckIntervalSlow ); // need to restore colectors later
   120             }
   127             }
   121         }
   128         }
   122     }
   129     }
   123 
   130 
   124 //-----------------------------------------------------------------------------
   131 //-----------------------------------------------------------------------------
   132 //-----------------------------------------------------------------------------
   139 //-----------------------------------------------------------------------------
   133 // CStopScheduler::StopLoading
   140 // CStopScheduler::StopLoading
   134 //-----------------------------------------------------------------------------
   141 //-----------------------------------------------------------------------------
   135 void CStopScheduler::StopLoading( TOOMPriority aPriority )
   142 void CStopScheduler::StopLoading( TOOMPriority aPriority )
   136     {
   143     {
       
   144     MEM_LOG("CStopScheduler::StopLoading - run");
   137     // stop operations
   145     // stop operations
   138     for( TInt i=0; i<iMemoryPool.Stoppers().Count(); ++i )
   146     for( TInt i=0; i<iMemoryPool.Stoppers().Count(); ++i )
   139         {
   147         {
   140         MOOMStopper* stopper = iMemoryPool.Stoppers()[i];
   148         MOOMStopper* stopper = iMemoryPool.Stoppers()[i];
   141         if( stopper->Priority() == aPriority )
   149         if( stopper->Priority() == aPriority )
   142             stopper->Stop();
   150             stopper->Stop();
   143         }
   151         }
       
   152     iMemoryPool.CollectMemory(2*KGoodMemoryThreshold);  // try to collect memory
   144     iMemoryPool.SetStopping( EFalse );
   153     iMemoryPool.SetStopping( EFalse );
   145     }
   154     }
   146 
   155 
   147 //-----------------------------------------------------------------------------
   156 //-----------------------------------------------------------------------------
   148 // CStopScheduler::CheckMemoryDefered
   157 // CStopScheduler::CheckMemoryDefered