author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:34:56 +0100 | |
branch | RCL_3 |
changeset 44 | 3e88ff8f41d5 |
parent 43 | c1f20ce4abcf |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// |
|
15 |
||
16 |
#include "memmodel.h" |
|
17 |
#include "mm.h" |
|
18 |
#include "mmu.h" |
|
19 |
||
20 |
#include "mpager.h" |
|
21 |
#include "mrom.h" |
|
22 |
#include "mobject.h" |
|
23 |
#include "mmapping.h" |
|
24 |
#include "maddressspace.h" |
|
25 |
#include "mmanager.h" |
|
26 |
#include "mptalloc.h" |
|
27 |
#include "mpagearray.h" |
|
28 |
#include "mswap.h" |
|
29 |
#include "mthrash.h" |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
30 |
#include "mpagecleaner.h" |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
31 |
|
0 | 32 |
#include "cache_maintenance.inl" |
33 |
||
34 |
||
35 |
const TUint16 KDefaultYoungOldRatio = 3; |
|
36 |
const TUint16 KDefaultMinPages = 256; |
|
37 |
const TUint16 KDefaultOldOldestRatio = 3; |
|
38 |
||
39 |
const TUint KMinOldPages = 1; |
|
40 |
||
41 |
/* On a 32 bit system without PAE can't have more than 2^(32-KPageShift) pages. |
|
42 |
* Subtract 1 so it doesn't overflow when converted to bytes. |
|
43 |
*/ |
|
44 |
const TUint KAbsoluteMaxPageCount = (1u<<(32-KPageShift))-1u; |
|
45 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
46 |
/** |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
47 |
Default limit for the maximum number of oldest pages. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
48 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
49 |
If the data paging device sets iPreferredWriteShift, then this is increased if necessary to allow |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
50 |
that many pages to be present. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
51 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
52 |
This limit exists to make our live list implementation a closer approximation to LRU, and to bound |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
53 |
the time taken by SelectSequentialPagesToClean(), which is called with the MmuLock held. |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
54 |
*/ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
55 |
const TUint KDefaultMaxOldestPages = 32; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
56 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
57 |
static DMutex* ThePageCleaningLock = NULL; |
0 | 58 |
|
59 |
DPager ThePager; |
|
60 |
||
61 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
62 |
DPager::DPager() : |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
63 |
iMinimumPageCount(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
64 |
iMaximumPageCount(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
65 |
iYoungOldRatio(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
66 |
iYoungCount(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
67 |
iOldCount(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
68 |
iOldestCleanCount(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
69 |
iMaxOldestPages(KDefaultMaxOldestPages), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
70 |
iNumberOfFreePages(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
71 |
iReservePageCount(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
72 |
iMinimumPageLimit(0), |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
73 |
iPagesToClean(1) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
74 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
75 |
, iBenchmarkLock(TSpinLock::EOrderGenericIrqHigh3) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
76 |
#endif |
0 | 77 |
{ |
78 |
} |
|
79 |
||
80 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
void DPager::InitCache() |
0 | 82 |
{ |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
// |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
// This routine doesn't acquire any mutexes because it should be called before the system |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
// is fully up and running. I.e. called before another thread can preempt this. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
// |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
TRACEB(("DPager::InitCache()")); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
// If any pages have been reserved then they will have already been allocated and |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
// therefore should be counted as part of iMinimumPageCount. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
__NK_ASSERT_DEBUG(iReservePageCount == iMinimumPageCount); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
__NK_ASSERT_DEBUG(!CacheInitialised()); |
0 | 92 |
|
93 |
#if defined(__CPU_ARM) |
|
94 |
||
95 |
/** Minimum number of young pages the demand paging live list may have. |
|
96 |
Need at least 4 mapped pages to guarantee to be able to execute all ARM instructions, |
|
97 |
plus enough pages for 4 page tables to map those pages, plus enough pages for the |
|
98 |
page table info structures of those page tables. |
|
99 |
(Worst case is a Thumb-2 STM instruction with both instruction and data straddling chunk |
|
100 |
boundaries.) |
|
101 |
*/ |
|
102 |
iMinYoungPages = 4 // pages |
|
103 |
+(4+KPtClusterSize-1)/KPtClusterSize // page table pages |
|
104 |
+(4+KPageTableInfosPerPage-1)/KPageTableInfosPerPage; // page table info pages |
|
105 |
||
106 |
#elif defined(__CPU_X86) |
|
107 |
||
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
108 |
/* Need at least 6 mapped pages to guarantee to be able to execute all X86 instructions, |
0 | 109 |
plus enough pages for 6 page tables to map those pages, plus enough pages for the |
110 |
page table info structures of those page tables. |
|
111 |
(Worst case is (?) a MOV [X],[Y] instruction with instruction, 'X' and 'Y' all |
|
112 |
straddling chunk boundaries.) |
|
113 |
*/ |
|
114 |
iMinYoungPages = 6 // pages |
|
115 |
+(6+KPtClusterSize-1)/KPtClusterSize // page table pages |
|
116 |
+(6+KPageTableInfosPerPage-1)/KPageTableInfosPerPage; // page table info pages |
|
117 |
||
118 |
#else |
|
119 |
#error Unknown CPU |
|
120 |
#endif |
|
121 |
||
122 |
#ifdef __SMP__ |
|
123 |
// Adjust min page count so that all CPUs are guaranteed to make progress. |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
124 |
TInt numberOfCpus = NKern::NumberOfCpus(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
125 |
iMinYoungPages *= numberOfCpus; |
0 | 126 |
#endif |
127 |
||
128 |
// A minimum young/old ratio of 1 means that we need at least twice iMinYoungPages pages... |
|
129 |
iAbsoluteMinPageCount = 2*iMinYoungPages; |
|
130 |
||
131 |
__NK_ASSERT_DEBUG(KMinOldPages<=iAbsoluteMinPageCount/2); |
|
132 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
// Read any paging config data. |
0 | 134 |
SDemandPagingConfig config = TheRomHeader().iDemandPagingConfig; |
135 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
// Set the list ratios... |
0 | 137 |
iYoungOldRatio = KDefaultYoungOldRatio; |
138 |
if(config.iYoungOldRatio) |
|
139 |
iYoungOldRatio = config.iYoungOldRatio; |
|
140 |
iOldOldestRatio = KDefaultOldOldestRatio; |
|
141 |
if(config.iSpare[2]) |
|
142 |
iOldOldestRatio = config.iSpare[2]; |
|
143 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
// Set the minimum page counts... |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
iMinimumPageLimit = iMinYoungPages * (1 + iYoungOldRatio) / iYoungOldRatio |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
+ DPageReadRequest::ReservedPagesRequired(); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
if(iMinimumPageLimit < iAbsoluteMinPageCount) |
0 | 149 |
iMinimumPageLimit = iAbsoluteMinPageCount; |
150 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
if (K::MemModelAttributes & (EMemModelAttrRomPaging | EMemModelAttrCodePaging | EMemModelAttrDataPaging)) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
iMinimumPageCount = KDefaultMinPages; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
else |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
{// No paging is enabled so set the minimum cache size to the minimum |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
// allowable with the current young old ratio. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
iMinimumPageCount = iMinYoungPages * (iYoungOldRatio + 1); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
if(config.iMinPages) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
iMinimumPageCount = config.iMinPages; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
if(iMinimumPageCount < iAbsoluteMinPageCount) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
iMinimumPageCount = iAbsoluteMinPageCount; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
if (iMinimumPageLimit + iReservePageCount > iMinimumPageCount) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
iMinimumPageCount = iMinimumPageLimit + iReservePageCount; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
166 |
iInitMinimumPageCount = iMinimumPageCount; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
// Set the maximum page counts... |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
iMaximumPageCount = KMaxTInt; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
if(config.iMaxPages) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
iMaximumPageCount = config.iMaxPages; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
if (iMaximumPageCount > KAbsoluteMaxPageCount) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
iMaximumPageCount = KAbsoluteMaxPageCount; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
iInitMaximumPageCount = iMaximumPageCount; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
TRACEB(("DPager::InitCache() live list min=%d max=%d ratio=%d",iMinimumPageCount,iMaximumPageCount,iYoungOldRatio)); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
// Verify the page counts are valid. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
__NK_ASSERT_ALWAYS(iMaximumPageCount >= iMinimumPageCount); |
0 | 180 |
TUint minOldAndOldest = iMinimumPageCount / (1 + iYoungOldRatio); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
__NK_ASSERT_ALWAYS(minOldAndOldest >= KMinOldPages); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
__NK_ASSERT_ALWAYS(iMinimumPageCount >= minOldAndOldest); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
// Need at least iMinYoungPages pages mapped to execute worst case CPU instruction |
0 | 185 |
TUint minYoung = iMinimumPageCount - minOldAndOldest; |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
__NK_ASSERT_ALWAYS(minYoung >= iMinYoungPages); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
// Verify that the young old ratio can be met even when there is only the |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
// minimum number of old pages. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
TInt ratioLimit = (iMinimumPageCount-KMinOldPages)/KMinOldPages; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
__NK_ASSERT_ALWAYS(iYoungOldRatio <= ratioLimit); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
|
0 | 193 |
// There should always be enough old pages to allow the oldest lists ratio. |
194 |
TUint oldestCount = minOldAndOldest / (1 + iOldOldestRatio); |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
__NK_ASSERT_ALWAYS(oldestCount); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
|
0 | 197 |
iNumberOfFreePages = 0; |
198 |
iNumberOfDirtyPages = 0; |
|
199 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
// Allocate RAM pages and put them all on the old list. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
// Reserved pages have already been allocated and already placed on the |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
// old list so don't allocate them again. |
0 | 203 |
RamAllocLock::Lock(); |
204 |
iYoungCount = 0; |
|
205 |
iOldCount = 0; |
|
206 |
iOldestDirtyCount = 0; |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
__NK_ASSERT_DEBUG(iOldestCleanCount == iReservePageCount); |
0 | 208 |
Mmu& m = TheMmu; |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
for(TUint i = iReservePageCount; i < iMinimumPageCount; i++) |
0 | 210 |
{ |
211 |
// Allocate a single page |
|
212 |
TPhysAddr pagePhys; |
|
213 |
TInt r = m.AllocRam(&pagePhys, 1, |
|
214 |
(Mmu::TRamAllocFlags)(EMemAttNormalCached|Mmu::EAllocNoWipe|Mmu::EAllocNoPagerReclaim), |
|
215 |
EPageDiscard); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
216 |
__NK_ASSERT_ALWAYS(r == KErrNone); |
0 | 217 |
MmuLock::Lock(); |
218 |
AddAsFreePage(SPageInfo::FromPhysAddr(pagePhys)); |
|
219 |
MmuLock::Unlock(); |
|
220 |
} |
|
221 |
RamAllocLock::Unlock(); |
|
222 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
__NK_ASSERT_DEBUG(CacheInitialised()); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
TRACEB(("DPager::InitCache() end with young=%d old=%d oldClean=%d oldDirty=%d min=%d free=%d max=%d",iYoungCount,iOldCount,iOldestCleanCount,iOldestDirtyCount,iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount)); |
0 | 225 |
} |
226 |
||
227 |
||
228 |
#ifdef _DEBUG |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
229 |
#ifdef FMM_PAGER_CHECK_LISTS |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
230 |
TBool CheckList(SDblQueLink* aHead, TUint aCount) |
0 | 231 |
{ |
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
232 |
SDblQueLink* link = aHead; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
233 |
while(aCount--) |
0 | 234 |
{ |
235 |
link = link->iNext; |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
236 |
if(link == aHead) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
237 |
return EFalse; |
0 | 238 |
} |
239 |
link = link->iNext; |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
240 |
if(link != aHead) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
241 |
return EFalse; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
242 |
return ETrue; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
243 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
244 |
#endif // #ifdef FMM_PAGER_CHECK_LISTS |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
245 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
246 |
TBool DPager::CheckLists() |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
247 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
248 |
#ifdef FMM_PAGER_CHECK_LISTS |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
249 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
250 |
if (!CheckList(&iOldList.iA, iOldCount)) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
251 |
return EFalse; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
252 |
if (!CheckList(&iYoungList.iA, iYoungCount)) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
253 |
return EFalse; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
254 |
if (!CheckList(&iOldestCleanList.iA, iOldestCleanCount)) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
255 |
return EFalse; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
256 |
if (!CheckList(&iOldestDirtyList.iA, iOldestDirtyCount)) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
257 |
return EFalse; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
258 |
TRACEP(("DP: y=%d o=%d oc=%d od=%d f=%d", iYoungCount, iOldCount, |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
259 |
iOldestCleanCount, iOldestDirtyCount, iNumberOfFreePages)); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
260 |
TraceCounts(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
261 |
#endif // #ifdef FMM_PAGER_CHECK_LISTS |
0 | 262 |
return true; |
263 |
} |
|
264 |
||
265 |
void DPager::TraceCounts() |
|
266 |
{ |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
267 |
TRACEP(("DP: y=%d o=%d oc=%d od=%d f=%d min=%d max=%d ml=%d res=%d", |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
268 |
iYoungCount, iOldCount, iOldestCleanCount, iOldestDirtyCount, |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
269 |
iNumberOfFreePages, iMinimumPageCount, iMaximumPageCount, |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
270 |
iMinimumPageLimit, iReservePageCount)); |
0 | 271 |
} |
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
272 |
#endif //#ifdef _DEBUG |
0 | 273 |
|
274 |
||
275 |
TBool DPager::HaveTooManyPages() |
|
276 |
{ |
|
277 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
278 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
279 |
return iMinimumPageCount+iNumberOfFreePages > iMaximumPageCount; |
|
280 |
} |
|
281 |
||
282 |
||
283 |
TBool DPager::HaveMaximumPages() |
|
284 |
{ |
|
285 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
286 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
287 |
return iMinimumPageCount+iNumberOfFreePages >= iMaximumPageCount; |
|
288 |
} |
|
289 |
||
290 |
||
291 |
void DPager::AddAsYoungestPage(SPageInfo* aPageInfo) |
|
292 |
{ |
|
293 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
294 |
__NK_ASSERT_DEBUG(CheckLists()); |
|
295 |
__NK_ASSERT_DEBUG(aPageInfo->PagedState()==SPageInfo::EUnpaged); |
|
296 |
||
297 |
aPageInfo->SetPagedState(SPageInfo::EPagedYoung); |
|
298 |
iYoungList.AddHead(&aPageInfo->iLink); |
|
299 |
++iYoungCount; |
|
300 |
} |
|
301 |
||
302 |
||
303 |
void DPager::AddAsFreePage(SPageInfo* aPageInfo) |
|
304 |
{ |
|
305 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
306 |
__NK_ASSERT_DEBUG(CheckLists()); |
|
307 |
||
308 |
__NK_ASSERT_DEBUG(aPageInfo->PagedState()==SPageInfo::EUnpaged); |
|
309 |
TheMmu.PageFreed(aPageInfo); |
|
310 |
__NK_ASSERT_DEBUG(aPageInfo->PagedState()==SPageInfo::EUnpaged); |
|
311 |
||
312 |
// add as oldest page... |
|
313 |
aPageInfo->SetPagedState(SPageInfo::EPagedOldestClean); |
|
314 |
iOldestCleanList.Add(&aPageInfo->iLink); |
|
315 |
++iOldestCleanCount; |
|
316 |
||
317 |
Event(EEventPageInFree,aPageInfo); |
|
318 |
} |
|
319 |
||
320 |
||
321 |
TInt DPager::PageFreed(SPageInfo* aPageInfo) |
|
322 |
{ |
|
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
323 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
0 | 324 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
325 |
__NK_ASSERT_DEBUG(CheckLists()); |
|
326 |
||
327 |
switch(aPageInfo->PagedState()) |
|
328 |
{ |
|
329 |
case SPageInfo::EUnpaged: |
|
330 |
return KErrNotFound; |
|
331 |
||
332 |
case SPageInfo::EPagedYoung: |
|
333 |
__NK_ASSERT_DEBUG(iYoungCount); |
|
334 |
aPageInfo->iLink.Deque(); |
|
335 |
--iYoungCount; |
|
336 |
break; |
|
337 |
||
338 |
case SPageInfo::EPagedOld: |
|
339 |
__NK_ASSERT_DEBUG(iOldCount); |
|
340 |
aPageInfo->iLink.Deque(); |
|
341 |
--iOldCount; |
|
342 |
break; |
|
343 |
||
344 |
case SPageInfo::EPagedOldestClean: |
|
345 |
__NK_ASSERT_DEBUG(iOldestCleanCount); |
|
346 |
aPageInfo->iLink.Deque(); |
|
347 |
--iOldestCleanCount; |
|
348 |
break; |
|
349 |
||
350 |
case SPageInfo::EPagedOldestDirty: |
|
351 |
__NK_ASSERT_DEBUG(iOldestDirtyCount); |
|
352 |
aPageInfo->iLink.Deque(); |
|
353 |
--iOldestDirtyCount; |
|
354 |
break; |
|
355 |
||
356 |
case SPageInfo::EPagedPinned: |
|
357 |
// this can occur if a pinned mapping is being unmapped when memory is decommitted. |
|
358 |
// the decommit will have succeeded because the the mapping no longer vetoes this, |
|
359 |
// however the unpinning hasn't yet got around to changing the page state. |
|
360 |
// When the state change happens the page will be put back on the live list so |
|
361 |
// we don't have to do anything now... |
|
362 |
return KErrNone; |
|
363 |
||
364 |
case SPageInfo::EPagedPinnedMoved: |
|
365 |
// This page was pinned when it was moved but it has not been returned |
|
366 |
// to the free pool yet so make sure it is... |
|
367 |
aPageInfo->SetPagedState(SPageInfo::EUnpaged); // Must be unpaged before returned to free pool. |
|
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
368 |
return KErrCompletion; |
0 | 369 |
|
370 |
default: |
|
371 |
__NK_ASSERT_DEBUG(0); |
|
372 |
return KErrNotFound; |
|
373 |
} |
|
374 |
||
375 |
// Update the dirty page count as required... |
|
376 |
if (aPageInfo->IsDirty()) |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
377 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
378 |
aPageInfo->SetReadOnly(); |
0 | 379 |
SetClean(*aPageInfo); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
380 |
} |
0 | 381 |
|
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
382 |
if (iNumberOfFreePages > 0) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
383 |
{// The paging cache is not at the minimum size so safe to let the |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
384 |
// ram allocator free this page. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
385 |
iNumberOfFreePages--; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
386 |
aPageInfo->SetPagedState(SPageInfo::EUnpaged); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
387 |
return KErrCompletion; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
388 |
} |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
389 |
// Need to hold onto this page as have reached the page cache limit. |
0 | 390 |
// add as oldest page... |
391 |
aPageInfo->SetPagedState(SPageInfo::EPagedOldestClean); |
|
392 |
iOldestCleanList.Add(&aPageInfo->iLink); |
|
393 |
++iOldestCleanCount; |
|
394 |
||
395 |
return KErrNone; |
|
396 |
} |
|
397 |
||
398 |
||
399 |
extern TBool IsPageTableUnpagedRemoveAllowed(SPageInfo* aPageInfo); |
|
400 |
||
401 |
void DPager::RemovePage(SPageInfo* aPageInfo) |
|
402 |
{ |
|
403 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
404 |
__NK_ASSERT_DEBUG(CheckLists()); |
|
405 |
||
406 |
switch(aPageInfo->PagedState()) |
|
407 |
{ |
|
408 |
case SPageInfo::EPagedYoung: |
|
409 |
__NK_ASSERT_DEBUG(iYoungCount); |
|
410 |
aPageInfo->iLink.Deque(); |
|
411 |
--iYoungCount; |
|
412 |
break; |
|
413 |
||
414 |
case SPageInfo::EPagedOld: |
|
415 |
__NK_ASSERT_DEBUG(iOldCount); |
|
416 |
aPageInfo->iLink.Deque(); |
|
417 |
--iOldCount; |
|
418 |
break; |
|
419 |
||
420 |
case SPageInfo::EPagedOldestClean: |
|
421 |
__NK_ASSERT_DEBUG(iOldestCleanCount); |
|
422 |
aPageInfo->iLink.Deque(); |
|
423 |
--iOldestCleanCount; |
|
424 |
break; |
|
425 |
||
426 |
case SPageInfo::EPagedOldestDirty: |
|
427 |
__NK_ASSERT_DEBUG(iOldestDirtyCount); |
|
428 |
aPageInfo->iLink.Deque(); |
|
429 |
--iOldestDirtyCount; |
|
430 |
break; |
|
431 |
||
432 |
case SPageInfo::EPagedPinned: |
|
433 |
__NK_ASSERT_DEBUG(0); |
|
434 |
case SPageInfo::EUnpaged: |
|
435 |
#ifdef _DEBUG |
|
436 |
if (!IsPageTableUnpagedRemoveAllowed(aPageInfo)) |
|
437 |
__NK_ASSERT_DEBUG(0); |
|
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
438 |
#endif |
0 | 439 |
break; |
440 |
default: |
|
441 |
__NK_ASSERT_DEBUG(0); |
|
442 |
return; |
|
443 |
} |
|
444 |
||
445 |
aPageInfo->SetPagedState(SPageInfo::EUnpaged); |
|
446 |
} |
|
447 |
||
448 |
||
449 |
void DPager::ReplacePage(SPageInfo& aOldPageInfo, SPageInfo& aNewPageInfo) |
|
450 |
{ |
|
451 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
452 |
__NK_ASSERT_DEBUG(CheckLists()); |
|
453 |
||
454 |
__NK_ASSERT_DEBUG(aOldPageInfo.PagedState() == aNewPageInfo.PagedState()); |
|
455 |
switch(aOldPageInfo.PagedState()) |
|
456 |
{ |
|
457 |
case SPageInfo::EPagedYoung: |
|
458 |
case SPageInfo::EPagedOld: |
|
459 |
case SPageInfo::EPagedOldestClean: |
|
460 |
case SPageInfo::EPagedOldestDirty: |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
461 |
{// Update the list links to point to the new page. |
0 | 462 |
SDblQueLink* prevLink = aOldPageInfo.iLink.iPrev; |
463 |
#ifdef _DEBUG |
|
464 |
SDblQueLink* nextLink = aOldPageInfo.iLink.iNext; |
|
465 |
__NK_ASSERT_DEBUG(prevLink == aOldPageInfo.iLink.iPrev); |
|
466 |
__NK_ASSERT_DEBUG(prevLink->iNext == &aOldPageInfo.iLink); |
|
467 |
__NK_ASSERT_DEBUG(nextLink == aOldPageInfo.iLink.iNext); |
|
468 |
__NK_ASSERT_DEBUG(nextLink->iPrev == &aOldPageInfo.iLink); |
|
469 |
#endif |
|
470 |
aOldPageInfo.iLink.Deque(); |
|
471 |
aNewPageInfo.iLink.InsertAfter(prevLink); |
|
472 |
aOldPageInfo.SetPagedState(SPageInfo::EUnpaged); |
|
473 |
#ifdef _DEBUG |
|
474 |
__NK_ASSERT_DEBUG(prevLink == aNewPageInfo.iLink.iPrev); |
|
475 |
__NK_ASSERT_DEBUG(prevLink->iNext == &aNewPageInfo.iLink); |
|
476 |
__NK_ASSERT_DEBUG(nextLink == aNewPageInfo.iLink.iNext); |
|
477 |
__NK_ASSERT_DEBUG(nextLink->iPrev == &aNewPageInfo.iLink); |
|
478 |
#endif |
|
479 |
} |
|
480 |
break; |
|
481 |
case SPageInfo::EPagedPinned: |
|
482 |
// Mark the page as 'pinned moved' so that when the page moving invokes |
|
483 |
// Mmu::FreeRam() it returns this page to the free pool. |
|
484 |
aOldPageInfo.ClearPinCount(); |
|
485 |
aOldPageInfo.SetPagedState(SPageInfo::EPagedPinnedMoved); |
|
486 |
break; |
|
487 |
case SPageInfo::EPagedPinnedMoved: |
|
488 |
// Shouldn't happen as the ram alloc mutex will be held for the |
|
489 |
// entire time the page's is paged state == EPagedPinnedMoved. |
|
490 |
case SPageInfo::EUnpaged: |
|
491 |
// Shouldn't happen as we only move pinned memory and unpinning will |
|
492 |
// atomically add the page to the live list and it can't be removed |
|
493 |
// from the live list without the ram alloc mutex. |
|
494 |
__NK_ASSERT_DEBUG(0); |
|
495 |
break; |
|
496 |
} |
|
497 |
} |
|
498 |
||
499 |
||
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
500 |
SPageInfo* DPager::StealOrAllocPage(TBool aAllowAlloc, Mmu::TRamAllocFlags aAllocFlags) |
0 | 501 |
{ |
502 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
503 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
504 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
505 |
// The PageCleaningLock may or may not be held to start with |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
506 |
TBool pageCleaningLockAcquired = EFalse; |
0 | 507 |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
508 |
SDblQueLink* link; |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
509 |
SPageInfo* pageInfo ; |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
510 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
511 |
restart: |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
512 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
513 |
// if there is a free page in the live list then use that (it will be at the end)... |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
514 |
if (iOldestCleanCount) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
515 |
{ |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
516 |
__NK_ASSERT_DEBUG(!iOldestCleanList.IsEmpty()); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
517 |
link = iOldestCleanList.Last(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
518 |
pageInfo = SPageInfo::FromLink(link); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
519 |
if(pageInfo->Type()==SPageInfo::EUnused) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
520 |
goto try_steal_from_page_info; |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
521 |
} |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
522 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
523 |
// maybe try getting a free page from the system pool... |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
524 |
if (aAllowAlloc && !HaveMaximumPages()) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
525 |
{ |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
526 |
MmuLock::Unlock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
527 |
pageInfo = GetPageFromSystem(aAllocFlags); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
528 |
MmuLock::Lock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
529 |
if (pageInfo) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
530 |
goto exit; |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
531 |
} |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
532 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
533 |
// try stealing the oldest clean page on the live list if there is one... |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
534 |
if (iOldestCleanCount) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
535 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
536 |
__NK_ASSERT_DEBUG(!iOldestCleanList.IsEmpty()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
537 |
link = iOldestCleanList.Last(); |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
538 |
goto try_steal_from_link; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
539 |
} |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
540 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
541 |
// no clean oldest pages, see if we can clean multiple dirty pages in one go... |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
542 |
if (iOldestDirtyCount > 1 && iPagesToClean > 1) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
543 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
544 |
__NK_ASSERT_DEBUG(!iOldestDirtyList.IsEmpty()); |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
545 |
|
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
546 |
// check if we hold page cleaning lock |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
547 |
TBool needPageCleaningLock = !PageCleaningLock::IsHeld(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
548 |
if (needPageCleaningLock) |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
549 |
{ |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
550 |
// temporarily release ram alloc mutex and acquire page cleaning mutex |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
551 |
MmuLock::Unlock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
552 |
RamAllocLock::Unlock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
553 |
PageCleaningLock::Lock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
554 |
MmuLock::Lock(); |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
555 |
} |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
556 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
557 |
// there may be clean pages now if we've waited on the page cleaning mutex, if so don't |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
558 |
// bother cleaning but just restart |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
559 |
if (iOldestCleanCount == 0 && iOldestDirtyCount >= 1) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
560 |
CleanSomePages(EFalse); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
561 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
562 |
if (needPageCleaningLock) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
563 |
{ |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
564 |
// release page cleaning mutex and re-aquire ram alloc mutex |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
565 |
MmuLock::Unlock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
566 |
PageCleaningLock::Unlock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
567 |
RamAllocLock::Lock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
568 |
MmuLock::Lock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
569 |
} |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
570 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
571 |
// if there are now some clean pages we restart so as to take one of them |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
572 |
if (iOldestCleanCount > 0) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
573 |
goto restart; |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
574 |
} |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
575 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
576 |
// otherwise just try to steal the oldest page... |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
577 |
if (iOldestDirtyCount) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
578 |
{ |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
579 |
__NK_ASSERT_DEBUG(!iOldestDirtyList.IsEmpty()); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
580 |
link = iOldestDirtyList.Last(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
581 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
582 |
else if (iOldCount) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
583 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
584 |
__NK_ASSERT_DEBUG(!iOldList.IsEmpty()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
585 |
link = iOldList.Last(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
586 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
587 |
else |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
588 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
589 |
__NK_ASSERT_DEBUG(iYoungCount); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
590 |
__NK_ASSERT_ALWAYS(!iYoungList.IsEmpty()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
591 |
link = iYoungList.Last(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
592 |
} |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
593 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
594 |
try_steal_from_link: |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
595 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
596 |
// lookup page info |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
597 |
__NK_ASSERT_DEBUG(link); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
598 |
pageInfo = SPageInfo::FromLink(link); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
599 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
600 |
try_steal_from_page_info: |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
601 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
602 |
// if the page is dirty and we don't hold the page cleaning mutex then we have to wait on it, |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
603 |
// and restart - we clean with the ram alloc mutex held in this case |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
604 |
if (pageInfo->IsDirty() && !PageCleaningLock::IsHeld()) |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
605 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
606 |
MmuLock::Unlock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
607 |
PageCleaningLock::Lock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
608 |
MmuLock::Lock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
609 |
pageCleaningLockAcquired = ETrue; |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
610 |
goto restart; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
611 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
612 |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
613 |
// try to steal it from owning object... |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
614 |
if (StealPage(pageInfo) != KErrNone) |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
615 |
goto restart; |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
616 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
617 |
BalanceAges(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
618 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
619 |
exit: |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
620 |
if (pageCleaningLockAcquired) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
621 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
622 |
MmuLock::Unlock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
623 |
PageCleaningLock::Unlock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
624 |
MmuLock::Lock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
625 |
} |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
626 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
627 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
628 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
629 |
|
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
630 |
return pageInfo; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
631 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
632 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
633 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
634 |
template <class T, TUint maxObjects> class TSequentialColourSelector |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
635 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
636 |
public: |
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
637 |
enum |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
638 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
639 |
KMaxSearchLength = _ALIGN_UP(maxObjects, KPageColourCount) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
640 |
}; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
641 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
642 |
FORCE_INLINE TSequentialColourSelector(TUint aTargetLength) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
643 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
644 |
memclr(this, sizeof(*this)); |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
645 |
__NK_ASSERT_DEBUG(aTargetLength <= maxObjects); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
646 |
iTargetLength = aTargetLength; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
647 |
iSearchLength = _ALIGN_UP(aTargetLength, KPageColourCount); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
648 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
649 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
650 |
FORCE_INLINE TBool FoundLongestSequence() |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
651 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
652 |
return iLongestLength >= iTargetLength; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
653 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
654 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
655 |
FORCE_INLINE void AddCandidate(T* aObject, TUint aColour) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
656 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
657 |
// allocate objects to slots based on colour |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
658 |
for (TUint i = aColour ; i < iSearchLength ; i += KPageColourCount) |
0 | 659 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
660 |
if (!iSlot[i]) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
661 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
662 |
iSlot[i] = aObject; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
663 |
iSeqLength[i] = i == 0 ? 1 : iSeqLength[i - 1] + 1; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
664 |
TUint j = i + 1; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
665 |
while(j < iSearchLength && iSeqLength[j]) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
666 |
iSeqLength[j++] += iSeqLength[i]; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
667 |
TUint currentLength = iSeqLength[j - 1]; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
668 |
if (currentLength > iLongestLength) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
669 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
670 |
iLongestLength = currentLength; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
671 |
iLongestStart = j - currentLength; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
672 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
673 |
break; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
674 |
} |
0 | 675 |
} |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
676 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
677 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
678 |
FORCE_INLINE TUint FindLongestRun(T** aObjectsOut) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
679 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
680 |
if (iLongestLength == 0) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
681 |
return 0; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
682 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
683 |
if (iLongestLength < iTargetLength && iSlot[0] && iSlot[iSearchLength - 1]) |
0 | 684 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
685 |
// check possibility of wrapping |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
686 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
687 |
TInt i = 1; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
688 |
while (iSlot[i]) ++i; // find first hole |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
689 |
TUint wrappedLength = iSeqLength[iSearchLength - 1] + iSeqLength[i - 1]; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
690 |
if (wrappedLength > iLongestLength) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
691 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
692 |
iLongestLength = wrappedLength; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
693 |
iLongestStart = iSearchLength - iSeqLength[iSearchLength - 1]; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
694 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
695 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
696 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
697 |
iLongestLength = MinU(iLongestLength, iTargetLength); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
698 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
699 |
__NK_ASSERT_DEBUG(iLongestStart < iSearchLength); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
700 |
__NK_ASSERT_DEBUG(iLongestStart + iLongestLength < 2 * iSearchLength); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
701 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
702 |
TUint len = MinU(iLongestLength, iSearchLength - iLongestStart); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
703 |
wordmove(aObjectsOut, &iSlot[iLongestStart], len * sizeof(T*)); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
704 |
wordmove(aObjectsOut + len, &iSlot[0], (iLongestLength - len) * sizeof(T*)); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
705 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
706 |
return iLongestLength; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
707 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
708 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
709 |
private: |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
710 |
TUint iTargetLength; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
711 |
TUint iSearchLength; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
712 |
TUint iLongestStart; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
713 |
TUint iLongestLength; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
714 |
T* iSlot[KMaxSearchLength]; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
715 |
TUint8 iSeqLength[KMaxSearchLength]; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
716 |
}; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
717 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
718 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
719 |
TInt DPager::SelectSequentialPagesToClean(SPageInfo** aPageInfosOut) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
720 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
721 |
// select up to iPagesToClean oldest dirty pages with sequential page colours |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
722 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
723 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
724 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
725 |
TSequentialColourSelector<SPageInfo, KMaxPagesToClean> selector(iPagesToClean); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
726 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
727 |
SDblQueLink* link = iOldestDirtyList.Last(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
728 |
while (link != &iOldestDirtyList.iA) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
729 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
730 |
SPageInfo* pi = SPageInfo::FromLink(link); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
731 |
if (!pi->IsWritable()) |
0 | 732 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
733 |
// the page may be in the process of being restricted, stolen or decommitted, but don't |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
734 |
// check for this as it will occur infrequently and will be detected by CheckModified |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
735 |
// anyway |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
736 |
TInt colour = pi->Index() & KPageColourMask; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
737 |
selector.AddCandidate(pi, colour); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
738 |
if (selector.FoundLongestSequence()) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
739 |
break; |
0 | 740 |
} |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
741 |
link = link->iPrev; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
742 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
743 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
744 |
return selector.FindLongestRun(aPageInfosOut); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
745 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
746 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
747 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
748 |
TInt DPager::SelectOldestPagesToClean(SPageInfo** aPageInfosOut) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
749 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
750 |
// select up to iPagesToClean oldest dirty pages |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
751 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
752 |
TUint pageCount = 0; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
753 |
SDblQueLink* link = iOldestDirtyList.Last(); |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
754 |
while (link != &iOldestDirtyList.iA && pageCount < iPagesToClean) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
755 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
756 |
SPageInfo* pi = SPageInfo::FromLink(link); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
757 |
if (!pi->IsWritable()) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
758 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
759 |
// the page may be in the process of being restricted, stolen or decommitted, but don't |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
760 |
// check for this as it will occur infrequently and will be detected by CheckModified |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
761 |
// anyway |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
762 |
aPageInfosOut[pageCount++] = pi; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
763 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
764 |
link = link->iPrev; |
0 | 765 |
} |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
766 |
return pageCount; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
767 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
768 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
769 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
770 |
TInt DPager::CleanSomePages(TBool aBackground) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
771 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
772 |
TRACE(("DPager::CleanSomePages")); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
773 |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
774 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
775 |
__NK_ASSERT_DEBUG(PageCleaningLock::IsHeld()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
776 |
// ram alloc lock may or may not be held |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
777 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
778 |
SPageInfo* pageInfos[KMaxPagesToClean]; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
779 |
TInt pageCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
780 |
if (iCleanInSequence) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
781 |
pageCount = SelectSequentialPagesToClean(&pageInfos[0]); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
782 |
else |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
783 |
pageCount = SelectOldestPagesToClean(&pageInfos[0]); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
784 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
785 |
if (pageCount == 0) |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
786 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
787 |
TRACE2(("DPager::CleanSomePages no pages to clean", pageCount)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
788 |
TRACE2((" page counts %d, %d, %d, %d", |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
789 |
iYoungCount, iOldCount, iOldestCleanCount, iOldestDirtyCount)); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
790 |
return 0; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
791 |
} |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
792 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
793 |
TheDataPagedMemoryManager->CleanPages(pageCount, pageInfos, aBackground); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
794 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
795 |
for (TInt i = 0 ; i < pageCount ; ++i) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
796 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
797 |
SPageInfo* pi = pageInfos[i]; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
798 |
if (pi) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
799 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
800 |
__NK_ASSERT_DEBUG(pi->PagedState() == SPageInfo::EPagedOldestDirty && iOldestDirtyCount); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
801 |
__NK_ASSERT_DEBUG(!pi->IsDirty() && !pi->IsWritable()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
802 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
803 |
pi->iLink.Deque(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
804 |
iOldestCleanList.AddHead(&pi->iLink); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
805 |
--iOldestDirtyCount; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
806 |
++iOldestCleanCount; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
807 |
pi->SetPagedState(SPageInfo::EPagedOldestClean); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
808 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
809 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
810 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
811 |
TRACE2(("DPager::CleanSomePages cleaned %d pages", pageCount)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
812 |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
813 |
return pageCount; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
814 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
815 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
816 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
817 |
TBool DPager::HasPagesToClean() |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
818 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
819 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
820 |
return iOldestDirtyCount > 0; |
0 | 821 |
} |
822 |
||
823 |
||
824 |
TInt DPager::RestrictPage(SPageInfo* aPageInfo, TRestrictPagesType aRestriction) |
|
825 |
{ |
|
826 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
827 |
||
828 |
TInt r; |
|
829 |
if(aPageInfo->Type()==SPageInfo::EUnused) |
|
830 |
{ |
|
831 |
// page was unused, so nothing to do... |
|
832 |
r = KErrNone; |
|
833 |
} |
|
834 |
else |
|
835 |
{ |
|
836 |
// get memory object which owns the page... |
|
837 |
__NK_ASSERT_DEBUG(aPageInfo->Type()==SPageInfo::EManaged); |
|
838 |
DMemoryObject* memory = aPageInfo->Owner(); |
|
839 |
memory->Open(); |
|
840 |
||
841 |
// try restricting access to page... |
|
842 |
r = memory->iManager->RestrictPage(memory,aPageInfo,aRestriction); |
|
843 |
__NK_ASSERT_DEBUG(r!=KErrNotSupported); |
|
844 |
||
845 |
// close memory object... |
|
846 |
MmuLock::Unlock(); |
|
847 |
memory->AsyncClose(); |
|
848 |
MmuLock::Lock(); |
|
849 |
} |
|
850 |
||
851 |
return r; |
|
852 |
} |
|
853 |
||
854 |
||
855 |
TInt DPager::StealPage(SPageInfo* aPageInfo) |
|
856 |
{ |
|
857 |
TRACE(("DPager::StealPage(0x%08x)",aPageInfo)); |
|
858 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
859 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
860 |
||
861 |
__UNLOCK_GUARD_START(MmuLock); |
|
862 |
RemovePage(aPageInfo); |
|
863 |
||
864 |
TInt r; |
|
865 |
if(aPageInfo->Type()==SPageInfo::EUnused) |
|
866 |
{ |
|
867 |
// page was unused, so nothing to do... |
|
868 |
r = KErrNone; |
|
869 |
__UNLOCK_GUARD_END(MmuLock); |
|
870 |
MmuLock::Unlock(); |
|
871 |
} |
|
872 |
else |
|
873 |
{ |
|
874 |
// get memory object which owns the page... |
|
875 |
__NK_ASSERT_DEBUG(aPageInfo->Type()==SPageInfo::EManaged); |
|
876 |
DMemoryObject* memory = aPageInfo->Owner(); |
|
877 |
memory->Open(); |
|
878 |
||
879 |
// try and steal page from memory object... |
|
880 |
__UNLOCK_GUARD_END(MmuLock); // StealPage must be called without releasing the MmuLock |
|
881 |
r = memory->iManager->StealPage(memory,aPageInfo); |
|
882 |
__NK_ASSERT_DEBUG(r!=KErrNotSupported); |
|
883 |
||
884 |
// close memory object... |
|
885 |
MmuLock::Unlock(); |
|
886 |
memory->AsyncClose(); |
|
887 |
} |
|
888 |
||
889 |
MmuLock::Lock(); |
|
890 |
||
891 |
if(r==KErrNone) |
|
892 |
Event(EEventPageOut,aPageInfo); |
|
893 |
||
894 |
TRACE(("DPager::StealPage returns %d",r)); |
|
895 |
return r; |
|
896 |
} |
|
897 |
||
898 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
899 |
TInt DPager::DiscardAndAllocPage(SPageInfo* aPageInfo, TZonePageType aPageType) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
900 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
901 |
TInt r = DiscardPage(aPageInfo, KRamZoneInvalidId, M::EMoveDisMoveDirty); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
902 |
if (r == KErrNone) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
903 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
904 |
TheMmu.MarkPageAllocated(aPageInfo->PhysAddr(), aPageType); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
905 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
906 |
return r; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
907 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
908 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
909 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
910 |
static TBool DiscardCanStealPage(SPageInfo* aOldPageInfo, TBool aMoveDirty) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
911 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
912 |
// If the page is pinned or if the page is dirty and a general defrag is being performed then |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
913 |
// don't attempt to steal it |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
914 |
return aOldPageInfo->Type() == SPageInfo::EUnused || |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
915 |
(aOldPageInfo->PagedState() != SPageInfo::EPagedPinned && (!aMoveDirty || !aOldPageInfo->IsDirty())); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
916 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
917 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
918 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
919 |
TInt DPager::DiscardPage(SPageInfo* aOldPageInfo, TUint aBlockZoneId, TUint aMoveDisFlags) |
0 | 920 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
921 |
// todo: assert MmuLock not released |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
922 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
923 |
TRACE(("> DPager::DiscardPage %08x", aOldPageInfo)); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
924 |
|
0 | 925 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
926 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
927 |
TBool moveDirty = (aMoveDisFlags & M::EMoveDisMoveDirty) != 0; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
928 |
TBool blockRest = (aMoveDisFlags & M::EMoveDisBlockRest) != 0; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
929 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
930 |
if (!DiscardCanStealPage(aOldPageInfo, moveDirty)) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
931 |
{ |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
932 |
// Page must be managed if it is pinned or dirty. |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
933 |
__NK_ASSERT_DEBUG(aOldPageInfo->Type()==SPageInfo::EManaged); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
934 |
// The page is pinned or is dirty and this is a general defrag so move the page. |
0 | 935 |
DMemoryObject* memory = aOldPageInfo->Owner(); |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
936 |
memory->Open(); |
0 | 937 |
TPhysAddr newAddr; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
938 |
TRACE2(("DPager::DiscardPage delegating pinned/dirty page to manager")); |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
939 |
TInt r = memory->iManager->MovePage(memory, aOldPageInfo, newAddr, aBlockZoneId, blockRest); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
940 |
TRACE(("< DPager::DiscardPage %d", r)); |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
941 |
memory->AsyncClose(); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
942 |
return r; |
0 | 943 |
} |
944 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
945 |
TInt r = KErrNone; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
946 |
SPageInfo* newPageInfo = NULL; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
947 |
TBool havePageCleaningLock = EFalse; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
948 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
949 |
TBool needNewPage; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
950 |
TBool needPageCleaningLock; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
951 |
while(needNewPage = (iNumberOfFreePages == 0 && newPageInfo == NULL), |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
952 |
needPageCleaningLock = (aOldPageInfo->IsDirty() && !havePageCleaningLock), |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
953 |
needNewPage || needPageCleaningLock) |
0 | 954 |
{ |
955 |
MmuLock::Unlock(); |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
956 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
957 |
if (needNewPage) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
958 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
959 |
// Allocate a new page for the live list as it has reached its minimum size. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
960 |
TUint flags = EMemAttNormalCached | Mmu::EAllocNoWipe; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
961 |
newPageInfo = GetPageFromSystem((Mmu::TRamAllocFlags)flags, aBlockZoneId, blockRest); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
962 |
if (!newPageInfo) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
963 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
964 |
TRACE(("< DPager::DiscardPage KErrNoMemory")); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
965 |
r = KErrNoMemory; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
966 |
MmuLock::Lock(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
967 |
break; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
968 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
969 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
970 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
971 |
if (needPageCleaningLock) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
972 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
973 |
// Acquire the page cleaning mutex so StealPage can clean it |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
974 |
PageCleaningLock::Lock(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
975 |
havePageCleaningLock = ETrue; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
976 |
} |
0 | 977 |
|
978 |
// Re-acquire the mmulock and re-check that the page is not pinned or dirty. |
|
979 |
MmuLock::Lock(); |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
980 |
if (!DiscardCanStealPage(aOldPageInfo, moveDirty)) |
0 | 981 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
982 |
// Page is now pinned or dirty so give up as it is in use. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
983 |
r = KErrInUse; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
984 |
break; |
0 | 985 |
} |
986 |
} |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
987 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
988 |
if (r == KErrNone) |
0 | 989 |
{ |
990 |
// Attempt to steal the page |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
991 |
r = StealPage(aOldPageInfo); // temporarily releases MmuLock if page is dirty |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
992 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
993 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
994 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
995 |
if (r == KErrCompletion) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
996 |
{// This was a page table that has been freed but added to the |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
997 |
// live list as a free page. Remove from live list and continue. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
998 |
__NK_ASSERT_DEBUG(!aOldPageInfo->IsDirty()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
999 |
RemovePage(aOldPageInfo); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1000 |
r = KErrNone; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1001 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1002 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1003 |
if (r == KErrNone && iNumberOfFreePages == 0) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1004 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1005 |
if (newPageInfo) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1006 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1007 |
// Add a new page to the live list if we have one as discarding the old page will reduce |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1008 |
// the live list below the minimum. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1009 |
AddAsFreePage(newPageInfo); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1010 |
newPageInfo = NULL; |
0 | 1011 |
} |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1012 |
else |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1013 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1014 |
// Otherwise the live list shrank when page was being cleaned so have to give up |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1015 |
AddAsFreePage(aOldPageInfo); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1016 |
BalanceAges(); // temporarily releases MmuLock |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1017 |
r = KErrInUse; |
0 | 1018 |
} |
1019 |
} |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1020 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1021 |
if (r == KErrNone) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1022 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1023 |
// We've successfully discarded the page and ensured the live list is large enough, so |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1024 |
// return it to the free pool. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1025 |
ReturnPageToSystem(*aOldPageInfo); // temporarily releases MmuLock |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1026 |
BalanceAges(); // temporarily releases MmuLock |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1027 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1028 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1029 |
if (newPageInfo) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1030 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1031 |
// New page not required so just return it to the system. This is safe as |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1032 |
// iNumberOfFreePages will have this page counted but as it is not on the live list noone |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1033 |
// else can touch it. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1034 |
if (iNumberOfFreePages == 0) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1035 |
AddAsFreePage(newPageInfo); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1036 |
else |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1037 |
ReturnPageToSystem(*newPageInfo); // temporarily releases MmuLock |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1038 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1039 |
MmuLock::Unlock(); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1040 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1041 |
if (havePageCleaningLock) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1042 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1043 |
// Release the page cleaning mutex |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1044 |
PageCleaningLock::Unlock(); |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1045 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1046 |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1047 |
TRACE(("< DPager::DiscardPage returns %d", r)); |
0 | 1048 |
return r; |
1049 |
} |
|
1050 |
||
1051 |
||
1052 |
TBool DPager::TryGrowLiveList() |
|
1053 |
{ |
|
1054 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1055 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1056 |
||
1057 |
MmuLock::Unlock(); |
|
1058 |
SPageInfo* sparePage = GetPageFromSystem((Mmu::TRamAllocFlags)(EMemAttNormalCached|Mmu::EAllocNoWipe)); |
|
1059 |
MmuLock::Lock(); |
|
1060 |
||
1061 |
if(!sparePage) |
|
1062 |
return false; |
|
1063 |
||
1064 |
// add page to live list... |
|
1065 |
AddAsFreePage(sparePage); |
|
1066 |
return true; |
|
1067 |
} |
|
1068 |
||
1069 |
||
1070 |
SPageInfo* DPager::GetPageFromSystem(Mmu::TRamAllocFlags aAllocFlags, TUint aBlockZoneId, TBool aBlockRest) |
|
1071 |
{ |
|
1072 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1073 |
||
1074 |
TPhysAddr pagePhys; |
|
1075 |
TInt r = TheMmu.AllocRam(&pagePhys, 1, |
|
1076 |
(Mmu::TRamAllocFlags)(aAllocFlags|Mmu::EAllocNoPagerReclaim), |
|
1077 |
EPageDiscard, aBlockZoneId, aBlockRest); |
|
1078 |
if(r!=KErrNone) |
|
1079 |
return NULL; |
|
1080 |
||
1081 |
MmuLock::Lock(); |
|
1082 |
++iNumberOfFreePages; |
|
1083 |
MmuLock::Unlock(); |
|
1084 |
||
1085 |
return SPageInfo::FromPhysAddr(pagePhys); |
|
1086 |
} |
|
1087 |
||
1088 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1089 |
TBool DPager::TryReturnOldestPageToSystem() |
0 | 1090 |
{ |
1091 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1092 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1093 |
__NK_ASSERT_DEBUG(iNumberOfFreePages>0); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1094 |
|
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1095 |
SPageInfo* pageInfo = StealOrAllocPage(EFalse, (Mmu::TRamAllocFlags)0); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1096 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1097 |
// StealOrAllocPage may have released the MmuLock, so check there are still enough pages |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1098 |
// to remove one from the live list |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1099 |
if (iNumberOfFreePages>0) |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1100 |
{ |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1101 |
ReturnPageToSystem(*pageInfo); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1102 |
return ETrue; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1103 |
} |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1104 |
else |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1105 |
{ |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1106 |
AddAsFreePage(pageInfo); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1107 |
return EFalse; |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1108 |
} |
0 | 1109 |
} |
1110 |
||
1111 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1112 |
TUint DPager::AllowAddFreePages(SPageInfo*& aPageInfo, TUint aNumPages) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1113 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1114 |
if (iMinimumPageCount + iNumberOfFreePages == iMaximumPageCount) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1115 |
{// The paging cache is already at the maximum size so steal a page |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1116 |
// so it can be returned to the system if required. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1117 |
aPageInfo = StealOrAllocPage(EFalse, (Mmu::TRamAllocFlags)0); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1118 |
__NK_ASSERT_DEBUG(aPageInfo->PagedState() == SPageInfo::EUnpaged); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1119 |
return 1; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1120 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1121 |
// The paging cache is not at its maximum so determine how many can be added to |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1122 |
// the paging cache without it growing past its maximum. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1123 |
aPageInfo = NULL; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1124 |
__NK_ASSERT_DEBUG(iMinimumPageCount + iNumberOfFreePages < iMaximumPageCount); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1125 |
if (iMinimumPageCount + iNumberOfFreePages + aNumPages > iMaximumPageCount) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1126 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1127 |
return iMaximumPageCount - (iMinimumPageCount + iNumberOfFreePages); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1128 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1129 |
else |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1130 |
return aNumPages; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1131 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1132 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1133 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1134 |
void DPager::AllowAddFreePage(SPageInfo*& aPageInfo) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1135 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1136 |
if (iMinimumPageCount + iNumberOfFreePages == iMaximumPageCount) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1137 |
{// The paging cache is already at the maximum size so steal a page |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1138 |
// so it can be returned to the system if required. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1139 |
aPageInfo = StealOrAllocPage(EFalse, (Mmu::TRamAllocFlags)0); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1140 |
__NK_ASSERT_DEBUG(aPageInfo->PagedState() == SPageInfo::EUnpaged); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1141 |
return; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1142 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1143 |
aPageInfo = NULL; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1144 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1145 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1146 |
|
0 | 1147 |
void DPager::ReturnPageToSystem(SPageInfo& aPageInfo) |
1148 |
{ |
|
1149 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1150 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1151 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1152 |
// should be unpaged at this point, otherwise Mmu::FreeRam will just give it back to us |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1153 |
__NK_ASSERT_DEBUG(aPageInfo.PagedState() == SPageInfo::EUnpaged); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1154 |
|
0 | 1155 |
__NK_ASSERT_DEBUG(iNumberOfFreePages>0); |
1156 |
--iNumberOfFreePages; |
|
1157 |
||
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1158 |
// The page must be unpaged, otherwise it wasn't successfully removed |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1159 |
// from the live list. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1160 |
__NK_ASSERT_DEBUG(aPageInfo.PagedState() == SPageInfo::EUnpaged); |
0 | 1161 |
MmuLock::Unlock(); |
1162 |
||
1163 |
TPhysAddr pagePhys = aPageInfo.PhysAddr(); |
|
1164 |
TheMmu.FreeRam(&pagePhys, 1, EPageDiscard); |
|
1165 |
||
1166 |
MmuLock::Lock(); |
|
1167 |
} |
|
1168 |
||
1169 |
||
1170 |
SPageInfo* DPager::PageInAllocPage(Mmu::TRamAllocFlags aAllocFlags) |
|
1171 |
{ |
|
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1172 |
// ram alloc mutex may or may not be held |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1173 |
__NK_ASSERT_DEBUG(!MmuLock::IsHeld()); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1174 |
|
0 | 1175 |
RamAllocLock::Lock(); |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1176 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1177 |
MmuLock::Lock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1178 |
SPageInfo* pageInfo = StealOrAllocPage(ETrue, aAllocFlags); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1179 |
TBool wasAllocated = pageInfo->Type() == SPageInfo::EUnknown; |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1180 |
MmuLock::Unlock(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1181 |
|
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1182 |
if (!wasAllocated) |
0 | 1183 |
{ |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1184 |
// make page state same as a freshly allocated page... |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1185 |
TPhysAddr pagePhys = pageInfo->PhysAddr(); |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1186 |
TheMmu.PagesAllocated(&pagePhys,1,aAllocFlags); |
0 | 1187 |
} |
1188 |
||
1189 |
RamAllocLock::Unlock(); |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1190 |
|
0 | 1191 |
return pageInfo; |
1192 |
} |
|
1193 |
||
1194 |
||
1195 |
TBool DPager::GetFreePages(TInt aNumPages) |
|
1196 |
{ |
|
1197 |
TRACE(("DPager::GetFreePages(%d)",aNumPages)); |
|
1198 |
||
1199 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1200 |
||
1201 |
MmuLock::Lock(); |
|
1202 |
while(aNumPages>0 && (TInt)NumberOfFreePages()>=aNumPages) |
|
1203 |
{ |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1204 |
if (TryReturnOldestPageToSystem()) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1205 |
--aNumPages; |
0 | 1206 |
} |
1207 |
MmuLock::Unlock(); |
|
1208 |
||
1209 |
TRACE(("DPager::GetFreePages returns %d",!aNumPages)); |
|
1210 |
return !aNumPages; |
|
1211 |
} |
|
1212 |
||
1213 |
||
1214 |
void DPager::DonatePages(TUint aCount, TPhysAddr* aPages) |
|
1215 |
{ |
|
1216 |
TRACE(("DPager::DonatePages(%d,?)",aCount)); |
|
1217 |
__ASSERT_CRITICAL; |
|
1218 |
RamAllocLock::Lock(); |
|
1219 |
MmuLock::Lock(); |
|
1220 |
||
1221 |
TPhysAddr* end = aPages+aCount; |
|
1222 |
while(aPages<end) |
|
1223 |
{ |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1224 |
// Steal a page from the paging cache in case we need to return one to the system. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1225 |
// This may release the ram alloc lock. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1226 |
SPageInfo* pageInfo; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1227 |
AllowAddFreePage(pageInfo); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1228 |
|
0 | 1229 |
TPhysAddr pagePhys = *aPages++; |
1230 |
if(RPageArray::State(pagePhys)!=RPageArray::ECommitted) |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1231 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1232 |
if (pageInfo) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1233 |
AddAsFreePage(pageInfo); |
0 | 1234 |
continue; // page is not present |
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1235 |
} |
0 | 1236 |
|
1237 |
#ifdef _DEBUG |
|
1238 |
SPageInfo* pi = SPageInfo::SafeFromPhysAddr(pagePhys&~KPageMask); |
|
1239 |
__NK_ASSERT_DEBUG(pi); |
|
1240 |
#else |
|
1241 |
SPageInfo* pi = SPageInfo::FromPhysAddr(pagePhys); |
|
1242 |
#endif |
|
1243 |
switch(pi->PagedState()) |
|
1244 |
{ |
|
1245 |
case SPageInfo::EUnpaged: |
|
1246 |
// Change the type of this page to discardable and |
|
1247 |
// then add it to live list. |
|
1248 |
// Only the DDiscardableMemoryManager should be invoking this and |
|
1249 |
// its pages will be movable before they are donated. |
|
1250 |
__NK_ASSERT_DEBUG(pi->Owner()->iManager->PageType() == EPageMovable); |
|
1251 |
TheMmu.ChangePageType(pi, EPageMovable, EPageDiscard); |
|
1252 |
break; |
|
1253 |
||
1254 |
case SPageInfo::EPagedYoung: |
|
1255 |
case SPageInfo::EPagedOld: |
|
1256 |
case SPageInfo::EPagedOldestDirty: |
|
1257 |
case SPageInfo::EPagedOldestClean: |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1258 |
if (pageInfo) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1259 |
AddAsFreePage(pageInfo); |
0 | 1260 |
continue; // discard already been allowed |
1261 |
||
1262 |
case SPageInfo::EPagedPinned: |
|
1263 |
__NK_ASSERT_DEBUG(0); |
|
1264 |
default: |
|
1265 |
__NK_ASSERT_DEBUG(0); |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1266 |
if (pageInfo) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1267 |
AddAsFreePage(pageInfo); |
0 | 1268 |
continue; |
1269 |
} |
|
1270 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1271 |
// put page on live list and free the stolen page... |
0 | 1272 |
AddAsYoungestPage(pi); |
1273 |
++iNumberOfFreePages; |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1274 |
if (pageInfo) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1275 |
ReturnPageToSystem(*pageInfo); |
0 | 1276 |
Event(EEventPageDonate,pi); |
1277 |
||
1278 |
// re-balance live list... |
|
1279 |
BalanceAges(); |
|
1280 |
} |
|
1281 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1282 |
__NK_ASSERT_DEBUG((iMinimumPageCount + iNumberOfFreePages) <= iMaximumPageCount); |
0 | 1283 |
MmuLock::Unlock(); |
1284 |
RamAllocLock::Unlock(); |
|
1285 |
} |
|
1286 |
||
1287 |
||
1288 |
TInt DPager::ReclaimPages(TUint aCount, TPhysAddr* aPages) |
|
1289 |
{ |
|
1290 |
TRACE(("DPager::ReclaimPages(%d,?)",aCount)); |
|
1291 |
__ASSERT_CRITICAL; |
|
1292 |
RamAllocLock::Lock(); |
|
1293 |
MmuLock::Lock(); |
|
1294 |
||
1295 |
TInt r = KErrNone; |
|
1296 |
TPhysAddr* end = aPages+aCount; |
|
1297 |
while(aPages<end) |
|
1298 |
{ |
|
1299 |
TPhysAddr pagePhys = *aPages++; |
|
1300 |
TBool changeType = EFalse; |
|
1301 |
||
1302 |
if(RPageArray::State(pagePhys)!=RPageArray::ECommitted) |
|
1303 |
{ |
|
1304 |
r = KErrNotFound; // too late, page has gone |
|
1305 |
continue; |
|
1306 |
} |
|
1307 |
||
1308 |
#ifdef _DEBUG |
|
1309 |
SPageInfo* pi = SPageInfo::SafeFromPhysAddr(pagePhys&~KPageMask); |
|
1310 |
__NK_ASSERT_DEBUG(pi); |
|
1311 |
#else |
|
1312 |
SPageInfo* pi = SPageInfo::FromPhysAddr(pagePhys); |
|
1313 |
#endif |
|
1314 |
switch(pi->PagedState()) |
|
1315 |
{ |
|
1316 |
case SPageInfo::EUnpaged: |
|
1317 |
continue; // discard already been disallowed |
|
1318 |
||
1319 |
case SPageInfo::EPagedYoung: |
|
1320 |
case SPageInfo::EPagedOld: |
|
1321 |
case SPageInfo::EPagedOldestClean: |
|
1322 |
case SPageInfo::EPagedOldestDirty: |
|
1323 |
changeType = ETrue; |
|
1324 |
break; // remove from live list |
|
1325 |
||
1326 |
case SPageInfo::EPagedPinned: |
|
1327 |
__NK_ASSERT_DEBUG(0); |
|
1328 |
default: |
|
1329 |
__NK_ASSERT_DEBUG(0); |
|
1330 |
break; |
|
1331 |
} |
|
1332 |
||
1333 |
// check paging list has enough pages before we remove one... |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1334 |
if(!iNumberOfFreePages) |
0 | 1335 |
{ |
1336 |
// need more pages so get a page from the system... |
|
1337 |
if(!TryGrowLiveList()) |
|
1338 |
{ |
|
1339 |
// out of memory... |
|
1340 |
r = KErrNoMemory; |
|
1341 |
break; |
|
1342 |
} |
|
1343 |
// retry the page reclaim... |
|
1344 |
--aPages; |
|
1345 |
continue; |
|
1346 |
} |
|
1347 |
||
1348 |
if (changeType) |
|
1349 |
{// Change the type of this page to movable, wait until any retries |
|
1350 |
// have been attempted as we can't change a page's type twice. |
|
1351 |
// Only the DDiscardableMemoryManager should be invoking this and |
|
1352 |
// its pages should be movable once they are reclaimed. |
|
1353 |
__NK_ASSERT_DEBUG(pi->Owner()->iManager->PageType() == EPageMovable); |
|
1354 |
TheMmu.ChangePageType(pi, EPageDiscard, EPageMovable); |
|
1355 |
} |
|
1356 |
||
1357 |
// remove page from paging list... |
|
1358 |
__NK_ASSERT_DEBUG(iNumberOfFreePages>0); |
|
1359 |
--iNumberOfFreePages; |
|
1360 |
RemovePage(pi); |
|
1361 |
||
1362 |
Event(EEventPageReclaim,pi); |
|
1363 |
||
1364 |
// re-balance live list... |
|
1365 |
BalanceAges(); |
|
1366 |
} |
|
1367 |
||
1368 |
// we may have added a spare free page to the live list without removing one, |
|
1369 |
// this could cause us to have too many pages, so deal with this... |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1370 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1371 |
// If there are too many pages they should all be unused free pages otherwise |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1372 |
// the ram alloc lock may be released by RemoveExcessPages(). |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1373 |
__NK_ASSERT_DEBUG( !HaveTooManyPages() || |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1374 |
(iMinimumPageCount + iNumberOfFreePages - iMaximumPageCount |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1375 |
<= iOldestCleanCount)); |
0 | 1376 |
RemoveExcessPages(); |
1377 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1378 |
__NK_ASSERT_DEBUG((iMinimumPageCount + iNumberOfFreePages) <= iMaximumPageCount); |
0 | 1379 |
MmuLock::Unlock(); |
1380 |
RamAllocLock::Unlock(); |
|
1381 |
return r; |
|
1382 |
} |
|
1383 |
||
1384 |
||
1385 |
TInt VMHalFunction(TAny*, TInt aFunction, TAny* a1, TAny* a2); |
|
1386 |
||
1387 |
void DPager::Init3() |
|
1388 |
{ |
|
1389 |
TRACEB(("DPager::Init3()")); |
|
1390 |
TheRomMemoryManager->Init3(); |
|
1391 |
TheDataPagedMemoryManager->Init3(); |
|
1392 |
TheCodePagedMemoryManager->Init3(); |
|
1393 |
TInt r = Kern::AddHalEntry(EHalGroupVM, VMHalFunction, 0); |
|
1394 |
__NK_ASSERT_ALWAYS(r==KErrNone); |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1395 |
PageCleaningLock::Init(); |
0 | 1396 |
} |
1397 |
||
1398 |
||
1399 |
void DPager::Fault(TFault aFault) |
|
1400 |
{ |
|
1401 |
Kern::Fault("DPager",aFault); |
|
1402 |
} |
|
1403 |
||
1404 |
||
1405 |
void DPager::BalanceAges() |
|
1406 |
{ |
|
1407 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1408 |
TBool retry; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1409 |
do |
0 | 1410 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1411 |
retry = EFalse; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1412 |
TBool restrictPage = EFalse; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1413 |
SPageInfo* pageInfo = NULL; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1414 |
TUint oldestCount = iOldestCleanCount + iOldestDirtyCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1415 |
if((iOldCount + oldestCount) * iYoungOldRatio < iYoungCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1416 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1417 |
// Need more old pages so make one young page into an old page... |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1418 |
__NK_ASSERT_DEBUG(!iYoungList.IsEmpty()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1419 |
__NK_ASSERT_DEBUG(iYoungCount); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1420 |
SDblQueLink* link = iYoungList.Last()->Deque(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1421 |
--iYoungCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1422 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1423 |
pageInfo = SPageInfo::FromLink(link); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1424 |
pageInfo->SetPagedState(SPageInfo::EPagedOld); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1425 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1426 |
iOldList.AddHead(link); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1427 |
++iOldCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1428 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1429 |
Event(EEventPageAged,pageInfo); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1430 |
// Delay restricting the page until it is safe to release the MmuLock. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1431 |
restrictPage = ETrue; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1432 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1433 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1434 |
// Check we have enough oldest pages. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1435 |
if (oldestCount < iMaxOldestPages && |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1436 |
oldestCount * iOldOldestRatio < iOldCount) |
0 | 1437 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1438 |
__NK_ASSERT_DEBUG(!iOldList.IsEmpty()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1439 |
__NK_ASSERT_DEBUG(iOldCount); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1440 |
SDblQueLink* link = iOldList.Last()->Deque(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1441 |
--iOldCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1442 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1443 |
SPageInfo* oldestPageInfo = SPageInfo::FromLink(link); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1444 |
if (oldestPageInfo->IsDirty()) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1445 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1446 |
oldestPageInfo->SetOldestPage(SPageInfo::EPagedOldestDirty); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1447 |
iOldestDirtyList.AddHead(link); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1448 |
++iOldestDirtyCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1449 |
PageCleaner::NotifyPagesToClean(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1450 |
Event(EEventPageAgedDirty,oldestPageInfo); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1451 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1452 |
else |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1453 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1454 |
oldestPageInfo->SetOldestPage(SPageInfo::EPagedOldestClean); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1455 |
iOldestCleanList.AddHead(link); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1456 |
++iOldestCleanCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1457 |
Event(EEventPageAgedClean,oldestPageInfo); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1458 |
} |
0 | 1459 |
} |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1460 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1461 |
if (restrictPage) |
0 | 1462 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1463 |
// Make the recently aged old page inaccessible. This is done last as it will release |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1464 |
// the MmuLock and therefore the page counts may otherwise change. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1465 |
TInt r = RestrictPage(pageInfo,ERestrictPagesNoAccessForOldPage); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1466 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1467 |
if (r == KErrInUse) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1468 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1469 |
SPageInfo::TPagedState state = pageInfo->PagedState(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1470 |
if (state == SPageInfo::EPagedOld || |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1471 |
state == SPageInfo::EPagedOldestClean || |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1472 |
state == SPageInfo::EPagedOldestDirty) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1473 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1474 |
// The restrict operation failed, but the page was left in an old state. This |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1475 |
// can happen when: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1476 |
// |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1477 |
// - pages are in the process of being pinned - the mapping will veto the |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1478 |
// restriction |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1479 |
// - pages are rejuvenated and then become quickly become old again |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1480 |
// |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1481 |
// In the second instance the page will be needlessly rejuvenated because we |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1482 |
// can't tell that it has actually been restricted by another thread |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1483 |
RemovePage(pageInfo); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1484 |
AddAsYoungestPage(pageInfo); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1485 |
retry = ETrue; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1486 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1487 |
} |
0 | 1488 |
} |
1489 |
} |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1490 |
while (retry); |
0 | 1491 |
} |
1492 |
||
1493 |
||
1494 |
void DPager::RemoveExcessPages() |
|
1495 |
{ |
|
1496 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1497 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1498 |
while(HaveTooManyPages()) |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1499 |
TryReturnOldestPageToSystem(); |
0 | 1500 |
} |
1501 |
||
1502 |
||
1503 |
void DPager::RejuvenatePageTable(TPte* aPt) |
|
1504 |
{ |
|
1505 |
SPageInfo* pi = SPageInfo::FromPhysAddr(Mmu::PageTablePhysAddr(aPt)); |
|
1506 |
||
1507 |
SPageTableInfo* pti = SPageTableInfo::FromPtPtr(aPt); |
|
1508 |
if(!pti->IsDemandPaged()) |
|
1509 |
{ |
|
1510 |
__NK_ASSERT_DEBUG(pi->PagedState()==SPageInfo::EUnpaged); |
|
1511 |
return; |
|
1512 |
} |
|
1513 |
||
1514 |
TRACE2(("DP: %O Rejuvenate PT 0x%08x 0x%08x",TheCurrentThread,pi->PhysAddr(),aPt)); |
|
1515 |
switch(pi->PagedState()) |
|
1516 |
{ |
|
1517 |
case SPageInfo::EPagedYoung: |
|
1518 |
case SPageInfo::EPagedOld: |
|
1519 |
case SPageInfo::EPagedOldestClean: |
|
1520 |
case SPageInfo::EPagedOldestDirty: |
|
1521 |
RemovePage(pi); |
|
1522 |
AddAsYoungestPage(pi); |
|
1523 |
BalanceAges(); |
|
1524 |
break; |
|
1525 |
||
1526 |
case SPageInfo::EUnpaged: |
|
1527 |
AddAsYoungestPage(pi); |
|
1528 |
BalanceAges(); |
|
1529 |
break; |
|
1530 |
||
1531 |
case SPageInfo::EPagedPinned: |
|
1532 |
break; |
|
1533 |
||
1534 |
default: |
|
1535 |
__NK_ASSERT_DEBUG(0); |
|
1536 |
break; |
|
1537 |
} |
|
1538 |
} |
|
1539 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1540 |
|
0 | 1541 |
TInt DPager::PteAndInfoFromLinAddr( TInt aOsAsid, TLinAddr aAddress, DMemoryMappingBase* aMapping, |
1542 |
TUint aMapInstanceCount, TPte*& aPte, SPageInfo*& aPageInfo) |
|
1543 |
{ |
|
1544 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1545 |
||
1546 |
// Verify the mapping is still mapped and has not been reused. |
|
1547 |
if (aMapInstanceCount != aMapping->MapInstanceCount() || aMapping->BeingDetached()) |
|
1548 |
return KErrAbort; |
|
1549 |
||
1550 |
aPte = Mmu::SafePtePtrFromLinAddr(aAddress,aOsAsid); |
|
1551 |
if(!aPte) |
|
1552 |
return KErrNotFound; |
|
1553 |
||
1554 |
TPte pte = *aPte; |
|
1555 |
if(pte==KPteUnallocatedEntry) |
|
1556 |
return KErrNotFound; |
|
1557 |
||
1558 |
SPageInfo* pi = SPageInfo::SafeFromPhysAddr(pte & ~KPageMask); |
|
1559 |
if(!pi) |
|
1560 |
return KErrNotFound; |
|
1561 |
aPageInfo = pi; |
|
1562 |
||
1563 |
return KErrNone; |
|
1564 |
} |
|
1565 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1566 |
|
0 | 1567 |
TInt DPager::TryRejuvenate( TInt aOsAsid, TLinAddr aAddress, TUint aAccessPermissions, TLinAddr aPc, |
1568 |
DMemoryMappingBase* aMapping, TUint aMapInstanceCount, DThread* aThread, |
|
1569 |
TAny* aExceptionInfo) |
|
1570 |
{ |
|
1571 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1572 |
START_PAGING_BENCHMARK; |
0 | 1573 |
|
1574 |
SPageInfo* pi; |
|
1575 |
TPte* pPte; |
|
1576 |
TPte pte; |
|
1577 |
TInt r = PteAndInfoFromLinAddr(aOsAsid, aAddress, aMapping, aMapInstanceCount, pPte, pi); |
|
1578 |
if (r != KErrNone) |
|
1579 |
{ |
|
1580 |
if (aThread->IsRealtime()) |
|
1581 |
{// This thread is real time so it shouldn't be accessing paged out paged memory |
|
1582 |
// unless there is a paging trap. |
|
1583 |
MmuLock::Unlock(); |
|
1584 |
// Ensure that we abort when the thread is not allowed to access paged out pages. |
|
1585 |
if (CheckRealtimeThreadFault(aThread, aExceptionInfo) != KErrNone) |
|
1586 |
r = KErrAbort; |
|
1587 |
MmuLock::Lock(); |
|
1588 |
} |
|
1589 |
return r; |
|
1590 |
} |
|
1591 |
pte = *pPte; |
|
1592 |
SPageInfo::TType type = pi->Type(); |
|
1593 |
SPageInfo::TPagedState state = pi->PagedState(); |
|
1594 |
||
1595 |
if (aThread->IsRealtime() && |
|
1596 |
state != SPageInfo::EPagedPinned && |
|
1597 |
state != SPageInfo::EPagedPinnedMoved) |
|
1598 |
{// This thread is real time so it shouldn't be accessing unpinned paged memory |
|
1599 |
// unless there is a paging trap. |
|
1600 |
MmuLock::Unlock(); |
|
1601 |
r = CheckRealtimeThreadFault(aThread, aExceptionInfo); |
|
1602 |
MmuLock::Lock(); |
|
1603 |
if (r != KErrNone) |
|
1604 |
return r; |
|
1605 |
// We had to release the MmuLock have to reverify the status of the page and mappings. |
|
1606 |
r = PteAndInfoFromLinAddr(aOsAsid, aAddress, aMapping, aMapInstanceCount, pPte, pi); |
|
1607 |
if (r != KErrNone) |
|
1608 |
return r; |
|
1609 |
pte = *pPte; |
|
1610 |
type = pi->Type(); |
|
1611 |
state = pi->PagedState(); |
|
1612 |
} |
|
1613 |
||
1614 |
if (type != SPageInfo::EManaged) |
|
1615 |
return KErrNotFound; |
|
1616 |
||
1617 |
if(state==SPageInfo::EUnpaged) |
|
1618 |
return KErrNotFound; |
|
1619 |
||
1620 |
DMemoryObject* memory = pi->Owner(); |
|
1621 |
TUint index = pi->Index(); |
|
1622 |
||
1623 |
TPhysAddr page = memory->iPages.Page(index); |
|
1624 |
if(!RPageArray::IsPresent(page)) |
|
1625 |
return KErrNotFound; |
|
1626 |
||
1627 |
TPhysAddr physAddr = pi->PhysAddr(); |
|
1628 |
if ((page^physAddr) >= (TPhysAddr)KPageSize) |
|
1629 |
{// Page array entry should contain same physical address as PTE unless the |
|
1630 |
// page has or is being moved and this mapping accessed the page. |
|
1631 |
// Get the page info for the page that we should be using. |
|
1632 |
physAddr = page & ~KPageMask; |
|
1633 |
pi = SPageInfo::SafeFromPhysAddr(physAddr); |
|
1634 |
if(!pi) |
|
1635 |
return KErrNotFound; |
|
1636 |
||
1637 |
type = pi->Type(); |
|
1638 |
if (type!=SPageInfo::EManaged) |
|
1639 |
return KErrNotFound; |
|
1640 |
||
1641 |
state = pi->PagedState(); |
|
1642 |
if(state==SPageInfo::EUnpaged) |
|
1643 |
return KErrNotFound; |
|
1644 |
||
1645 |
memory = pi->Owner(); |
|
1646 |
index = pi->Index(); |
|
1647 |
||
1648 |
// Update pte to point to the correct physical address for this memory object's page. |
|
1649 |
pte = (pte & KPageMask) | physAddr; |
|
1650 |
} |
|
1651 |
||
1652 |
if(aAccessPermissions&EReadWrite) |
|
1653 |
{// The mapping that took the fault permits writes and is still attached |
|
1654 |
// to the memory object therefore the object can't be read only. |
|
1655 |
__NK_ASSERT_DEBUG(!memory->IsReadOnly()); |
|
1656 |
SetWritable(*pi); |
|
1657 |
} |
|
1658 |
||
1659 |
pte = Mmu::MakePteAccessible(pte,aAccessPermissions&EReadWrite); |
|
1660 |
TRACE2(("!PTE %x=%x",pPte,pte)); |
|
1661 |
*pPte = pte; |
|
1662 |
CacheMaintenance::SinglePteUpdated((TLinAddr)pPte); |
|
1663 |
InvalidateTLBForPage((aAddress&~KPageMask)|aOsAsid); |
|
1664 |
||
1665 |
Event(EEventPageRejuvenate,pi,aPc,aAddress,aAccessPermissions); |
|
1666 |
||
1667 |
TBool balance = false; |
|
1668 |
if( state==SPageInfo::EPagedYoung || state==SPageInfo::EPagedOld || |
|
1669 |
state==SPageInfo::EPagedOldestClean || state==SPageInfo::EPagedOldestDirty) |
|
1670 |
{ |
|
1671 |
RemovePage(pi); |
|
1672 |
AddAsYoungestPage(pi); |
|
1673 |
// delay BalanceAges because we don't want to release MmuLock until after |
|
1674 |
// RejuvenatePageTable has chance to look at the page table page... |
|
1675 |
balance = true; |
|
1676 |
} |
|
1677 |
else |
|
1678 |
{// Clear the modifier so that if this page is being moved then this |
|
1679 |
// access is detected. For non-pinned pages the modifier is cleared |
|
1680 |
// by RemovePage(). |
|
1681 |
__NK_ASSERT_DEBUG(state==SPageInfo::EPagedPinned); |
|
1682 |
pi->SetModifier(0); |
|
1683 |
} |
|
1684 |
||
1685 |
RejuvenatePageTable(pPte); |
|
1686 |
||
1687 |
if(balance) |
|
1688 |
BalanceAges(); |
|
1689 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
1690 |
END_PAGING_BENCHMARK(EPagingBmRejuvenate); |
0 | 1691 |
return KErrNone; |
1692 |
} |
|
1693 |
||
1694 |
||
1695 |
TInt DPager::PageInAllocPages(TPhysAddr* aPages, TUint aCount, Mmu::TRamAllocFlags aAllocFlags) |
|
1696 |
{ |
|
1697 |
TUint n = 0; |
|
1698 |
while(n<aCount) |
|
1699 |
{ |
|
1700 |
SPageInfo* pi = PageInAllocPage(aAllocFlags); |
|
1701 |
if(!pi) |
|
1702 |
goto fail; |
|
1703 |
aPages[n++] = pi->PhysAddr(); |
|
1704 |
} |
|
1705 |
return KErrNone; |
|
1706 |
fail: |
|
1707 |
PageInFreePages(aPages,n); |
|
1708 |
return KErrNoMemory; |
|
1709 |
} |
|
1710 |
||
1711 |
||
1712 |
void DPager::PageInFreePages(TPhysAddr* aPages, TUint aCount) |
|
1713 |
{ |
|
1714 |
while(aCount--) |
|
1715 |
{ |
|
1716 |
MmuLock::Lock(); |
|
1717 |
SPageInfo* pi = SPageInfo::FromPhysAddr(aPages[aCount]); |
|
1718 |
switch(pi->PagedState()) |
|
1719 |
{ |
|
1720 |
case SPageInfo::EPagedYoung: |
|
1721 |
case SPageInfo::EPagedOld: |
|
1722 |
case SPageInfo::EPagedOldestClean: |
|
1723 |
case SPageInfo::EPagedOldestDirty: |
|
1724 |
RemovePage(pi); |
|
1725 |
// fall through... |
|
1726 |
case SPageInfo::EUnpaged: |
|
1727 |
AddAsFreePage(pi); |
|
1728 |
break; |
|
1729 |
||
1730 |
case SPageInfo::EPagedPinned: |
|
1731 |
__NK_ASSERT_DEBUG(0); |
|
1732 |
break; |
|
1733 |
default: |
|
1734 |
__NK_ASSERT_DEBUG(0); |
|
1735 |
break; |
|
1736 |
} |
|
1737 |
MmuLock::Unlock(); |
|
1738 |
} |
|
1739 |
} |
|
1740 |
||
1741 |
||
1742 |
void DPager::PagedInUnneeded(SPageInfo* aPageInfo) |
|
1743 |
{ |
|
1744 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1745 |
Event(EEventPageInUnneeded,aPageInfo); |
|
1746 |
AddAsFreePage(aPageInfo); |
|
1747 |
} |
|
1748 |
||
1749 |
||
1750 |
void DPager::PagedIn(SPageInfo* aPageInfo) |
|
1751 |
{ |
|
1752 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1753 |
switch(aPageInfo->PagedState()) |
|
1754 |
{ |
|
1755 |
case SPageInfo::EPagedYoung: |
|
1756 |
case SPageInfo::EPagedOld: |
|
1757 |
case SPageInfo::EPagedOldestClean: |
|
1758 |
case SPageInfo::EPagedOldestDirty: |
|
1759 |
RemovePage(aPageInfo); |
|
1760 |
AddAsYoungestPage(aPageInfo); |
|
1761 |
BalanceAges(); |
|
1762 |
break; |
|
1763 |
||
1764 |
case SPageInfo::EUnpaged: |
|
1765 |
AddAsYoungestPage(aPageInfo); |
|
1766 |
BalanceAges(); |
|
1767 |
break; |
|
1768 |
||
1769 |
case SPageInfo::EPagedPinned: |
|
1770 |
// Clear the modifier so that if this page is being moved then this |
|
1771 |
// access is detected. For non-pinned pages the modifier is cleared by RemovePage(). |
|
1772 |
aPageInfo->SetModifier(0); |
|
1773 |
break; |
|
1774 |
||
1775 |
default: |
|
1776 |
__NK_ASSERT_DEBUG(0); |
|
1777 |
break; |
|
1778 |
} |
|
1779 |
} |
|
1780 |
||
1781 |
||
1782 |
void DPager::PagedInPinned(SPageInfo* aPageInfo, TPinArgs& aPinArgs) |
|
1783 |
{ |
|
1784 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1785 |
Pin(aPageInfo,aPinArgs); |
|
1786 |
} |
|
1787 |
||
1788 |
||
1789 |
void DPager::Pin(SPageInfo* aPageInfo, TPinArgs& aPinArgs) |
|
1790 |
{ |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1791 |
TRACE(("DPager::Pin %08x", aPageInfo->PhysAddr())); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
1792 |
|
0 | 1793 |
__ASSERT_CRITICAL; |
1794 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1795 |
__NK_ASSERT_DEBUG(aPinArgs.HaveSufficientPages(1)); |
|
1796 |
||
1797 |
aPageInfo->IncPinCount(); |
|
1798 |
Event(EEventPagePin,aPageInfo); |
|
1799 |
||
1800 |
// remove page from live list... |
|
1801 |
switch(aPageInfo->PagedState()) |
|
1802 |
{ |
|
1803 |
case SPageInfo::EPagedYoung: |
|
1804 |
__NK_ASSERT_DEBUG(iYoungCount); |
|
1805 |
aPageInfo->iLink.Deque(); |
|
1806 |
--iYoungCount; |
|
1807 |
__NK_ASSERT_DEBUG(aPageInfo->PinCount()==1); |
|
1808 |
break; |
|
1809 |
||
1810 |
case SPageInfo::EPagedOld: |
|
1811 |
__NK_ASSERT_DEBUG(iOldCount); |
|
1812 |
aPageInfo->iLink.Deque(); |
|
1813 |
--iOldCount; |
|
1814 |
__NK_ASSERT_DEBUG(aPageInfo->PinCount()==1); |
|
1815 |
break; |
|
1816 |
||
1817 |
case SPageInfo::EPagedOldestClean: |
|
1818 |
__NK_ASSERT_DEBUG(iOldestCleanCount); |
|
1819 |
aPageInfo->iLink.Deque(); |
|
1820 |
--iOldestCleanCount; |
|
1821 |
__NK_ASSERT_DEBUG(aPageInfo->PinCount()==1); |
|
1822 |
break; |
|
1823 |
||
1824 |
case SPageInfo::EPagedOldestDirty: |
|
1825 |
__NK_ASSERT_DEBUG(iOldestDirtyCount); |
|
1826 |
aPageInfo->iLink.Deque(); |
|
1827 |
--iOldestDirtyCount; |
|
1828 |
__NK_ASSERT_DEBUG(aPageInfo->PinCount()==1); |
|
1829 |
break; |
|
1830 |
||
1831 |
case SPageInfo::EPagedPinned: |
|
1832 |
// nothing more to do... |
|
1833 |
__NK_ASSERT_DEBUG(aPageInfo->PinCount()>1); |
|
1834 |
return; |
|
1835 |
||
1836 |
case SPageInfo::EUnpaged: |
|
1837 |
__NK_ASSERT_DEBUG(aPageInfo->PinCount()==1); |
|
1838 |
TRACE2(("DPager::PinPage page was unpaged")); |
|
1839 |
// This could be a page in the process of being stolen. |
|
1840 |
// Could also be page for storing page table infos, which aren't necessarily |
|
1841 |
// on the live list. |
|
1842 |
break; |
|
1843 |
||
1844 |
default: |
|
1845 |
__NK_ASSERT_DEBUG(0); |
|
1846 |
return; |
|
1847 |
} |
|
1848 |
||
1849 |
// page has now been removed from the live list and is pinned... |
|
1850 |
aPageInfo->SetPagedState(SPageInfo::EPagedPinned); |
|
1851 |
||
1852 |
if(aPinArgs.iReplacementPages==TPinArgs::EUseReserveForPinReplacementPages) |
|
1853 |
{ |
|
1854 |
// pinned paged counts as coming from reserve pool... |
|
1855 |
aPageInfo->SetPinnedReserve(); |
|
1856 |
} |
|
1857 |
else |
|
1858 |
{ |
|
1859 |
// we used up a replacement page... |
|
1860 |
--aPinArgs.iReplacementPages; |
|
1861 |
} |
|
1862 |
||
1863 |
BalanceAges(); |
|
1864 |
} |
|
1865 |
||
1866 |
||
1867 |
void DPager::Unpin(SPageInfo* aPageInfo, TPinArgs& aPinArgs) |
|
1868 |
{ |
|
1869 |
__ASSERT_CRITICAL; |
|
1870 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1871 |
__NK_ASSERT_DEBUG(aPageInfo->PagedState()==SPageInfo::EPagedPinned); |
|
1872 |
__NK_ASSERT_DEBUG(aPageInfo->PinCount()>0); |
|
1873 |
||
1874 |
TUint pinCount = aPageInfo->DecPinCount(); |
|
1875 |
Event(EEventPageUnpin,aPageInfo); |
|
1876 |
||
1877 |
if(pinCount) |
|
1878 |
return; |
|
1879 |
||
1880 |
aPageInfo->SetPagedState(SPageInfo::EUnpaged); |
|
1881 |
||
1882 |
if(!aPageInfo->ClearPinnedReserve()) |
|
1883 |
{ |
|
1884 |
// was not a pinned reserve page, so we how have a spare replacement page, |
|
1885 |
// which can be used again or freed later ... |
|
1886 |
__NK_ASSERT_DEBUG(aPinArgs.iReplacementPages!=TPinArgs::EUseReserveForPinReplacementPages); |
|
1887 |
++aPinArgs.iReplacementPages; |
|
1888 |
} |
|
1889 |
||
1890 |
AddAsYoungestPage(aPageInfo); |
|
1891 |
BalanceAges(); |
|
1892 |
} |
|
1893 |
||
1894 |
||
1895 |
TInt TPinArgs::AllocReplacementPages(TUint aNumPages) |
|
1896 |
{ |
|
1897 |
if(iUseReserve) |
|
1898 |
{ |
|
1899 |
__NK_ASSERT_DEBUG(iReplacementPages==0 || iReplacementPages==EUseReserveForPinReplacementPages); |
|
1900 |
iReplacementPages = EUseReserveForPinReplacementPages; |
|
1901 |
} |
|
1902 |
else |
|
1903 |
{ |
|
1904 |
if(aNumPages>iReplacementPages) |
|
1905 |
{ |
|
1906 |
if(!ThePager.AllocPinReplacementPages(aNumPages-iReplacementPages)) |
|
1907 |
return KErrNoMemory; |
|
1908 |
iReplacementPages = aNumPages; |
|
1909 |
} |
|
1910 |
} |
|
1911 |
return KErrNone; |
|
1912 |
} |
|
1913 |
||
1914 |
||
1915 |
void TPinArgs::FreeReplacementPages() |
|
1916 |
{ |
|
1917 |
if(iReplacementPages!=0 && iReplacementPages!=EUseReserveForPinReplacementPages) |
|
1918 |
ThePager.FreePinReplacementPages(iReplacementPages); |
|
1919 |
iReplacementPages = 0; |
|
1920 |
} |
|
1921 |
||
1922 |
||
1923 |
TBool DPager::AllocPinReplacementPages(TUint aNumPages) |
|
1924 |
{ |
|
1925 |
TRACE2(("DPager::AllocPinReplacementPages(0x%x)",aNumPages)); |
|
1926 |
__ASSERT_CRITICAL; |
|
1927 |
RamAllocLock::Lock(); |
|
1928 |
MmuLock::Lock(); |
|
1929 |
||
1930 |
TBool ok = false; |
|
1931 |
do |
|
1932 |
{ |
|
1933 |
if(iNumberOfFreePages>=aNumPages) |
|
1934 |
{ |
|
1935 |
iNumberOfFreePages -= aNumPages; |
|
1936 |
ok = true; |
|
1937 |
break; |
|
1938 |
} |
|
1939 |
} |
|
1940 |
while(TryGrowLiveList()); |
|
1941 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1942 |
if (!ok) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1943 |
{// Failed to allocate enough pages so free any excess.. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1944 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1945 |
// If there are too many pages they should all be unused free pages otherwise |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1946 |
// the ram alloc lock may be released by RemoveExcessPages(). |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1947 |
__NK_ASSERT_DEBUG( !HaveTooManyPages() || |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1948 |
(iMinimumPageCount + iNumberOfFreePages - iMaximumPageCount |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1949 |
<= iOldestCleanCount)); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1950 |
RemoveExcessPages(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1951 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1952 |
__NK_ASSERT_DEBUG((iMinimumPageCount + iNumberOfFreePages) <= iMaximumPageCount); |
0 | 1953 |
MmuLock::Unlock(); |
1954 |
RamAllocLock::Unlock(); |
|
1955 |
return ok; |
|
1956 |
} |
|
1957 |
||
1958 |
||
1959 |
void DPager::FreePinReplacementPages(TUint aNumPages) |
|
1960 |
{ |
|
1961 |
TRACE2(("DPager::FreePinReplacementPage(0x%x)",aNumPages)); |
|
1962 |
__ASSERT_CRITICAL; |
|
1963 |
||
1964 |
RamAllocLock::Lock(); |
|
1965 |
MmuLock::Lock(); |
|
1966 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1967 |
while (aNumPages) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1968 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1969 |
SPageInfo* pageInfo; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1970 |
// This may release the ram alloc lock but it will flash the mmulock |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1971 |
// if not all pages could be added in one go, i.e. freePages != aNumPages. |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1972 |
TUint freePages = AllowAddFreePages(pageInfo, aNumPages); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1973 |
iNumberOfFreePages += freePages; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1974 |
aNumPages -= freePages; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1975 |
if (pageInfo) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1976 |
ReturnPageToSystem(*pageInfo); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1977 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1978 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1979 |
__NK_ASSERT_DEBUG((iMinimumPageCount + iNumberOfFreePages) <= iMaximumPageCount); |
0 | 1980 |
MmuLock::Unlock(); |
1981 |
RamAllocLock::Unlock(); |
|
1982 |
} |
|
1983 |
||
1984 |
||
1985 |
TBool DPager::ReservePage() |
|
1986 |
{ |
|
1987 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1988 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1989 |
__ASSERT_CRITICAL; |
|
1990 |
__NK_ASSERT_DEBUG(iMinimumPageCount >= iMinimumPageLimit+iReservePageCount); |
|
1991 |
while(iMinimumPageCount==iMinimumPageLimit+iReservePageCount && iNumberOfFreePages==0) |
|
1992 |
{ |
|
1993 |
if(!TryGrowLiveList()) |
|
1994 |
return false; |
|
1995 |
} |
|
1996 |
if(iMinimumPageCount==iMinimumPageLimit+iReservePageCount) |
|
1997 |
{ |
|
1998 |
++iMinimumPageCount; |
|
1999 |
--iNumberOfFreePages; |
|
2000 |
if(iMinimumPageCount>iMaximumPageCount) |
|
2001 |
iMaximumPageCount = iMinimumPageCount; |
|
2002 |
} |
|
2003 |
++iReservePageCount; |
|
2004 |
__NK_ASSERT_DEBUG(iMinimumPageCount >= iMinimumPageLimit+iReservePageCount); |
|
2005 |
__NK_ASSERT_DEBUG(iMinimumPageCount+iNumberOfFreePages <= iMaximumPageCount); |
|
2006 |
return ETrue; |
|
2007 |
} |
|
2008 |
||
2009 |
||
2010 |
TBool DPager::ReservePages(TUint aRequiredCount, TUint& aCount) |
|
2011 |
{ |
|
2012 |
__ASSERT_CRITICAL; |
|
2013 |
||
2014 |
RamAllocLock::Lock(); |
|
2015 |
MmuLock::Lock(); |
|
2016 |
while(aCount<aRequiredCount) |
|
2017 |
{ |
|
2018 |
if(!ReservePage()) |
|
2019 |
break; |
|
2020 |
++aCount; |
|
2021 |
MmuLock::Flash(); |
|
2022 |
} |
|
2023 |
TBool enoughPages = aCount==aRequiredCount; |
|
2024 |
MmuLock::Unlock(); |
|
2025 |
RamAllocLock::Unlock(); |
|
2026 |
||
2027 |
if(!enoughPages) |
|
2028 |
UnreservePages(aCount); |
|
2029 |
||
2030 |
return enoughPages; |
|
2031 |
} |
|
2032 |
||
2033 |
||
2034 |
void DPager::UnreservePages(TUint& aCount) |
|
2035 |
{ |
|
2036 |
MmuLock::Lock(); |
|
2037 |
iReservePageCount -= aCount; |
|
2038 |
aCount = 0; |
|
2039 |
MmuLock::Unlock(); |
|
2040 |
} |
|
2041 |
||
2042 |
||
44 | 2043 |
TInt DPager::CheckRealtimeThreadFault(DThread* aThread, TAny* aExceptionInfo) |
0 | 2044 |
{ |
44 | 2045 |
// realtime threads shouldn't take paging faults... |
0 | 2046 |
DThread* client = aThread->iIpcClient; |
2047 |
||
2048 |
// If iIpcClient is set then we are accessing the address space of a remote thread. If we are |
|
2049 |
// in an IPC trap, this will contain information the local and remote addresses being accessed. |
|
2050 |
// If this is not set then we assume than any fault must be the fault of a bad remote address. |
|
2051 |
TIpcExcTrap* ipcTrap = (TIpcExcTrap*)aThread->iExcTrap; |
|
2052 |
if (ipcTrap && !ipcTrap->IsTIpcExcTrap()) |
|
2053 |
ipcTrap = 0; |
|
44 | 2054 |
if (client && (!ipcTrap || ipcTrap->ExcLocation(aThread, aExceptionInfo) == TIpcExcTrap::EExcRemote)) |
0 | 2055 |
{ |
44 | 2056 |
// kill client thread... |
2057 |
if(K::IllegalFunctionForRealtimeThread(client,"Access to Paged Memory (by other thread)")) |
|
2058 |
{ |
|
2059 |
// treat memory access as bad... |
|
2060 |
return KErrAbort; |
|
2061 |
} |
|
2062 |
// else thread is in 'warning only' state so allow paging... |
|
0 | 2063 |
} |
2064 |
else |
|
2065 |
{ |
|
44 | 2066 |
// kill current thread... |
2067 |
if(K::IllegalFunctionForRealtimeThread(NULL,"Access to Paged Memory")) |
|
2068 |
{ |
|
2069 |
// if current thread is in critical section, then the above kill will be deferred |
|
2070 |
// and we will continue executing. We will handle this by returning an error |
|
2071 |
// which means that the thread will take an exception (which hopefully is XTRAPed!) |
|
2072 |
return KErrAbort; |
|
2073 |
} |
|
2074 |
// else thread is in 'warning only' state so allow paging... |
|
0 | 2075 |
} |
44 | 2076 |
return KErrNone; |
0 | 2077 |
} |
2078 |
||
2079 |
||
2080 |
TInt DPager::HandlePageFault( TLinAddr aPc, TLinAddr aFaultAddress, TUint aFaultAsid, TUint aFaultIndex, |
|
2081 |
TUint aAccessPermissions, DMemoryObject* aMemory, DMemoryMapping* aMapping, |
|
2082 |
TUint aMapInstanceCount, DThread* aThread, TAny* aExceptionInfo) |
|
2083 |
{ |
|
2084 |
MmuLock::Lock(); |
|
2085 |
TInt r = TryRejuvenate( aFaultAsid, aFaultAddress, aAccessPermissions, aPc, aMapping, aMapInstanceCount, |
|
2086 |
aThread, aExceptionInfo); |
|
2087 |
if(r == KErrNone || r == KErrAbort) |
|
2088 |
{ |
|
2089 |
MmuLock::Unlock(); |
|
2090 |
} |
|
2091 |
else |
|
2092 |
{ |
|
2093 |
// rejuvenate failed, call memory manager to page in memory... |
|
2094 |
Event(EEventPageInStart, 0, aPc, aFaultAddress, aAccessPermissions); |
|
2095 |
MmuLock::Unlock(); |
|
2096 |
TheThrashMonitor.NotifyStartPaging(); |
|
2097 |
||
2098 |
DMemoryManager* manager = aMemory->iManager; |
|
2099 |
r = manager->HandleFault(aMemory, aFaultIndex, aMapping, aMapInstanceCount, aAccessPermissions); |
|
2100 |
||
2101 |
TheThrashMonitor.NotifyEndPaging(); |
|
2102 |
} |
|
2103 |
return r; |
|
2104 |
} |
|
2105 |
||
2106 |
||
2107 |
TInt DPager::ResizeLiveList() |
|
2108 |
{ |
|
2109 |
MmuLock::Lock(); |
|
2110 |
TUint min = iMinimumPageCount; |
|
2111 |
TUint max = iMaximumPageCount; |
|
2112 |
MmuLock::Unlock(); |
|
2113 |
return ResizeLiveList(min,max); |
|
2114 |
} |
|
2115 |
||
2116 |
||
2117 |
TInt DPager::ResizeLiveList(TUint aMinimumPageCount, TUint aMaximumPageCount) |
|
2118 |
{ |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2119 |
TRACE(("DPager::ResizeLiveList(%d,%d) current: %d %d %d %d, %d %d %d", |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2120 |
aMinimumPageCount,aMaximumPageCount, |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2121 |
iYoungCount,iOldCount,iOldestCleanCount,iOldestDirtyCount, |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2122 |
iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount)); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2123 |
__NK_ASSERT_DEBUG(CacheInitialised()); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2124 |
|
0 | 2125 |
if(!aMaximumPageCount) |
2126 |
{ |
|
2127 |
aMinimumPageCount = iInitMinimumPageCount; |
|
2128 |
aMaximumPageCount = iInitMaximumPageCount; |
|
2129 |
} |
|
2130 |
if (aMaximumPageCount > KAbsoluteMaxPageCount) |
|
2131 |
aMaximumPageCount = KAbsoluteMaxPageCount; |
|
2132 |
||
2133 |
// Min must not be greater than max... |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
2134 |
if(aMinimumPageCount > aMaximumPageCount) |
0 | 2135 |
return KErrArgument; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2136 |
|
0 | 2137 |
NKern::ThreadEnterCS(); |
2138 |
RamAllocLock::Lock(); |
|
2139 |
||
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
2140 |
// We must hold this otherwise StealOrAllocPage will release the RamAllocLock while waiting for |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
2141 |
// it. Note this method is not used in producton, so it's ok to hold both locks for longer than |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
2142 |
// would otherwise happen. |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2143 |
PageCleaningLock::Lock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2144 |
|
0 | 2145 |
MmuLock::Lock(); |
2146 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2147 |
__NK_ASSERT_ALWAYS(iYoungOldRatio); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2148 |
|
0 | 2149 |
// Make sure aMinimumPageCount is not less than absolute minimum we can cope with... |
2150 |
iMinimumPageLimit = iMinYoungPages * (1 + iYoungOldRatio) / iYoungOldRatio |
|
2151 |
+ DPageReadRequest::ReservedPagesRequired(); |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
2152 |
if(iMinimumPageLimit < iAbsoluteMinPageCount) |
0 | 2153 |
iMinimumPageLimit = iAbsoluteMinPageCount; |
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
2154 |
if(aMinimumPageCount < iMinimumPageLimit + iReservePageCount) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
2155 |
aMinimumPageCount = iMinimumPageLimit + iReservePageCount; |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
2156 |
if(aMaximumPageCount < aMinimumPageCount) |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
2157 |
aMaximumPageCount = aMinimumPageCount; |
0 | 2158 |
|
2159 |
// Increase iMaximumPageCount? |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2160 |
if(aMaximumPageCount > iMaximumPageCount) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2161 |
iMaximumPageCount = aMaximumPageCount; |
0 | 2162 |
|
2163 |
// Reduce iMinimumPageCount? |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2164 |
if(aMinimumPageCount < iMinimumPageCount) |
0 | 2165 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2166 |
iNumberOfFreePages += iMinimumPageCount - aMinimumPageCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2167 |
iMinimumPageCount = aMinimumPageCount; |
0 | 2168 |
} |
2169 |
||
2170 |
// Increase iMinimumPageCount? |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
2171 |
TInt r = KErrNone; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2172 |
while(aMinimumPageCount > iMinimumPageCount) |
0 | 2173 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2174 |
TUint newMin = MinU(aMinimumPageCount, iMinimumPageCount + iNumberOfFreePages); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2175 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2176 |
if (newMin == iMinimumPageCount) |
0 | 2177 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2178 |
// have to add pages before we can increase minimum page count |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2179 |
if(!TryGrowLiveList()) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2180 |
{ |
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
2181 |
r = KErrNoMemory; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2182 |
break; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2183 |
} |
0 | 2184 |
} |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2185 |
else |
0 | 2186 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2187 |
iNumberOfFreePages -= newMin - iMinimumPageCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2188 |
iMinimumPageCount = newMin; |
0 | 2189 |
} |
2190 |
} |
|
2191 |
||
2192 |
// Reduce iMaximumPageCount? |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2193 |
while(aMaximumPageCount < iMaximumPageCount) |
0 | 2194 |
{ |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2195 |
TUint newMax = MaxU(aMaximumPageCount, iMinimumPageCount + iNumberOfFreePages); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2196 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2197 |
if (newMax == iMaximumPageCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2198 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2199 |
// have to remove pages before we can reduce maximum page count |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2200 |
TryReturnOldestPageToSystem(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2201 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2202 |
else |
0 | 2203 |
{ |
2204 |
iMaximumPageCount = newMax; |
|
2205 |
} |
|
2206 |
} |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2207 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2208 |
TRACE(("DPager::ResizeLiveList end: %d %d %d %d, %d %d %d", |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2209 |
iYoungCount,iOldCount,iOldestCleanCount,iOldestDirtyCount, |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2210 |
iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2211 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2212 |
__NK_ASSERT_DEBUG((iMinimumPageCount + iNumberOfFreePages) <= iMaximumPageCount); |
0 | 2213 |
|
2214 |
#ifdef BTRACE_KERNEL_MEMORY |
|
2215 |
BTrace4(BTrace::EKernelMemory,BTrace::EKernelMemoryDemandPagingCache,iMinimumPageCount << KPageShift); |
|
2216 |
#endif |
|
2217 |
||
2218 |
MmuLock::Unlock(); |
|
2219 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2220 |
PageCleaningLock::Unlock(); |
0 | 2221 |
RamAllocLock::Unlock(); |
2222 |
NKern::ThreadLeaveCS(); |
|
2223 |
||
2224 |
return r; |
|
2225 |
} |
|
2226 |
||
2227 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2228 |
TUint RequiredOldestPages(TUint aPagesToClean, TBool aCleanInSequence) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2229 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2230 |
return aCleanInSequence ? aPagesToClean * 8 : aPagesToClean; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2231 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2232 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2233 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2234 |
void DPager::SetPagesToClean(TUint aPagesToClean) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2235 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2236 |
TRACE(("WDP: Pager will attempt to clean %d pages", aPagesToClean)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2237 |
__NK_ASSERT_ALWAYS(aPagesToClean > 0 && aPagesToClean <= KMaxPagesToClean); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2238 |
MmuLock::Lock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2239 |
iPagesToClean = aPagesToClean; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2240 |
iMaxOldestPages = MaxU(KDefaultMaxOldestPages, |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2241 |
RequiredOldestPages(iPagesToClean, iCleanInSequence)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2242 |
MmuLock::Unlock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2243 |
TRACE(("WDP: Maximum %d oldest pages", iMaxOldestPages)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2244 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2245 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2246 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2247 |
TUint DPager::PagesToClean() |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2248 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2249 |
return iPagesToClean; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2250 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2251 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2252 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2253 |
void DPager::SetCleanInSequence(TBool aCleanInSequence) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2254 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2255 |
TRACE(("WDP: Sequential page colour set to %d", aCleanInSequence)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2256 |
MmuLock::Lock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2257 |
iCleanInSequence = aCleanInSequence; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2258 |
iMaxOldestPages = MaxU(KDefaultMaxOldestPages, |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2259 |
RequiredOldestPages(iPagesToClean, iCleanInSequence)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2260 |
MmuLock::Unlock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2261 |
TRACE(("WDP: Maximum %d oldest pages", iMaxOldestPages)); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2262 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2263 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2264 |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2265 |
// WARNING THIS METHOD MAY HOLD THE RAM ALLOC LOCK FOR EXCESSIVE PERIODS. DON'T USE THIS IN ANY PRODUCTION CODE. |
0 | 2266 |
void DPager::FlushAll() |
2267 |
{ |
|
2268 |
NKern::ThreadEnterCS(); |
|
2269 |
RamAllocLock::Lock(); |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2270 |
PageCleaningLock::Lock(); |
0 | 2271 |
|
2272 |
TRACE(("DPager::FlushAll() live list young=%d old=%d min=%d free=%d max=%d",iYoungCount,iOldCount,iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount)); |
|
2273 |
||
2274 |
// look at all RAM pages in the system, and unmap all those used for paging |
|
2275 |
const TUint32* piMap = (TUint32*)KPageInfoMap; |
|
2276 |
const TUint32* piMapEnd = piMap+(KNumPageInfoPages>>5); |
|
2277 |
SPageInfo* pi = (SPageInfo*)KPageInfoLinearBase; |
|
2278 |
MmuLock::Lock(); |
|
2279 |
do |
|
2280 |
{ |
|
2281 |
SPageInfo* piNext = pi+(KPageInfosPerPage<<5); |
|
2282 |
for(TUint32 piFlags=*piMap++; piFlags; piFlags>>=1) |
|
2283 |
{ |
|
2284 |
if(!(piFlags&1)) |
|
2285 |
{ |
|
2286 |
pi += KPageInfosPerPage; |
|
2287 |
continue; |
|
2288 |
} |
|
2289 |
SPageInfo* piEnd = pi+KPageInfosPerPage; |
|
2290 |
do |
|
2291 |
{ |
|
2292 |
SPageInfo::TPagedState state = pi->PagedState(); |
|
2293 |
if (state==SPageInfo::EPagedYoung || state==SPageInfo::EPagedOld || |
|
2294 |
state==SPageInfo::EPagedOldestClean || state==SPageInfo::EPagedOldestDirty) |
|
2295 |
{ |
|
2296 |
if (pi->Type() != SPageInfo::EUnused) |
|
2297 |
{ |
|
2298 |
TInt r = StealPage(pi); |
|
2299 |
if(r==KErrNone) |
|
2300 |
AddAsFreePage(pi); |
|
2301 |
MmuLock::Flash(); |
|
2302 |
} |
|
2303 |
} |
|
2304 |
++pi; |
|
2305 |
if(((TUint)pi&(0xf<<KPageInfoShift))==0) |
|
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2306 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2307 |
MmuLock::Flash(); // every 16 page infos |
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2308 |
} |
0 | 2309 |
} |
2310 |
while(pi<piEnd); |
|
2311 |
} |
|
2312 |
pi = piNext; |
|
2313 |
} |
|
2314 |
while(piMap<piMapEnd); |
|
2315 |
MmuLock::Unlock(); |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2316 |
PageCleaningLock::Unlock(); |
0 | 2317 |
|
2318 |
// reduce live page list to a minimum |
|
2319 |
while(GetFreePages(1)) {}; |
|
2320 |
||
2321 |
TRACE(("DPager::FlushAll() end with young=%d old=%d min=%d free=%d max=%d",iYoungCount,iOldCount,iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount)); |
|
2322 |
||
2323 |
RamAllocLock::Unlock(); |
|
2324 |
NKern::ThreadLeaveCS(); |
|
2325 |
} |
|
2326 |
||
2327 |
||
2328 |
void DPager::GetLiveListInfo(SVMCacheInfo& aInfo) |
|
2329 |
{ |
|
2330 |
MmuLock::Lock(); // ensure consistent set of values are read... |
|
2331 |
aInfo.iMinSize = iMinimumPageCount<<KPageShift; |
|
2332 |
aInfo.iMaxSize = iMaximumPageCount<<KPageShift; |
|
2333 |
aInfo.iCurrentSize = (iMinimumPageCount+iNumberOfFreePages)<<KPageShift; |
|
2334 |
aInfo.iMaxFreeSize = iNumberOfFreePages<<KPageShift; |
|
2335 |
MmuLock::Unlock(); |
|
2336 |
} |
|
2337 |
||
2338 |
||
2339 |
void DPager::GetEventInfo(SVMEventInfo& aInfoOut) |
|
2340 |
{ |
|
2341 |
MmuLock::Lock(); // ensure consistent set of values are read... |
|
2342 |
aInfoOut = iEventInfo; |
|
2343 |
MmuLock::Unlock(); |
|
2344 |
} |
|
2345 |
||
2346 |
||
2347 |
void DPager::ResetEventInfo() |
|
2348 |
{ |
|
2349 |
MmuLock::Lock(); |
|
2350 |
memclr(&iEventInfo, sizeof(iEventInfo)); |
|
2351 |
MmuLock::Unlock(); |
|
2352 |
} |
|
2353 |
||
2354 |
||
2355 |
TInt TestPageState(TLinAddr aAddr) |
|
2356 |
{ |
|
2357 |
DMemModelProcess* process = (DMemModelProcess*)TheCurrentThread->iOwningProcess; |
|
2358 |
// Get the os asid of current thread's process so no need to open a reference on it. |
|
2359 |
TInt osAsid = process->OsAsid(); |
|
2360 |
TPte* ptePtr = 0; |
|
2361 |
TPte pte = 0; |
|
2362 |
TInt r = 0; |
|
2363 |
SPageInfo* pageInfo = NULL; |
|
2364 |
||
2365 |
NKern::ThreadEnterCS(); |
|
2366 |
||
2367 |
TUint offsetInMapping; |
|
2368 |
TUint mapInstanceCount; |
|
2369 |
DMemoryMapping* mapping = MM::FindMappingInAddressSpace(osAsid, aAddr, 1, offsetInMapping, mapInstanceCount); |
|
2370 |
||
2371 |
MmuLock::Lock(); |
|
2372 |
||
2373 |
if(mapping) |
|
2374 |
{ |
|
2375 |
DMemoryObject* memory = mapping->Memory(); |
|
2376 |
if(mapInstanceCount == mapping->MapInstanceCount() && memory) |
|
2377 |
{ |
|
2378 |
DMemoryManager* manager = memory->iManager; |
|
2379 |
if(manager==TheCodePagedMemoryManager) |
|
2380 |
r |= EPageStateInRamCode|EPageStatePaged; |
|
2381 |
} |
|
2382 |
} |
|
2383 |
||
2384 |
ptePtr = Mmu::SafePtePtrFromLinAddr(aAddr,osAsid); |
|
2385 |
if (!ptePtr) |
|
2386 |
goto done; |
|
2387 |
pte = *ptePtr; |
|
2388 |
if (pte == KPteUnallocatedEntry) |
|
2389 |
goto done; |
|
2390 |
r |= EPageStatePtePresent; |
|
2391 |
if (pte!=Mmu::MakePteInaccessible(pte,0)) |
|
2392 |
r |= EPageStatePteValid; |
|
2393 |
||
2394 |
pageInfo = SPageInfo::SafeFromPhysAddr(pte&~KPageMask); |
|
2395 |
if(pageInfo) |
|
2396 |
{ |
|
2397 |
r |= pageInfo->Type(); |
|
2398 |
r |= pageInfo->PagedState()<<8; |
|
2399 |
} |
|
2400 |
done: |
|
2401 |
MmuLock::Unlock(); |
|
2402 |
if(mapping) |
|
2403 |
mapping->Close(); |
|
2404 |
NKern::ThreadLeaveCS(); |
|
2405 |
return r; |
|
2406 |
} |
|
2407 |
||
2408 |
||
2409 |
||
2410 |
TInt VMHalFunction(TAny*, TInt aFunction, TAny* a1, TAny* a2) |
|
2411 |
{ |
|
2412 |
switch(aFunction) |
|
2413 |
{ |
|
2414 |
case EVMHalFlushCache: |
|
2415 |
if(!TheCurrentThread->HasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by VMHalFunction(EVMHalFlushCache)"))) |
|
2416 |
K::UnlockedPlatformSecurityPanic(); |
|
2417 |
ThePager.FlushAll(); |
|
2418 |
return KErrNone; |
|
2419 |
||
2420 |
case EVMHalSetCacheSize: |
|
2421 |
{ |
|
2422 |
if(!TheCurrentThread->HasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by VMHalFunction(EVMHalSetCacheSize)"))) |
|
2423 |
K::UnlockedPlatformSecurityPanic(); |
|
2424 |
TUint min = TUint(a1)>>KPageShift; |
|
2425 |
if(TUint(a1)&KPageMask) |
|
2426 |
++min; |
|
2427 |
TUint max = TUint(a2)>>KPageShift; |
|
2428 |
if(TUint(a2)&KPageMask) |
|
2429 |
++max; |
|
2430 |
return ThePager.ResizeLiveList(min,max); |
|
2431 |
} |
|
2432 |
||
2433 |
case EVMHalGetCacheSize: |
|
2434 |
{ |
|
2435 |
SVMCacheInfo info; |
|
2436 |
ThePager.GetLiveListInfo(info); |
|
2437 |
kumemput32(a1,&info,sizeof(info)); |
|
2438 |
} |
|
2439 |
return KErrNone; |
|
2440 |
||
2441 |
case EVMHalGetEventInfo: |
|
2442 |
{ |
|
2443 |
SVMEventInfo info; |
|
2444 |
ThePager.GetEventInfo(info); |
|
2445 |
Kern::InfoCopy(*(TDes8*)a1,(TUint8*)&info,sizeof(info)); |
|
2446 |
} |
|
2447 |
return KErrNone; |
|
2448 |
||
2449 |
case EVMHalResetEventInfo: |
|
2450 |
ThePager.ResetEventInfo(); |
|
2451 |
return KErrNone; |
|
2452 |
||
2453 |
#ifdef __SUPPORT_DEMAND_PAGING_EMULATION__ |
|
2454 |
case EVMHalGetOriginalRomPages: |
|
2455 |
RomOriginalPages(*((TPhysAddr**)a1), *((TUint*)a2)); |
|
2456 |
return KErrNone; |
|
2457 |
#endif |
|
2458 |
||
2459 |
case EVMPageState: |
|
2460 |
return TestPageState((TLinAddr)a1); |
|
2461 |
||
2462 |
case EVMHalGetSwapInfo: |
|
2463 |
{ |
|
2464 |
if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0) |
|
2465 |
return KErrNotSupported; |
|
2466 |
SVMSwapInfo info; |
|
2467 |
GetSwapInfo(info); |
|
2468 |
kumemput32(a1,&info,sizeof(info)); |
|
2469 |
} |
|
2470 |
return KErrNone; |
|
2471 |
||
2472 |
case EVMHalGetThrashLevel: |
|
2473 |
return TheThrashMonitor.ThrashLevel(); |
|
2474 |
||
2475 |
case EVMHalSetSwapThresholds: |
|
2476 |
{ |
|
2477 |
if(!TheCurrentThread->HasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by VMHalFunction(EVMHalSetSwapThresholds)"))) |
|
2478 |
K::UnlockedPlatformSecurityPanic(); |
|
2479 |
if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0) |
|
2480 |
return KErrNotSupported; |
|
2481 |
SVMSwapThresholds thresholds; |
|
2482 |
kumemget32(&thresholds,a1,sizeof(thresholds)); |
|
2483 |
return SetSwapThresholds(thresholds); |
|
2484 |
} |
|
2485 |
||
2486 |
case EVMHalSetThrashThresholds: |
|
2487 |
if(!TheCurrentThread->HasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by VMHalFunction(EVMHalSetThrashThresholds)"))) |
|
2488 |
K::UnlockedPlatformSecurityPanic(); |
|
2489 |
return TheThrashMonitor.SetThresholds((TUint)a1, (TUint)a2); |
|
2490 |
||
2491 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
2492 |
case EVMHalGetPagingBenchmark: |
|
2493 |
{ |
|
2494 |
TUint index = (TInt) a1; |
|
2495 |
if (index >= EMaxPagingBm) |
|
2496 |
return KErrNotFound; |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2497 |
SPagingBenchmarkInfo info; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2498 |
ThePager.ReadBenchmarkData((TPagingBenchmark)index, info); |
0 | 2499 |
kumemput32(a2,&info,sizeof(info)); |
2500 |
} |
|
2501 |
return KErrNone; |
|
2502 |
||
2503 |
case EVMHalResetPagingBenchmark: |
|
2504 |
{ |
|
2505 |
TUint index = (TInt) a1; |
|
2506 |
if (index >= EMaxPagingBm) |
|
2507 |
return KErrNotFound; |
|
2508 |
ThePager.ResetBenchmarkData((TPagingBenchmark)index); |
|
2509 |
} |
|
2510 |
return KErrNone; |
|
2511 |
#endif |
|
2512 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2513 |
case EVMHalGetPhysicalAccessSupported: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2514 |
if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2515 |
return KErrNotSupported; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2516 |
return GetPhysicalAccessSupported(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2517 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2518 |
case EVMHalGetUsePhysicalAccess: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2519 |
if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2520 |
return KErrNotSupported; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2521 |
return GetUsePhysicalAccess(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2522 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2523 |
case EVMHalSetUsePhysicalAccess: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2524 |
if(!TheCurrentThread->HasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by VMHalFunction(EVMHalSetUsePhysicalAccess)"))) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2525 |
K::UnlockedPlatformSecurityPanic(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2526 |
if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2527 |
return KErrNotSupported; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2528 |
if ((TUint)a1 > 1) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2529 |
return KErrArgument; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2530 |
SetUsePhysicalAccess((TBool)a1); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2531 |
return KErrNone; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2532 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2533 |
case EVMHalGetPreferredDataWriteSize: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2534 |
if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2535 |
return KErrNotSupported; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2536 |
return GetPreferredDataWriteSize(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2537 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2538 |
case EVMHalGetDataWriteSize: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2539 |
if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2540 |
return KErrNotSupported; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2541 |
return __e32_find_ms1_32(ThePager.PagesToClean()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2542 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2543 |
case EVMHalSetDataWriteSize: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2544 |
if(!TheCurrentThread->HasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by VMHalFunction(EVMHalSetDataWriteSize)"))) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2545 |
K::UnlockedPlatformSecurityPanic(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2546 |
if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2547 |
return KErrNotSupported; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2548 |
return SetDataWriteSize((TUint)a1); |
44 | 2549 |
|
0 | 2550 |
default: |
2551 |
return KErrNotSupported; |
|
2552 |
} |
|
2553 |
} |
|
2554 |
||
2555 |
||
2556 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
2557 |
||
2558 |
void DPager::ResetBenchmarkData(TPagingBenchmark aBm) |
|
2559 |
{ |
|
2560 |
SPagingBenchmarkInfo& info = iBenchmarkInfo[aBm]; |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2561 |
__SPIN_LOCK_IRQ(iBenchmarkLock); |
0 | 2562 |
info.iCount = 0; |
2563 |
info.iTotalTime = 0; |
|
2564 |
info.iMaxTime = 0; |
|
2565 |
info.iMinTime = KMaxTInt; |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2566 |
__SPIN_UNLOCK_IRQ(iBenchmarkLock); |
0 | 2567 |
} |
2568 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2569 |
void DPager::RecordBenchmarkData(TPagingBenchmark aBm, TUint32 aStartTime, TUint32 aEndTime, TUint aCount) |
0 | 2570 |
{ |
2571 |
SPagingBenchmarkInfo& info = iBenchmarkInfo[aBm]; |
|
2572 |
#if !defined(HIGH_RES_TIMER) || defined(HIGH_RES_TIMER_COUNTS_UP) |
|
2573 |
TInt64 elapsed = aEndTime - aStartTime; |
|
2574 |
#else |
|
2575 |
TInt64 elapsed = aStartTime - aEndTime; |
|
2576 |
#endif |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2577 |
__SPIN_LOCK_IRQ(iBenchmarkLock); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2578 |
info.iCount += aCount; |
0 | 2579 |
info.iTotalTime += elapsed; |
2580 |
if (elapsed > info.iMaxTime) |
|
2581 |
info.iMaxTime = elapsed; |
|
2582 |
if (elapsed < info.iMinTime) |
|
2583 |
info.iMinTime = elapsed; |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2584 |
__SPIN_UNLOCK_IRQ(iBenchmarkLock); |
0 | 2585 |
} |
2586 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2587 |
void DPager::ReadBenchmarkData(TPagingBenchmark aBm, SPagingBenchmarkInfo& aDataOut) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2588 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2589 |
__SPIN_LOCK_IRQ(iBenchmarkLock); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2590 |
aDataOut = iBenchmarkInfo[aBm]; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2591 |
__SPIN_UNLOCK_IRQ(iBenchmarkLock); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2592 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2593 |
|
0 | 2594 |
#endif //__DEMAND_PAGING_BENCHMARKS__ |
2595 |
||
2596 |
||
2597 |
// |
|
2598 |
// Paging request management... |
|
2599 |
// |
|
2600 |
||
2601 |
// |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2602 |
// DPagingRequestBase |
0 | 2603 |
// |
2604 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2605 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2606 |
TLinAddr DPagingRequestBase::MapPages(TUint aColour, TUint aCount, TPhysAddr* aPages) |
0 | 2607 |
{ |
2608 |
__NK_ASSERT_DEBUG(iMutex->iCleanup.iThread == &Kern::CurrentThread()); |
|
2609 |
return iTempMapping.Map(aPages,aCount,aColour); |
|
2610 |
} |
|
2611 |
||
2612 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2613 |
void DPagingRequestBase::UnmapPages(TBool aIMBRequired) |
0 | 2614 |
{ |
2615 |
__NK_ASSERT_DEBUG(iMutex->iCleanup.iThread == &Kern::CurrentThread()); |
|
2616 |
iTempMapping.Unmap(aIMBRequired); |
|
2617 |
} |
|
2618 |
||
2619 |
||
2620 |
// |
|
2621 |
// DPageReadRequest |
|
2622 |
// |
|
2623 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2624 |
|
0 | 2625 |
TInt DPageReadRequest::iAllocNext = 0; |
2626 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2627 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2628 |
TUint DPageReadRequest::ReservedPagesRequired() |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2629 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2630 |
return iAllocNext*EMaxPages; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2631 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2632 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2633 |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2634 |
DPageReadRequest::DPageReadRequest(DPagingRequestPool::TGroup& aPoolGroup) : |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2635 |
iPoolGroup(aPoolGroup) |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2636 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2637 |
iTempMapping.Alloc(EMaxPages); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2638 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2639 |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2640 |
|
0 | 2641 |
TInt DPageReadRequest::Construct() |
2642 |
{ |
|
2643 |
// allocate id and mutex... |
|
2644 |
TUint id = (TUint)__e32_atomic_add_ord32(&iAllocNext, 1); |
|
2645 |
_LIT(KLitPagingRequest,"PageReadRequest-"); |
|
2646 |
TBuf<sizeof("PageReadRequest-")+10> mutexName(KLitPagingRequest); |
|
2647 |
mutexName.AppendNum(id); |
|
2648 |
TInt r = K::MutexCreate(iMutex, mutexName, NULL, EFalse, KMutexOrdPageIn); |
|
2649 |
if(r!=KErrNone) |
|
2650 |
return r; |
|
2651 |
||
2652 |
// create memory buffer... |
|
2653 |
TUint bufferSize = EMaxPages+1; |
|
2654 |
DMemoryObject* bufferMemory; |
|
2655 |
r = MM::MemoryNew(bufferMemory,EMemoryObjectUnpaged,bufferSize,EMemoryCreateNoWipe); |
|
2656 |
if(r!=KErrNone) |
|
2657 |
return r; |
|
2658 |
MM::MemorySetLock(bufferMemory,iMutex); |
|
2659 |
TPhysAddr physAddr; |
|
2660 |
r = MM::MemoryAllocContiguous(bufferMemory,0,bufferSize,0,physAddr); |
|
2661 |
(void)physAddr; |
|
2662 |
if(r!=KErrNone) |
|
2663 |
return r; |
|
2664 |
DMemoryMapping* bufferMapping; |
|
2665 |
r = MM::MappingNew(bufferMapping,bufferMemory,ESupervisorReadWrite,KKernelOsAsid); |
|
2666 |
if(r!=KErrNone) |
|
2667 |
return r; |
|
2668 |
iBuffer = MM::MappingBase(bufferMapping); |
|
2669 |
||
2670 |
return r; |
|
2671 |
} |
|
2672 |
||
2673 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2674 |
void DPageReadRequest::Release() |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2675 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2676 |
NKern::LockSystem(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2677 |
ResetUse(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2678 |
Signal(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2679 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2680 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2681 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2682 |
void DPageReadRequest::Wait() |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2683 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2684 |
__ASSERT_SYSTEM_LOCK; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2685 |
++iUsageCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2686 |
TInt r = iMutex->Wait(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2687 |
__NK_ASSERT_ALWAYS(r == KErrNone); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2688 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2689 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2690 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2691 |
void DPageReadRequest::Signal() |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2692 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2693 |
__ASSERT_SYSTEM_LOCK; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2694 |
__NK_ASSERT_DEBUG(iUsageCount > 0); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2695 |
if (--iUsageCount == 0) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2696 |
iPoolGroup.iFreeList.AddHead(&iLink); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2697 |
iMutex->Signal(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2698 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2699 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2700 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2701 |
void DPageReadRequest::SetUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2702 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2703 |
__ASSERT_SYSTEM_LOCK; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2704 |
__NK_ASSERT_DEBUG(aMemory != NULL && aCount <= EMaxPages); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2705 |
__NK_ASSERT_DEBUG(iMemory == NULL); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2706 |
iMemory = aMemory; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2707 |
iIndex = aIndex; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2708 |
iCount = aCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2709 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2710 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2711 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2712 |
void DPageReadRequest::ResetUse() |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2713 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2714 |
__ASSERT_SYSTEM_LOCK; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2715 |
__NK_ASSERT_DEBUG(iMemory != NULL); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2716 |
iMemory = NULL; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2717 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2718 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2719 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2720 |
TBool DPageReadRequest::IsCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2721 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2722 |
__ASSERT_SYSTEM_LOCK; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2723 |
return iMemory == aMemory && aIndex < iIndex + iCount && aIndex + aCount > iIndex; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2724 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2725 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2726 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2727 |
TBool DPageReadRequest::CheckUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2728 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2729 |
return iMemory == aMemory && iIndex == aIndex && iCount == aCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2730 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2731 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2732 |
|
0 | 2733 |
// |
2734 |
// DPageWriteRequest |
|
2735 |
// |
|
2736 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2737 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2738 |
DPageWriteRequest::DPageWriteRequest() |
0 | 2739 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2740 |
iMutex = ThePageCleaningLock; |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2741 |
iTempMapping.Alloc(EMaxPages); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2742 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2743 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2744 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2745 |
void DPageWriteRequest::Release() |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2746 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2747 |
NKern::LockSystem(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2748 |
ResetUse(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2749 |
NKern::UnlockSystem(); |
0 | 2750 |
} |
2751 |
||
2752 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2753 |
void DPageWriteRequest::SetUseDiscontiguous(DMemoryObject** aMemory, TUint* aIndex, TUint aCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2754 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2755 |
__ASSERT_SYSTEM_LOCK; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2756 |
__NK_ASSERT_DEBUG(iUseRegionCount == 0); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2757 |
__NK_ASSERT_DEBUG(aCount > 0 && aCount <= EMaxPages); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2758 |
for (TUint i = 0 ; i < aCount ; ++i) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2759 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2760 |
iUseRegionMemory[i] = aMemory[i]; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2761 |
iUseRegionIndex[i] = aIndex[i]; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2762 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2763 |
iUseRegionCount = aCount; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2764 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2765 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2766 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2767 |
void DPageWriteRequest::ResetUse() |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2768 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2769 |
__ASSERT_SYSTEM_LOCK; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2770 |
__NK_ASSERT_DEBUG(iUseRegionCount > 0); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2771 |
iUseRegionCount = 0; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2772 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2773 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2774 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2775 |
TBool DPageWriteRequest::CheckUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2776 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2777 |
if (iUseRegionCount != aCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2778 |
return EFalse; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2779 |
for (TUint i = 0 ; i < iUseRegionCount ; ++i) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2780 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2781 |
if (iUseRegionMemory[i] != aMemory || iUseRegionIndex[i] != aIndex + i) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2782 |
return EFalse; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2783 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2784 |
return ETrue; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2785 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2786 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2787 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2788 |
TBool DPageWriteRequest::IsCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2789 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2790 |
// note this could be optimised as most of the time we will be checking read/read collusions, |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2791 |
// both of which will be contiguous |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2792 |
__ASSERT_SYSTEM_LOCK; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2793 |
for (TUint i = 0 ; i < iUseRegionCount ; ++i) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2794 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2795 |
if (iUseRegionMemory[i] == aMemory && |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2796 |
TUint(iUseRegionIndex[i] - aIndex) < aCount) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2797 |
return ETrue; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2798 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2799 |
return EFalse; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2800 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2801 |
|
0 | 2802 |
// |
2803 |
// DPagingRequestPool |
|
2804 |
// |
|
2805 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2806 |
DPagingRequestPool::DPagingRequestPool(TUint aNumPageReadRequest, TBool aWriteRequest) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2807 |
: iPageReadRequests(aNumPageReadRequest) |
0 | 2808 |
{ |
2809 |
TUint i; |
|
2810 |
for(i=0; i<aNumPageReadRequest; ++i) |
|
2811 |
{ |
|
2812 |
DPageReadRequest* req = new DPageReadRequest(iPageReadRequests); |
|
2813 |
__NK_ASSERT_ALWAYS(req); |
|
2814 |
TInt r = req->Construct(); |
|
2815 |
__NK_ASSERT_ALWAYS(r==KErrNone); |
|
2816 |
iPageReadRequests.iRequests[i] = req; |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2817 |
iPageReadRequests.iFreeList.Add(&req->iLink); |
0 | 2818 |
} |
2819 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2820 |
if (aWriteRequest) |
0 | 2821 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2822 |
iPageWriteRequest = new DPageWriteRequest(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2823 |
__NK_ASSERT_ALWAYS(iPageWriteRequest); |
0 | 2824 |
} |
2825 |
} |
|
2826 |
||
2827 |
||
2828 |
DPagingRequestPool::~DPagingRequestPool() |
|
2829 |
{ |
|
2830 |
__NK_ASSERT_ALWAYS(0); // deletion not implemented |
|
2831 |
} |
|
2832 |
||
2833 |
||
2834 |
DPageReadRequest* DPagingRequestPool::AcquirePageReadRequest(DMemoryObject* aMemory, TUint aIndex, TUint aCount) |
|
2835 |
{ |
|
2836 |
NKern::LockSystem(); |
|
2837 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2838 |
DPageReadRequest* req; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2839 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2840 |
// check for collision with existing write |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2841 |
if(iPageWriteRequest && iPageWriteRequest->IsCollisionContiguous(aMemory,aIndex,aCount)) |
0 | 2842 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2843 |
NKern::UnlockSystem(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2844 |
PageCleaningLock::Lock(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2845 |
PageCleaningLock::Unlock(); |
0 | 2846 |
return 0; // caller expected to retry if needed |
2847 |
} |
|
2848 |
||
2849 |
// get a request object to use... |
|
2850 |
req = iPageReadRequests.GetRequest(aMemory,aIndex,aCount); |
|
2851 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2852 |
// check no new read or write requests collide with us... |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2853 |
if ((iPageWriteRequest && iPageWriteRequest->IsCollisionContiguous(aMemory,aIndex,aCount)) || |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2854 |
iPageReadRequests.FindCollisionContiguous(aMemory,aIndex,aCount)) |
0 | 2855 |
{ |
2856 |
// another operation is colliding with this region, give up and retry... |
|
2857 |
req->Signal(); |
|
2858 |
return 0; // caller expected to retry if needed |
|
2859 |
} |
|
2860 |
||
2861 |
// we have a request object which we can use... |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2862 |
req->SetUseContiguous(aMemory,aIndex,aCount); |
0 | 2863 |
|
2864 |
NKern::UnlockSystem(); |
|
2865 |
return (DPageReadRequest*)req; |
|
2866 |
} |
|
2867 |
||
2868 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2869 |
DPageWriteRequest* DPagingRequestPool::AcquirePageWriteRequest(DMemoryObject** aMemory, TUint* aIndex, TUint aCount) |
0 | 2870 |
{ |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2871 |
__NK_ASSERT_DEBUG(iPageWriteRequest); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2872 |
__NK_ASSERT_DEBUG(PageCleaningLock::IsHeld()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2873 |
|
0 | 2874 |
NKern::LockSystem(); |
2875 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2876 |
// Collision with existing read requests is not possible here. For a page to be read it must |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2877 |
// not be present, and for it to be written it must be present and dirty. There is no way for a |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2878 |
// page to go between these states without an intervening read on an uninitialised (freshly |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2879 |
// committed) page, which will wait on the first read request. In other words something like |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2880 |
// this: |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2881 |
// |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2882 |
// read (blocks), decommit, re-commit, read (waits on mutex), write (now no pending reads!) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2883 |
// |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2884 |
// Note that a read request can be outstanding and appear to collide with this write, but only |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2885 |
// in the case when the thread making the read has blocked just after acquiring the request but |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2886 |
// before it checks whether the read is still necessasry. This makes it difficult to assert |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2887 |
// that no collisions take place. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2888 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2889 |
iPageWriteRequest->SetUseDiscontiguous(aMemory,aIndex,aCount); |
0 | 2890 |
NKern::UnlockSystem(); |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2891 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2892 |
return iPageWriteRequest; |
0 | 2893 |
} |
2894 |
||
2895 |
||
2896 |
DPagingRequestPool::TGroup::TGroup(TUint aNumRequests) |
|
2897 |
{ |
|
2898 |
iNumRequests = aNumRequests; |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2899 |
iRequests = new DPageReadRequest*[aNumRequests]; |
0 | 2900 |
__NK_ASSERT_ALWAYS(iRequests); |
2901 |
} |
|
2902 |
||
2903 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2904 |
DPageReadRequest* DPagingRequestPool::TGroup::FindCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount) |
0 | 2905 |
{ |
2906 |
__ASSERT_SYSTEM_LOCK; |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2907 |
DPageReadRequest** ptr = iRequests; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2908 |
DPageReadRequest** ptrEnd = ptr+iNumRequests; |
0 | 2909 |
while(ptr<ptrEnd) |
2910 |
{ |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2911 |
DPageReadRequest* req = *ptr++; |
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2912 |
if(req->IsCollisionContiguous(aMemory,aIndex,aCount)) |
0 | 2913 |
return req; |
2914 |
} |
|
2915 |
return 0; |
|
2916 |
} |
|
2917 |
||
2918 |
||
2919 |
static TUint32 RandomSeed = 33333; |
|
2920 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2921 |
DPageReadRequest* DPagingRequestPool::TGroup::GetRequest(DMemoryObject* aMemory, TUint aIndex, TUint aCount) |
0 | 2922 |
{ |
2923 |
__NK_ASSERT_DEBUG(iNumRequests > 0); |
|
2924 |
||
2925 |
// try using an existing request which collides with this region... |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2926 |
DPageReadRequest* req = FindCollisionContiguous(aMemory,aIndex,aCount); |
0 | 2927 |
if(!req) |
2928 |
{ |
|
2929 |
// use a free request... |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2930 |
SDblQueLink* first = iFreeList.GetFirst(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2931 |
if(first) |
0 | 2932 |
{ |
2933 |
// free requests aren't being used... |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2934 |
req = _LOFF(first, DPageReadRequest, iLink); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2935 |
__NK_ASSERT_DEBUG(req->ThreadsWaiting() == 0); |
0 | 2936 |
} |
2937 |
else |
|
2938 |
{ |
|
2939 |
// pick a random request... |
|
2940 |
RandomSeed = RandomSeed*69069+1; // next 'random' number |
|
2941 |
TUint index = (TUint64(RandomSeed) * TUint64(iNumRequests)) >> 32; |
|
2942 |
req = iRequests[index]; |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
2943 |
__NK_ASSERT_DEBUG(req->ThreadsWaiting() > 0); // we only pick random when none are free |
0 | 2944 |
} |
2945 |
} |
|
2946 |
||
2947 |
// wait for chosen request object... |
|
2948 |
req->Wait(); |
|
2949 |
||
2950 |
return req; |
|
2951 |
} |
|
2952 |
||
2953 |
||
2954 |
/** |
|
2955 |
Register the specified paging device with the kernel. |
|
2956 |
||
2957 |
@param aDevice A pointer to the paging device to install |
|
2958 |
||
2959 |
@return KErrNone on success |
|
2960 |
*/ |
|
2961 |
EXPORT_C TInt Kern::InstallPagingDevice(DPagingDevice* aDevice) |
|
2962 |
{ |
|
2963 |
TRACEB(("Kern::InstallPagingDevice(0x%08x) name='%s' type=%d",aDevice,aDevice->iName,aDevice->iType)); |
|
2964 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2965 |
__NK_ASSERT_DEBUG(!ThePager.CacheInitialised()); |
0 | 2966 |
__NK_ASSERT_ALWAYS(aDevice->iReadUnitShift <= KPageShift); |
2967 |
||
2968 |
TInt r = KErrNotSupported; // Will return this if unsupported device type is installed |
|
2969 |
||
2970 |
// create the pools of page out and page in requests... |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2971 |
const TBool writeReq = (aDevice->iType & DPagingDevice::EData) != 0; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
2972 |
aDevice->iRequestPool = new DPagingRequestPool(KPagingRequestsPerDevice, writeReq); |
0 | 2973 |
if(!aDevice->iRequestPool) |
2974 |
{ |
|
2975 |
r = KErrNoMemory; |
|
2976 |
goto exit; |
|
2977 |
} |
|
2978 |
||
2979 |
if(aDevice->iType & DPagingDevice::ERom) |
|
2980 |
{ |
|
2981 |
r = TheRomMemoryManager->InstallPagingDevice(aDevice); |
|
2982 |
if(r!=KErrNone) |
|
2983 |
goto exit; |
|
2984 |
} |
|
2985 |
||
2986 |
if(aDevice->iType & DPagingDevice::ECode) |
|
2987 |
{ |
|
2988 |
r = TheCodePagedMemoryManager->InstallPagingDevice(aDevice); |
|
2989 |
if(r!=KErrNone) |
|
2990 |
goto exit; |
|
2991 |
} |
|
2992 |
||
2993 |
if(aDevice->iType & DPagingDevice::EData) |
|
2994 |
{ |
|
2995 |
r = TheDataPagedMemoryManager->InstallPagingDevice(aDevice); |
|
2996 |
if(r!=KErrNone) |
|
2997 |
goto exit; |
|
2998 |
} |
|
2999 |
||
3000 |
if (K::MemModelAttributes & (EMemModelAttrRomPaging | EMemModelAttrCodePaging | EMemModelAttrDataPaging)) |
|
3001 |
TheThrashMonitor.Start(); |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3002 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3003 |
if (K::MemModelAttributes & EMemModelAttrDataPaging) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3004 |
PageCleaner::Start(); |
0 | 3005 |
|
3006 |
exit: |
|
3007 |
TRACEB(("Kern::InstallPagingDevice returns %d",r)); |
|
3008 |
return r; |
|
3009 |
} |
|
3010 |
||
3011 |
||
3012 |
||
3013 |
// |
|
3014 |
// DDemandPagingLock |
|
3015 |
// |
|
3016 |
||
3017 |
EXPORT_C DDemandPagingLock::DDemandPagingLock() |
|
3018 |
: iReservedPageCount(0), iLockedPageCount(0), iPinMapping(0) |
|
3019 |
{ |
|
3020 |
} |
|
3021 |
||
3022 |
||
3023 |
EXPORT_C TInt DDemandPagingLock::Alloc(TInt aSize) |
|
3024 |
{ |
|
3025 |
TRACEP(("DDemandPagingLock[0x%08x]::Alloc(0x%x)",this,aSize)); |
|
3026 |
iMaxPageCount = ((aSize-1+KPageMask)>>KPageShift)+1; |
|
3027 |
||
3028 |
TInt r = KErrNoMemory; |
|
3029 |
||
3030 |
NKern::ThreadEnterCS(); |
|
3031 |
||
3032 |
TUint maxPt = DVirtualPinMapping::MaxPageTables(iMaxPageCount); |
|
3033 |
// Note, we need to reserve whole pages even for page tables which are smaller |
|
3034 |
// because pinning can remove the page from live list... |
|
3035 |
TUint reserve = iMaxPageCount+maxPt*KNumPagesToPinOnePageTable; |
|
3036 |
if(ThePager.ReservePages(reserve,(TUint&)iReservedPageCount)) |
|
3037 |
{ |
|
3038 |
iPinMapping = DVirtualPinMapping::New(iMaxPageCount); |
|
3039 |
if(iPinMapping) |
|
3040 |
r = KErrNone; |
|
3041 |
else |
|
3042 |
ThePager.UnreservePages((TUint&)iReservedPageCount); |
|
3043 |
} |
|
3044 |
||
3045 |
NKern::ThreadLeaveCS(); |
|
3046 |
TRACEP(("DDemandPagingLock[0x%08x]::Alloc returns %d, iMaxPageCount=%d, iReservedPageCount=%d",this,r,iMaxPageCount,iReservedPageCount)); |
|
3047 |
return r; |
|
3048 |
} |
|
3049 |
||
3050 |
||
3051 |
EXPORT_C void DDemandPagingLock::Free() |
|
3052 |
{ |
|
3053 |
TRACEP(("DDemandPagingLock[0x%08x]::Free()")); |
|
3054 |
Unlock(); |
|
3055 |
NKern::ThreadEnterCS(); |
|
3056 |
DVirtualPinMapping* pinMapping = (DVirtualPinMapping*)__e32_atomic_swp_ord_ptr(&iPinMapping, 0); |
|
3057 |
if (pinMapping) |
|
3058 |
pinMapping->Close(); |
|
3059 |
NKern::ThreadLeaveCS(); |
|
3060 |
ThePager.UnreservePages((TUint&)iReservedPageCount); |
|
3061 |
} |
|
3062 |
||
3063 |
||
3064 |
EXPORT_C TInt DDemandPagingLock::Lock(DThread* aThread, TLinAddr aStart, TInt aSize) |
|
3065 |
{ |
|
3066 |
// TRACEP(("DDemandPagingLock[0x%08x]::Lock(0x%08x,0x%08x,0x%08x)",this,aThread,aStart,aSize)); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3067 |
__NK_ASSERT_ALWAYS(!iLockedPageCount); // lock already used |
0 | 3068 |
|
3069 |
// calculate the number of pages that need to be locked... |
|
3070 |
TUint mask=KPageMask; |
|
3071 |
TUint offset=aStart&mask; |
|
3072 |
TInt numPages = (aSize+offset+mask)>>KPageShift; |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3073 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3074 |
// Should never be asked to lock more pages than are allocated to this object. |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3075 |
__NK_ASSERT_ALWAYS(numPages <= iMaxPageCount); |
0 | 3076 |
|
3077 |
NKern::ThreadEnterCS(); |
|
3078 |
||
3079 |
// find mapping which covers the specified region... |
|
3080 |
TUint offsetInMapping; |
|
3081 |
TUint mapInstanceCount; |
|
3082 |
DMemoryMapping* mapping = MM::FindMappingInThread((DMemModelThread*)aThread, aStart, aSize, offsetInMapping, mapInstanceCount); |
|
3083 |
if(!mapping) |
|
3084 |
{ |
|
3085 |
NKern::ThreadLeaveCS(); |
|
3086 |
return KErrBadDescriptor; |
|
3087 |
} |
|
3088 |
||
3089 |
MmuLock::Lock(); |
|
3090 |
DMemoryObject* memory = mapping->Memory(); |
|
3091 |
if(mapInstanceCount != mapping->MapInstanceCount() || !memory) |
|
3092 |
{// Mapping has been reused or no memory. |
|
3093 |
MmuLock::Unlock(); |
|
3094 |
mapping->Close(); |
|
3095 |
NKern::ThreadLeaveCS(); |
|
3096 |
return KErrBadDescriptor; |
|
3097 |
} |
|
3098 |
||
3099 |
if(!memory->IsDemandPaged()) |
|
3100 |
{ |
|
3101 |
// memory not demand paged, so we have nothing to do... |
|
3102 |
MmuLock::Unlock(); |
|
3103 |
mapping->Close(); |
|
3104 |
NKern::ThreadLeaveCS(); |
|
3105 |
return KErrNone; |
|
3106 |
} |
|
3107 |
||
3108 |
// Open a reference on the memory so it doesn't get deleted. |
|
3109 |
memory->Open(); |
|
3110 |
MmuLock::Unlock(); |
|
3111 |
||
3112 |
// pin memory... |
|
3113 |
TUint index = (offsetInMapping>>KPageShift)+mapping->iStartIndex; |
|
3114 |
TUint count = ((offsetInMapping&KPageMask)+aSize+KPageMask)>>KPageShift; |
|
3115 |
TInt r = ((DVirtualPinMapping*)iPinMapping)->Pin( memory,index,count,mapping->Permissions(), |
|
3116 |
mapping, mapInstanceCount); |
|
3117 |
||
3118 |
if(r==KErrNotFound) |
|
3119 |
{ |
|
3120 |
// some memory wasn't present, so treat this as an error... |
|
3121 |
memory->Close(); |
|
3122 |
mapping->Close(); |
|
3123 |
NKern::ThreadLeaveCS(); |
|
3124 |
return KErrBadDescriptor; |
|
3125 |
} |
|
3126 |
||
3127 |
// we can't fail to pin otherwise... |
|
3128 |
__NK_ASSERT_DEBUG(r!=KErrNoMemory); // separate OOM assert to aid debugging |
|
3129 |
__NK_ASSERT_ALWAYS(r==KErrNone); |
|
3130 |
||
3131 |
// indicate that we have actually pinned... |
|
3132 |
__NK_ASSERT_DEBUG(iLockedPageCount==0); |
|
3133 |
iLockedPageCount = count; |
|
3134 |
||
3135 |
// cleanup... |
|
3136 |
memory->Close(); |
|
3137 |
mapping->Close(); |
|
3138 |
NKern::ThreadLeaveCS(); |
|
3139 |
||
3140 |
return 1; |
|
3141 |
} |
|
3142 |
||
3143 |
||
3144 |
EXPORT_C void DDemandPagingLock::DoUnlock() |
|
3145 |
{ |
|
3146 |
NKern::ThreadEnterCS(); |
|
3147 |
((DVirtualPinMapping*)iPinMapping)->Unpin(); |
|
3148 |
__NK_ASSERT_DEBUG(iLockedPageCount); |
|
3149 |
iLockedPageCount = 0; |
|
3150 |
NKern::ThreadLeaveCS(); |
|
3151 |
} |
|
3152 |
||
3153 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3154 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3155 |
// |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3156 |
// PageCleaningLock |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3157 |
// |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3158 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3159 |
_LIT(KLitPageCleaningLock,"PageCleaningLock"); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3160 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3161 |
void PageCleaningLock::Init() |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3162 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3163 |
__NK_ASSERT_DEBUG(!ThePageCleaningLock); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3164 |
TInt r = Kern::MutexCreate(ThePageCleaningLock, KLitPageCleaningLock, KMutexOrdPageOut); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3165 |
__NK_ASSERT_ALWAYS(r == KErrNone); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3166 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3167 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3168 |
void PageCleaningLock::Lock() |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3169 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3170 |
Kern::MutexWait(*ThePageCleaningLock); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3171 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3172 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3173 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3174 |
void PageCleaningLock::Unlock() |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3175 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3176 |
Kern::MutexSignal(*ThePageCleaningLock); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3177 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3178 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3179 |
TBool PageCleaningLock::IsHeld() |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3180 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3181 |
return ThePageCleaningLock->iCleanup.iThread == &Kern::CurrentThread(); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
3182 |
} |