kernel/eka/memmodel/epoc/flexible/mmu/mpager.cpp
branchRCL_3
changeset 97 41f0cfe18c80
parent 87 2f92ad2dc5db
child 110 c734af59ce98
equal deleted inserted replaced
89:1df514389a47 97:41f0cfe18c80
   334 	}
   334 	}
   335 
   335 
   336 
   336 
   337 TInt DPager::PageFreed(SPageInfo* aPageInfo)
   337 TInt DPager::PageFreed(SPageInfo* aPageInfo)
   338 	{
   338 	{
       
   339 	__NK_ASSERT_DEBUG(RamAllocLock::IsHeld());
   339 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
   340 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
   340 	__NK_ASSERT_DEBUG(CheckLists());
   341 	__NK_ASSERT_DEBUG(CheckLists());
   341 
   342 
   342 	switch(aPageInfo->PagedState())
   343 	switch(aPageInfo->PagedState())
   343 		{
   344 		{
   380 
   381 
   381 	case SPageInfo::EPagedPinnedMoved:
   382 	case SPageInfo::EPagedPinnedMoved:
   382 		// This page was pinned when it was moved but it has not been returned 
   383 		// This page was pinned when it was moved but it has not been returned 
   383 		// to the free pool yet so make sure it is...
   384 		// to the free pool yet so make sure it is...
   384 		aPageInfo->SetPagedState(SPageInfo::EUnpaged);	// Must be unpaged before returned to free pool.
   385 		aPageInfo->SetPagedState(SPageInfo::EUnpaged);	// Must be unpaged before returned to free pool.
   385 		return KErrNotFound;
   386 		return KErrCompletion;
   386 
   387 
   387 	default:
   388 	default:
   388 		__NK_ASSERT_DEBUG(0);
   389 		__NK_ASSERT_DEBUG(0);
   389 		return KErrNotFound;
   390 		return KErrNotFound;
   390 		}
   391 		}
   391 
   392 
   392 	// Update the dirty page count as required...
   393 	// Update the dirty page count as required...
   393 	if (aPageInfo->IsDirty())
   394 	if (aPageInfo->IsDirty())
   394 		SetClean(*aPageInfo);
   395 		SetClean(*aPageInfo);
   395 
   396 
       
   397 	if (iNumberOfFreePages > 0)
       
   398 		{// The paging cache is not at the minimum size so safe to let the 
       
   399 		// ram allocator free this page.
       
   400 		iNumberOfFreePages--;
       
   401 		aPageInfo->SetPagedState(SPageInfo::EUnpaged);
       
   402 		return KErrCompletion;
       
   403 		}
       
   404 	// Need to hold onto this page as have reached the page cache limit.
   396 	// add as oldest page...
   405 	// add as oldest page...
   397 #ifdef _USE_OLDEST_LISTS
   406 #ifdef _USE_OLDEST_LISTS
   398 	aPageInfo->SetPagedState(SPageInfo::EPagedOldestClean);
   407 	aPageInfo->SetPagedState(SPageInfo::EPagedOldestClean);
   399 	iOldestCleanList.Add(&aPageInfo->iLink);
   408 	iOldestCleanList.Add(&aPageInfo->iLink);
   400 	++iOldestCleanCount;
   409 	++iOldestCleanCount;
   447 		__NK_ASSERT_DEBUG(0);
   456 		__NK_ASSERT_DEBUG(0);
   448 	case SPageInfo::EUnpaged:
   457 	case SPageInfo::EUnpaged:
   449 #ifdef _DEBUG
   458 #ifdef _DEBUG
   450 		if (!IsPageTableUnpagedRemoveAllowed(aPageInfo))
   459 		if (!IsPageTableUnpagedRemoveAllowed(aPageInfo))
   451 			__NK_ASSERT_DEBUG(0);
   460 			__NK_ASSERT_DEBUG(0);
       
   461 #endif
   452 		break;
   462 		break;
   453 #endif
       
   454 	default:
   463 	default:
   455 		__NK_ASSERT_DEBUG(0);
   464 		__NK_ASSERT_DEBUG(0);
   456 		return;
   465 		return;
   457 		}
   466 		}
   458 
   467 
   785 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
   794 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
   786 
   795 
   787 	__NK_ASSERT_DEBUG(iNumberOfFreePages>0);
   796 	__NK_ASSERT_DEBUG(iNumberOfFreePages>0);
   788 	--iNumberOfFreePages;
   797 	--iNumberOfFreePages;
   789 
   798 
       
   799 	// The page must be unpaged, otherwise it wasn't successfully removed 
       
   800 	// from the live list.
       
   801 	__NK_ASSERT_DEBUG(aPageInfo.PagedState() == SPageInfo::EUnpaged);
   790 	MmuLock::Unlock();
   802 	MmuLock::Unlock();
   791 
   803 
   792 	TPhysAddr pagePhys = aPageInfo.PhysAddr();
   804 	TPhysAddr pagePhys = aPageInfo.PhysAddr();
   793 	TheMmu.FreeRam(&pagePhys, 1, EPageDiscard);
   805 	TheMmu.FreeRam(&pagePhys, 1, EPageDiscard);
   794 
   806 
  1859 						MmuLock::Flash();
  1871 						MmuLock::Flash();
  1860 						}
  1872 						}
  1861 					}
  1873 					}
  1862 				++pi;
  1874 				++pi;
  1863 				if(((TUint)pi&(0xf<<KPageInfoShift))==0)
  1875 				if(((TUint)pi&(0xf<<KPageInfoShift))==0)
  1864 					MmuLock::Flash(); // every 16 page infos
  1876 					{
       
  1877 					MmuLock::Unlock(); // every 16 page infos
       
  1878 					RamAllocLock::Unlock();
       
  1879 					RamAllocLock::Lock();
       
  1880 					MmuLock::Lock();
       
  1881 					}
  1865 				}
  1882 				}
  1866 			while(pi<piEnd);
  1883 			while(pi<piEnd);
  1867 			}
  1884 			}
  1868 		pi = piNext;
  1885 		pi = piNext;
  1869 		}
  1886 		}