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