kernel/eka/memmodel/epoc/mmubase/defragbase.cpp
branchRCL_3
changeset 28 5b5d147c7838
parent 22 2f92ad2dc5db
equal deleted inserted replaced
26:c734af59ce98 28:5b5d147c7838
    76 	__KTRACE_OPT(KMMU, Kern::Printf("ClearMovableFromZone: ID %x ", aZone.iId));
    76 	__KTRACE_OPT(KMMU, Kern::Printf("ClearMovableFromZone: ID %x ", aZone.iId));
    77 
    77 
    78 	TUint offset = 0;
    78 	TUint offset = 0;
    79 	TPhysAddr newAddr;
    79 	TPhysAddr newAddr;
    80 	TBool zoneActive = EFalse;
    80 	TBool zoneActive = EFalse;
       
    81 	const TUint moveDisFlags = (aBestEffort)? 0 : M::EMoveDisBlockRest | M::EMoveDisMoveDirty;
    81 	TInt ret = iRamAllocator->NextAllocatedPage(&aZone, offset, EPageMovable);
    82 	TInt ret = iRamAllocator->NextAllocatedPage(&aZone, offset, EPageMovable);
    82 
    83 
    83 	// if not best effort mode keep moving pages unless someone allocates into 
    84 	// if not best effort mode keep moving pages unless someone allocates into 
    84 	// the zone or an unmovable page is hit.
    85 	// the zone or an unmovable page is hit.
    85 	// If in best effort mode then attempt to move all allocated pages in 
    86 	// If in best effort mode then attempt to move all allocated pages in 
    99 			zoneActive))
   100 			zoneActive))
   100 			{
   101 			{
   101 			__KTRACE_OPT(KMMU, Kern::Printf("ClearMovableFromZone: memory too low or zone active addr %x", addr));
   102 			__KTRACE_OPT(KMMU, Kern::Printf("ClearMovableFromZone: memory too low or zone active addr %x", addr));
   102 			return KErrNoMemory;
   103 			return KErrNoMemory;
   103 			}
   104 			}
   104 		TInt moved = M::MovePage(addr, newAddr, aZone.iId, !aBestEffort);
   105 		TInt moved = M::MovePage(addr, newAddr, aZone.iId, moveDisFlags);
   105 		if (moved != KErrNone)
   106 		if (moved != KErrNone)
   106 			{// Couldn't move the page so stop as we can't clear the zone
   107 			{// Couldn't move the page so stop as we can't clear the zone
   107 			if (!aBestEffort)
   108 			if (!aBestEffort)
   108 				{
   109 				{
   109 				__KTRACE_OPT(KMMU, Kern::Printf("ClearMovableFromZone exit: move fail zone %x addr %x", aZone.iId, addr));
   110 				__KTRACE_OPT(KMMU, Kern::Printf("ClearMovableFromZone exit: move fail zone %x addr %x", aZone.iId, addr));
   142 	__KTRACE_OPT(KMMU, Kern::Printf("ClearDiscardableFromZone: ID %x ", aZone.iId));
   143 	__KTRACE_OPT(KMMU, Kern::Printf("ClearDiscardableFromZone: ID %x ", aZone.iId));
   143 
   144 
   144 	TUint offset = 0;
   145 	TUint offset = 0;
   145 	TBool zoneActive = EFalse;
   146 	TBool zoneActive = EFalse;
   146 	TInt ret = iRamAllocator->NextAllocatedPage(&aZone, offset, EPageDiscard);
   147 	TInt ret = iRamAllocator->NextAllocatedPage(&aZone, offset, EPageDiscard);
       
   148 	const TUint moveDisFlags = (aBestEffort)? 0 : M::EMoveDisBlockRest | M::EMoveDisMoveDirty;
   147 
   149 
   148 
   150 
   149 	while (	aZone.iAllocPages[EPageDiscard] != 0 && ret == KErrNone && 
   151 	while (	aZone.iAllocPages[EPageDiscard] != 0 && ret == KErrNone && 
   150 			(!aMaxDiscard || *aMaxDiscard))
   152 			(!aMaxDiscard || *aMaxDiscard))
   151 		{
   153 		{
   167 			{
   169 			{
   168 			__KTRACE_OPT(KMMU, Kern::Printf("ClearDiscardableFromZone: memory too low or zone active addr %x", addr));
   170 			__KTRACE_OPT(KMMU, Kern::Printf("ClearDiscardableFromZone: memory too low or zone active addr %x", addr));
   169 			return KErrNoMemory;
   171 			return KErrNoMemory;
   170 			}
   172 			}
   171 
   173 
   172 		TInt discardRet = M::DiscardPage(addr, aZone.iId, !aBestEffort);
   174 		TInt discardRet = M::DiscardPage(addr, aZone.iId, moveDisFlags);
   173 		if (discardRet == KErrNone)
   175 		if (discardRet == KErrNone)
   174 			{// Page was discarded successfully.
   176 			{// Page was discarded successfully.
   175 			if (aMaxDiscard)
   177 			if (aMaxDiscard)
   176 				(*aMaxDiscard)--;
   178 				(*aMaxDiscard)--;
   177 			}
   179 			}