author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 11:08:29 +0300 | |
changeset 247 | d8d70de2bd36 |
parent 201 | 43365a9b78a3 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2007-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 |
/** |
|
17 |
@file |
|
18 |
@internalComponent |
|
19 |
*/ |
|
20 |
||
21 |
#ifndef MPTALLOC_H |
|
22 |
#define MPTALLOC_H |
|
23 |
||
24 |
#include "mcleanup.h" |
|
25 |
||
26 |
/** |
|
27 |
Number of #SPageTableInfo structures which will fit into a page of RAM. |
|
28 |
*/ |
|
29 |
const TUint KPageTableInfosPerPage = KPageSize/sizeof(SPageTableInfo); |
|
30 |
||
31 |
/** |
|
32 |
Number of pages of page tables which correspond to a page of page infos. |
|
33 |
*/ |
|
34 |
const TUint KPageTableGroupSize = KPageTableInfosPerPage/KPtClusterSize; |
|
35 |
||
36 |
/** |
|
37 |
Max number of RAM pages which can be used for page tables. |
|
38 |
*/ |
|
39 |
const TUint KMaxPageTablePages = (KPageTableEnd-KPageTableBase)/KPageSize; |
|
40 |
||
41 |
||
42 |
/** |
|
43 |
The maximum number of pages required to pin a single page table. |
|
44 |
*/ |
|
45 |
const TUint KNumPagesToPinOnePageTable = 2; // 1 page table page + 1 page table info page |
|
46 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
47 |
/** |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
The minimum number of unpinned paged page table pages required so a page fault |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
can't fail to allocate a page table. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
*/ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
const TUint KMinUnpinnedPagedPtPages = KMaxCpus; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
|
0 | 53 |
|
54 |
/** |
|
55 |
Class for allocating MMU page tables. |
|
56 |
*/ |
|
57 |
class PageTableAllocator |
|
58 |
{ |
|
59 |
public: |
|
60 |
void Init2(DMutex* aLock); |
|
61 |
void Init2B(); |
|
62 |
||
63 |
/** |
|
64 |
Allocate a page table. |
|
65 |
||
66 |
@param aDemandPaged True if the page table will be used to map demand paged memory; |
|
67 |
false, otherwise. |
|
68 |
||
69 |
@return Virtual address of the allocated page table, |
|
70 |
or the null-pointer if there was insufficient memory. |
|
71 |
||
72 |
@pre #PageTablesLockIsHeld, i.e. current thread has called #Lock() |
|
73 |
*/ |
|
74 |
TPte* Alloc(TBool aDemandPaged); |
|
75 |
||
76 |
/** |
|
77 |
Free a page table previously aquired with #Alloc. |
|
78 |
||
79 |
@param aPageTable Virtual address of the page table, |
|
80 |
||
81 |
@pre #PageTablesLockIsHeld, i.e. current thread has called #Lock() |
|
82 |
*/ |
|
83 |
void Free(TPte* aPageTable); |
|
84 |
||
85 |
/** |
|
86 |
Acquire the mutex used to protect page table allocation. |
|
87 |
*/ |
|
88 |
void Lock(); |
|
89 |
||
90 |
/** |
|
91 |
Release the mutex used to protect page table allocation. |
|
92 |
*/ |
|
93 |
void Unlock(); |
|
94 |
||
95 |
/** |
|
96 |
Return true if the current thread has acquired the mutex used to protect page table allocation. |
|
97 |
I.e. has called #Lock(). |
|
98 |
*/ |
|
99 |
TBool LockIsHeld(); |
|
100 |
||
101 |
/** |
|
102 |
Steal a RAM page which is currently being used to store demand paged page tables |
|
103 |
or page table infos. |
|
104 |
||
105 |
This removes the page tables contained in the RAM from any objects which own |
|
106 |
them and then returns the RAM to the demand paging system as a free page. This |
|
107 |
will not ever return KErrNone indicating that the page has been successfully |
|
108 |
stolen. |
|
109 |
||
110 |
This is only intended for use by DPageTableMemoryManager::StealPage. |
|
111 |
||
112 |
@param aPageInfo The page information structure of the page to be stolen. |
|
113 |
||
114 |
@return KErrCompletion to indicate that the page was stolen but has been |
|
115 |
returned to the demand paging live list as a free page. |
|
116 |
Otherwise, KErrInUse if the page was not able to be freed. |
|
117 |
||
118 |
@pre #PageTablesLockIsHeld, i.e. current thread has called #Lock() |
|
119 |
@pre MmuLock held. |
|
120 |
*/ |
|
121 |
TInt StealPage(SPageInfo* aPageInfo); |
|
122 |
||
123 |
/** |
|
124 |
Discards a page of page tables or page table infos but only if it is demand paged. |
|
125 |
||
126 |
This will only be invoked on page table info pages or pinned paged tables |
|
127 |
as they aren't on the live list and so M::MovePage() will not know the pager |
|
128 |
can discard them. |
|
129 |
||
130 |
@param aMemory This should always be the page table info memory object. |
|
131 |
@param aOldPageInfo The page info of the page to discard. |
|
132 |
@param aBlockZoneId The ID of any RAM zone not to be allocated into. |
|
133 |
@param aBlockRest ETrue when any allocations should stop if blocked zone hit. |
|
134 |
||
135 |
@return KErrNone if the page could be successfully discarded and its RAM page freed. |
|
136 |
*/ |
|
137 |
TInt MovePage( DMemoryObject* aMemory, SPageInfo* aOldPageInfo, |
|
138 |
TUint aBlockZoneId, TBool aBlockRest); |
|
139 |
||
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
140 |
/** |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
141 |
Attempts to discard a page of page tables using #MovePage. If the discard was |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
142 |
succesful it then allocates the page with type aPageType. |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
143 |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
144 |
@param aMemory This should always be the page table info memory object. |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
145 |
@param aPageInfo The page info of the page to discard. |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
146 |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
147 |
@return KErrNone if the page could be successfully discarded and its RAM page allocated. |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
148 |
*/ |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
149 |
TInt MoveAndAllocPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TZonePageType aPageType); |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
150 |
|
0 | 151 |
#ifdef _DEBUG |
152 |
/** |
|
153 |
Debug function for use by DPager::RemovePage() to allow it to remove |
|
154 |
pages with paged state == EUnpaged. |
|
155 |
||
156 |
A page table page may be stolen when it is unpaged as it has been |
|
157 |
allocated via DMemoryMapping::AllocatePageTable() but not yet rejuvenated |
|
158 |
by Mmu::PageInPages() as the MmuLock is released between these stages. |
|
159 |
||
160 |
A page table info page is never added to the live list so it will always |
|
161 |
be unpaged but it can be stolen so allow it to be removed. |
|
162 |
||
163 |
@param aPageInfo The page info of the page. |
|
164 |
||
165 |
@return ETrue if the page is a page table info page, EFalse otherwise. |
|
166 |
*/ |
|
167 |
TBool IsPageTableUnpagedRemoveAllowed(SPageInfo* aPageInfo); |
|
168 |
#endif |
|
169 |
||
170 |
/** |
|
171 |
Pin the RAM page containing a page table, as well as the RAM page |
|
172 |
containing its #SPageTableInfo structure. |
|
173 |
||
174 |
@param aPageTable Virtual address of the page table, |
|
175 |
@param aPinArgs The resources to use for pinning. This must have |
|
176 |
at least #KNumPagesToPinOnePageTable replacement |
|
177 |
pages available. |
|
178 |
*/ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
TInt PinPageTable(TPte* aPageTable, TPinArgs& aPinArgs); |
0 | 180 |
|
181 |
/** |
|
182 |
Unpin the RAM page containing a page table, as well as the RAM page |
|
183 |
containing its #SPageTableInfo structure. |
|
184 |
This reverses the action of #PinPageTable. |
|
185 |
||
186 |
@param aPageTable Virtual address of the page table, |
|
187 |
@param aPinArgs The resources to use for pinning. The replacement |
|
188 |
pages count in this will be incremented for each |
|
189 |
completely unpinned, e.g. those which can be reused |
|
190 |
as new replacement pages or freed. |
|
191 |
*/ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
void UnpinPageTable(TPte* aPageTable, TPinArgs& aPinArgs); |
0 | 193 |
|
194 |
private: |
|
195 |
/** |
|
196 |
Sub-allocator used for managing page tables of a given 'pagedness' (paged/not-paged). |
|
197 |
Each allocator maintains a list free page tables (#iFreeList) from which it can allocate. |
|
198 |
As well as a separate list of RAM pages which have no allocated page tables, #iCleanupList. |
|
199 |
Page tables in the RAM on #iCleanupList do not appear in #iFreeList. |
|
200 |
*/ |
|
201 |
class TSubAllocator |
|
202 |
{ |
|
203 |
public: |
|
204 |
void Init2(PageTableAllocator* iAllocator, TUint aReserveCount, TBool aDemandPaged); |
|
205 |
||
206 |
/** |
|
207 |
Allocate a page table from this sub-allocator. |
|
208 |
||
209 |
@return The #SPageTableInfo structure of the page table, |
|
210 |
or the null-pointer if none could be allocated. |
|
211 |
*/ |
|
212 |
SPageTableInfo* Alloc(); |
|
213 |
||
214 |
/** |
|
215 |
Free a page table back to this sub-allocator. |
|
216 |
||
217 |
@param aPageTableInfo The #SPageTableInfo structure of the page table. |
|
218 |
*/ |
|
219 |
void Free(SPageTableInfo* aPageTableInfo); |
|
220 |
||
221 |
/** |
|
222 |
Add a single page of page tables to this allocator for management. |
|
223 |
||
224 |
@param aPageTableInfo The #SPageTableInfo structure of the first page table |
|
225 |
contained in the page. |
|
226 |
*/ |
|
227 |
void AllocPage(SPageTableInfo* aPageTableInfo); |
|
228 |
||
229 |
/** |
|
230 |
Attempt to remove a single unused page of page tables from this allocator. |
|
231 |
||
232 |
@return The #SPageTableInfo structure of the first page table contained |
|
233 |
in the removed page. Or the null-pointer if there were no unused |
|
234 |
memory to be freed. |
|
235 |
*/ |
|
236 |
SPageTableInfo* FreePage(); |
|
237 |
||
238 |
/** |
|
239 |
Move a page of RAM containing page tables to #iCleanupList. |
|
240 |
All page tables in the page must be currently unused. |
|
241 |
||
242 |
@param aPageTableInfo The #SPageTableInfo structure of the first page table |
|
243 |
contained in the page. |
|
244 |
*/ |
|
245 |
void MoveToCleanup(SPageTableInfo* aPageTableInfo); |
|
246 |
||
247 |
/** |
|
248 |
Return true if there are whole RAM pages which can be freed from this |
|
249 |
sub-allocator without reducing #iFreeCount below #iReserveCount. |
|
250 |
*/ |
|
251 |
TBool IsCleanupRequired(); |
|
252 |
||
253 |
/** |
|
254 |
Debug check returning true if this objects lists are in a valid state. |
|
255 |
*/ |
|
256 |
TBool CheckFreeList(); |
|
257 |
public: |
|
258 |
SDblQue iFreeList; ///< List of unused page tables, linked by their SPageTableInfo::FreeLink. |
|
259 |
SDblQue iCleanupList; ///< List of unused pages, linked by the SPageTableInfo::FreeLink of the first page table in the page. |
|
260 |
TUint iFreeCount; ///< Total free page tables in pages on #iFreeList and #iCleanupList. |
|
261 |
TUint iReserveCount; ///< Minimum number of page tables to keep in reserve. |
|
262 |
TBool iDemandPaged; ///< True if this allocator id used for demand paged page tables. |
|
263 |
}; |
|
264 |
||
265 |
/** |
|
266 |
Implementation of #Alloc. |
|
267 |
*/ |
|
268 |
TPte* DoAlloc(TBool aDemandPaged); |
|
269 |
||
270 |
/** |
|
271 |
Implementation of #Free. |
|
272 |
*/ |
|
273 |
void DoFree(TPte* aPageTable); |
|
274 |
||
275 |
/** |
|
276 |
Allocate resources for a pages worth of page tables owned by \a aSubAllocator. |
|
277 |
||
278 |
@return True if the resources were successfully allocated. |
|
279 |
||
280 |
@pre #PageTablesLockIsHeld, i.e. current thread has called #Lock() |
|
281 |
*/ |
|
282 |
TBool AllocReserve(TSubAllocator& aSubAllocator); |
|
283 |
||
284 |
/** |
|
285 |
Free the resources taken up by a pages worth of unused page tables |
|
286 |
owned by \a aSubAllocator. |
|
287 |
||
288 |
@return True, if any resources were freed. |
|
289 |
False, if there are no more unused resources. |
|
290 |
||
291 |
@pre #PageTablesLockIsHeld, i.e. current thread has called #Lock() |
|
292 |
*/ |
|
293 |
TBool FreeReserve(TSubAllocator& aSubAllocator); |
|
294 |
||
295 |
/** |
|
296 |
Steal a RAM page which is currently being used to store demand paged page |
|
297 |
table infos. |
|
298 |
||
299 |
This removes all the page tables references by the page table infos contained in |
|
300 |
the RAM from any objects which own them and then returns the RAM to the demand |
|
301 |
paging system as a free page. This will not ever return KErrNone indicating that |
|
302 |
the page has been successfully stolen. |
|
303 |
||
304 |
This is only intended for use by PageTableAllocator::StealPage. |
|
305 |
||
306 |
@param aPageInfo The page information structure of the page to be stolen. |
|
307 |
||
308 |
@return KErrCompletion to indicate that the page was stolen but has been |
|
309 |
returned to the demand paging live list as a free page. |
|
310 |
Otherwise, KErrInUse if the page was not able to be freed. |
|
311 |
||
312 |
@pre #PageTablesLockIsHeld, i.e. current thread has called #Lock() |
|
313 |
@pre MmuLock held. |
|
314 |
*/ |
|
315 |
TInt StealPageTableInfo(SPageInfo* aPageInfo); |
|
316 |
||
317 |
/** |
|
318 |
Free all unused resources taken up for page table management. |
|
319 |
*/ |
|
320 |
void Cleanup(); |
|
321 |
||
322 |
/** |
|
323 |
Trampoline function for use with iCleanup which redirects to #Cleanup(). |
|
324 |
*/ |
|
325 |
static void CleanupTrampoline(TAny* aSelf); |
|
326 |
||
327 |
private: |
|
328 |
/** |
|
329 |
Sub-allocator for allocating unpaged page tables. |
|
330 |
*/ |
|
331 |
TSubAllocator iUnpagedAllocator; |
|
332 |
||
333 |
/** |
|
334 |
Sub-allocator for allocating demand paged page tables. |
|
335 |
*/ |
|
336 |
TSubAllocator iPagedAllocator; |
|
337 |
||
338 |
/** |
|
339 |
Object used for queueing cleanup callbacks to #CleanupTrampoline. |
|
340 |
*/ |
|
341 |
TMemoryCleanup iCleanup; |
|
342 |
||
343 |
/** |
|
344 |
Recursion count for #Alloc. |
|
345 |
*/ |
|
346 |
TUint iAllocating; |
|
347 |
||
348 |
/** |
|
349 |
The mutex used to protect page table allocation. |
|
350 |
*/ |
|
351 |
DMutex* iLock; |
|
352 |
||
353 |
/** |
|
354 |
The memory object used to store the memory containing page tables. |
|
355 |
*/ |
|
356 |
DMemoryObject* iPageTableMemory; |
|
357 |
||
358 |
/** |
|
359 |
The memory object used to store #SPageTableInfo structures. |
|
360 |
*/ |
|
361 |
DMemoryObject* iPageTableInfoMemory; |
|
362 |
||
363 |
/** |
|
364 |
Helper class for allocating page index values within #iPageTableMemory. |
|
365 |
This wraps up to two bitmap allocators, one each used for paged and unpaged |
|
366 |
page tables. |
|
367 |
||
368 |
Page indexes are allocated in a way which ensures that there will not be |
|
369 |
any SPageTableInfo structures for unpaged page tables in the same RAM page |
|
370 |
as the structures for paged page tables. |
|
371 |
*/ |
|
372 |
class TPtPageAllocator |
|
373 |
{ |
|
374 |
public: |
|
375 |
void Init2(TUint aNumInitPages); |
|
376 |
TInt Alloc(TBool aDemandPaged); |
|
377 |
void Free(TUint aPageIndex, TBool aDemandPaged); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
/** |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
380 |
Determine if the page table info page is paged. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
@param aPageInfo Pointer to the SPageInfo of the page table info page. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
@return ETrue if the page table info page is paged, EFalse otherwise. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
@pre MmuLock is held. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
*/ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
inline TBool IsDemandPagedPtInfo(SPageInfo* aPageInfo) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
// Is the highest page table index this page table info page can reference |
0 | 389 |
// allocated within the demand paged region of the page table address space. |
390 |
TUint groupIndex = aPageInfo->Index(); |
|
391 |
return ((groupIndex+1) * KPageTableGroupSize)-1 >= iUpperWaterMark; |
|
392 |
} |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
/** |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
Determine if the page table page is paged. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
@param aPageInfo Pointer to the SPageInfo of the page table info page. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
@return ETrue if the page table page is paged, EFalse otherwise. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
@pre MmuLock is held. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
*/ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
inline TBool IsDemandPagedPt(SPageInfo* aPageInfo) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
return aPageInfo->Index() >= iUpperWaterMark; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
/** |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
Get a random paged page table page. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
@return The index of a paged page table page. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
@pre All paged page table pages are allocated. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
@pre Page tables lock is held. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
*/ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
TUint RandomPagedPtPage(); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
/** |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
Increase the count of pinned paged page table pages. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
@return KErrNone on success, KErrNoMemory if too many pages are already pinned. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
@pre MmuLock is held |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
*/ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
inline TInt PtPagePinCountInc() |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
if (AtPinnedPagedPtsLimit(iUpperWaterMark, iLowerWaterMark, iPinnedPageTablePages + 1)) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
425 |
return KErrNoMemory; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
427 |
iPinnedPageTablePages++; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
428 |
return KErrNone; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
430 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
431 |
/** |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
432 |
Decrease the count of pinned paged page table pages. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
433 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
434 |
@pre MmuLock is held |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
435 |
*/ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
inline void PtPagePinCountDec() |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
__NK_ASSERT_DEBUG(iPinnedPageTablePages); // Can't be zero. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
439 |
iPinnedPageTablePages--; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
440 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
441 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
442 |
private: |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
443 |
/** |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
444 |
Check whether it is safe to pin a paged page table or reduce the amount of |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
445 |
virtual address space available to paged page tables. By checking that we |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
446 |
either have spare virtual address space to increase the amount of paged page |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
447 |
tables or that there are already enough unpinned paged page tables. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
448 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
449 |
@return ETrue if there isn't or EFalse if it is ok to pin more paged page |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
450 |
tables or increase the number of unpaged page tables. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
*/ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
452 |
TBool AtPinnedPagedPtsLimit(TUint aUpperWaterMark, TUint aLowerWaterMark, TUint aPinnedPtPages) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
453 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
454 |
TUint adjustedUpperWaterMark = aUpperWaterMark & ~(KPageTableGroupSize - 1); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
455 |
TUint availPagedPtPages = KMaxPageTablePages - adjustedUpperWaterMark; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
456 |
TUint availUnpinnedPagedPtPages = availPagedPtPages - aPinnedPtPages; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
457 |
// This check is sufficient as we only increase the pinned paged page table |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
458 |
// pages or unpaged page table pages one at a time. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
459 |
return (aLowerWaterMark + 1 == adjustedUpperWaterMark && |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
460 |
availUnpinnedPagedPtPages < KMinUnpinnedPagedPtPages); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
461 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
462 |
|
0 | 463 |
private: |
464 |
TBitMapAllocator* iLowerAllocator; ///< Allocator for unpaged page tables |
|
465 |
TUint iLowerWaterMark; ///< Highest page index allocated by iLowerAllocator |
|
466 |
TBitMapAllocator* iUpperAllocator; ///< Allocator for demand paged page tables |
|
467 |
TUint iUpperWaterMark; ///< Lowest page index allocated by iUpperAllocator |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
TUint iPinnedPageTablePages; ///< The number of pinned paged page table pages. |
0 | 469 |
}; |
470 |
||
471 |
/** |
|
472 |
Allocator for page indexes within #iPageTableMemory. |
|
473 |
*/ |
|
474 |
TPtPageAllocator iPtPageAllocator; |
|
475 |
||
476 |
/** |
|
477 |
Array which contains usage for pages of #SPageTableInfo structures. |
|
478 |
When the count is zero, there are no structure in use in the corresponding |
|
479 |
page of memory in #iPageTableInfoMemory. Indicating that the memory may be |
|
480 |
freed. |
|
481 |
*/ |
|
482 |
TUint16 iPageTableGroupCounts[KMaxPageTablePages/KPageTableGroupSize]; |
|
483 |
||
484 |
friend class TSubAllocator; |
|
485 |
}; |
|
486 |
||
487 |
||
488 |
/** |
|
489 |
The single instance of the #PageTableAllocator. |
|
490 |
*/ |
|
491 |
extern PageTableAllocator PageTables; |
|
492 |
||
493 |
||
494 |
#endif |