kernel/eka/memmodel/epoc/flexible/mmu/mdefrag.cpp
branchGCC_SURGE
changeset 221 39b39e1a406e
parent 201 43365a9b78a3
equal deleted inserted replaced
219:0ff03867bdb6 221:39b39e1a406e
   113 		}
   113 		}
   114 
   114 
   115 	RamAllocLock::Lock();
   115 	RamAllocLock::Lock();
   116 
   116 
   117 	// Move the page to any RAM zone.
   117 	// Move the page to any RAM zone.
   118 	r = M::MovePage(aOld, aNew, KRamZoneInvalidId, EFalse);
   118 	r = M::MovePage(aOld, aNew, KRamZoneInvalidId, 0);
   119 
   119 
   120 	RamAllocLock::Unlock();
   120 	RamAllocLock::Unlock();
   121 	return r;
   121 	return r;
   122 	}
   122 	}
   123 
   123 
   124 
   124 
   125 TInt M::MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TBool aBlockRest)
   125 TInt M::MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TUint aMoveDisFlags)
   126 	{
   126 	{
   127 	TInt r;
   127 	// Returns this when page is not paged or managed or free but is a real RAM page.
       
   128 	TInt r = KErrNotSupported;
   128 
   129 
   129 	// get memory object corresponding to the page...
   130 	// get memory object corresponding to the page...
   130 	DMemoryObject* memory = 0;
   131 	DMemoryObject* memory = 0;
   131 	MmuLock::Lock();
   132 	MmuLock::Lock();
   132 	SPageInfo* pi = SPageInfo::SafeFromPhysAddr(aOld&~KPageMask);
   133 	SPageInfo* pi = SPageInfo::SafeFromPhysAddr(aOld & ~KPageMask);
       
   134 	if (pi)
       
   135 		{
       
   136 		if (pi->PagedState() != SPageInfo::EUnpaged)
       
   137 			{// The page is paged so let the pager handle it.
       
   138 			return ThePager.DiscardPage(pi, aBlockZoneId, aMoveDisFlags);
       
   139 			}
       
   140 		switch (pi->Type())
       
   141 			{
       
   142 			case SPageInfo::EManaged:
       
   143 				memory = pi->Owner();
       
   144 				memory->Open();
       
   145 				// move page, this will release the mmu lock.
       
   146 				r = memory->iManager->MovePage(	memory, pi, aNew, aBlockZoneId, 
       
   147 												(aMoveDisFlags & M::EMoveDisBlockRest)!=0);
       
   148 				memory->AsyncClose();
       
   149 				break;
       
   150 			case SPageInfo::EUnused:
       
   151 				r = KErrNotFound;	// This page is free so nothing to do.
       
   152 				// Fall through..
       
   153 			default:
       
   154 				MmuLock::Unlock();
       
   155 			}
       
   156 		}
       
   157 	else
       
   158 		{// page info for aOld not found so aOld is not a RAM page...
       
   159 		MmuLock::Unlock();
       
   160 		r = KErrArgument;
       
   161 		}
       
   162 	return r;
       
   163 	}
       
   164 
       
   165 
       
   166 TInt M::MoveAndAllocPage(TPhysAddr aAddr, TZonePageType aPageType)
       
   167 	{
       
   168 	// Returns this when page is not paged or managed or free but is a real RAM page.
       
   169 	TInt r = KErrNotSupported;
       
   170 
       
   171 	// get memory object corresponding to the page...
       
   172 	DMemoryObject* memory = 0;
       
   173 	MmuLock::Lock();
       
   174 	SPageInfo* pi = SPageInfo::SafeFromPhysAddr(aAddr & ~KPageMask);
   133 	if(pi)
   175 	if(pi)
   134 		{
   176 		{
   135 		if (pi->PagedState() != SPageInfo::EUnpaged)
   177 		if (pi->PagedState() != SPageInfo::EUnpaged)
   136 			{// The page is paged so let the pager handle it.
   178 			{// The page is paged so let the pager handle it.
   137 			return ThePager.DiscardPage(pi, aBlockZoneId, aBlockRest);
   179 			return ThePager.DiscardAndAllocPage(pi, aPageType);
   138 			}
   180 			}
   139 		if (pi->Type()==SPageInfo::EManaged)
   181 		switch (pi->Type())
   140 			memory = pi->Owner();
   182 			{
   141 		}
   183 			case SPageInfo::EManaged:
   142 	MmuLock::Unlock();
   184 				memory = pi->Owner();
   143 
   185 				memory->Open();
   144 	// Note, whilst we hold the RamAllocLock the page can't change it's use
   186 				// move page, this will release the mmu lock.
   145 	// and we can safely assume that it still belongs to the memory object
   187 				r = memory->iManager->MoveAndAllocPage(memory, pi, aPageType);
   146 	// at a fixed page index.
   188 				memory->AsyncClose();
   147 	// Also, as memory objects can't be destroyed whilst they still own pages
   189 				break;
   148 	// we can safely access this object without taking an explicit referernce,
   190 			case SPageInfo::EUnused:
   149 	// i.e. we don't need to Open() the memory object.
   191 				r = KErrNone;	// This page is free so nothing to do.
   150 	if (!pi)
   192 				// Fall through..
   151 		{// page info for aOld not found so aOld is not a RAM page...
   193 			default:
       
   194 				MmuLock::Unlock();
       
   195 			}
       
   196 		}
       
   197 	else
       
   198 		{// page info for aAddr not found so aAddr is not a RAM page...
       
   199 		MmuLock::Unlock();
   152 		r = KErrArgument;
   200 		r = KErrArgument;
   153 		}
       
   154 	else if(!memory)
       
   155 		{
       
   156 		// page does not have a memory manager, so we can't move it...
       
   157 		r = KErrNotSupported;
       
   158 		}
       
   159 	else
       
   160 		{
       
   161 		// move page...
       
   162 		r = memory->iManager->MovePage(memory, pi, aNew, aBlockZoneId, aBlockRest);
       
   163 		}
   201 		}
   164 	return r;
   202 	return r;
   165 	}
   203 	}