VirtualBox

root/trunk/include/VBox/gmm.h

Revision 12653, 14.7 kB (checked in by vboxsync, 2 months ago)

various files: doxygen fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 /** @file
2  * GMM - The Global Memory Manager.
3  */
4
5 /*
6  * Copyright (C) 2007 Sun Microsystems, Inc.
7  *
8  * This file is part of VirtualBox Open Source Edition (OSE), as
9  * available from http://www.virtualbox.org. This file is free software;
10  * you can redistribute it and/or modify it under the terms of the GNU
11  * General Public License (GPL) as published by the Free Software
12  * Foundation, in version 2 as it comes in the "COPYING" file of the
13  * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14  * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15  *
16  * The contents of this file may alternatively be used under the terms
17  * of the Common Development and Distribution License Version 1.0
18  * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19  * VirtualBox OSE distribution, in which case the provisions of the
20  * CDDL are applicable instead of those of the GPL.
21  *
22  * You may elect to license modified versions of this file under the
23  * terms and conditions of either the GPL or the CDDL or both.
24  *
25  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26  * Clara, CA 95054 USA or visit http://www.sun.com if you need
27  * additional information or have any questions.
28  */
29
30 #ifndef ___VBox_gmm_h
31 #define ___VBox_gmm_h
32
33 #include <VBox/types.h>
34 #include <VBox/gvmm.h>
35 #include <VBox/sup.h>
36
37 __BEGIN_DECLS
38
39 /** @defgroup   grp_gmm     GMM - The Global Memory Manager
40  * @{
41  */
42
43 /** @def IN_GMM_R0
44  * Used to indicate whether we're inside the same link module as the ring 0
45  * part of the Global Memory Manager or not.
46  */
47 #ifdef DOXYGEN_RUNNING
48 # define IN_GMM_R0
49 #endif
50 /** @def GMMR0DECL
51  * Ring 0 GMM export or import declaration.
52  * @param   type    The return type of the function declaration.
53  */
54 #ifdef IN_GMM_R0
55 # define GMMR0DECL(type)    DECLEXPORT(type) VBOXCALL
56 #else
57 # define GMMR0DECL(type)    DECLIMPORT(type) VBOXCALL
58 #endif
59
60 /** @def IN_GMM_R3
61  * Used to indicate whether we're inside the same link module as the ring 3
62  * part of the Global Memory Manager or not.
63  */
64 #ifdef DOXYGEN_RUNNING
65 # define IN_GMM_R3
66 #endif
67 /** @def GMMR3DECL
68  * Ring 3 GMM export or import declaration.
69  * @param   type    The return type of the function declaration.
70  */
71 #ifdef IN_GMM_R3
72 # define GMMR3DECL(type)    DECLEXPORT(type) VBOXCALL
73 #else
74 # define GMMR3DECL(type)    DECLIMPORT(type) VBOXCALL
75 #endif
76
77
78 /** The chunk shift. (2^20 = 1 MB) */
79 #define GMM_CHUNK_SHIFT                 20
80 /** The allocation chunk size. */
81 #define GMM_CHUNK_SIZE                  (1U << GMM_CHUNK_SHIFT)
82 /** The allocation chunk size in pages. */
83 #define GMM_CHUNK_NUM_PAGES             (1U << (GMM_CHUNK_SHIFT - PAGE_SHIFT))
84 /** The shift factor for converting a page id into a chunk id. */
85 #define GMM_CHUNKID_SHIFT               (GMM_CHUNK_SHIFT - PAGE_SHIFT)
86 /** The last valid Chunk ID value. */
87 #define GMM_CHUNKID_LAST                (GMM_PAGEID_LAST >> GMM_CHUNKID_SHIFT)
88 /** The last valid Page ID value.
89  * The current limit is 2^28 - 1, or almost 1TB if you like.
90  * The constraints are currently dictated by PGMPAGE. */
91 #define GMM_PAGEID_LAST                 (RT_BIT_32(28) - 1)
92 /** Mask out the page index from the Page ID. */
93 #define GMM_PAGEID_IDX_MASK             ((1U << GMM_CHUNKID_SHIFT) - 1)
94 /** The NIL Chunk ID value. */
95 #define NIL_GMM_CHUNKID                 0
96 /** The NIL Page ID value. */
97 #define NIL_GMM_PAGEID                  0
98
99 #if 0 /* wrong - these are guest page pfns and not page ids! */
100 /** Special Page ID used by unassigned pages. */
101 #define GMM_PAGEID_UNASSIGNED           0x0fffffffU
102 /** Special Page ID used by unsharable pages.
103  * Like MMIO2, shadow and heap. This is for later, obviously. */
104 #define GMM_PAGEID_UNSHARABLE           0x0ffffffeU
105 /** The end of the valid Page IDs. This is the first special one. */
106 #define GMM_PAGEID_END                  0x0ffffff0U
107 #endif
108
109
110 /**
111  * Over-commitment policy.
112  */
113 typedef enum GMMOCPOLICY
114 {
115     /** The usual invalid 0 value. */
116     GMMOCPOLICY_INVALID = 0,
117     /** No over-commitment, fully backed.
118      * The GMM guarantees that it will be able to allocate all of the
119      * guest RAM for a VM with OC policy. */
120     GMMOCPOLICY_NO_OC,
121     /** to-be-determined. */
122     GMMOCPOLICY_TBD,
123     /** The end of the valid policy range. */
124     GMMOCPOLICY_END,
125     /** The usual 32-bit hack. */
126     GMMOCPOLICY_32BIT_HACK = 0x7fffffff
127 } GMMOCPOLICY;
128
129 /**
130  * VM / Memory priority.
131  */
132 typedef enum GMMPRIORITY
133 {
134     /** The usual invalid 0 value. */
135     GMMPRIORITY_INVALID = 0,
136     /** High.
137      * When ballooning, ask these VMs last.
138      * When running out of memory, try not to interrupt these VMs. */
139     GMMPRIORITY_HIGH,
140     /** Normal.
141      * When ballooning, don't wait to ask these.
142      * When running out of memory, pause, save and/or kill these VMs. */
143     GMMPRIORITY_NORMAL,
144     /** Low.
145      * When ballooning, maximize these first.
146      * When running out of memory, save or kill these VMs. */
147     GMMPRIORITY_LOW,
148     /** The end of the valid priority range. */
149     GMMPRIORITY_END,
150     /** The custom 32-bit type blowup. */
151     GMMPRIORITY_32BIT_HACK = 0x7fffffff
152 } GMMPRIORITY;
153
154
155 /**
156  * GMM Memory Accounts.
157  */
158 typedef enum GMMACCOUNT
159 {
160     /** The customary invalid zero entry. */
161     GMMACCOUNT_INVALID = 0,
162     /** Account with the base allocations. */
163     GMMACCOUNT_BASE,
164     /** Account with the shadow allocations. */
165     GMMACCOUNT_SHADOW,
166     /** Account with the fixed allocations. */
167     GMMACCOUNT_FIXED,
168     /** The end of the valid values. */
169     GMMACCOUNT_END,
170     /** The usual 32-bit value to finish it off. */
171     GMMACCOUNT_32BIT_HACK = 0x7fffffff
172 } GMMACCOUNT;
173
174
175 /**
176  * A page descriptor for use when freeing pages.
177  * See GMMR0FreePages, GMMR0BalloonedPages.
178  */
179 typedef struct GMMFREEPAGEDESC
180 {
181     /** The Page ID of the page to be freed. */
182     uint32_t idPage;
183 } GMMFREEPAGEDESC;
184 /** Pointer to a page descriptor for freeing pages. */
185 typedef GMMFREEPAGEDESC *PGMMFREEPAGEDESC;
186
187
188 /**
189  * A page descriptor for use when updating and allocating pages.
190  *
191  * This is a bit complicated because we want to do as much as possible
192  * with the same structure.
193  */
194 typedef struct GMMPAGEDESC
195 {
196     /** The physical address of the page.
197      *
198      * @input   GMMR0AllocateHandyPages expects the guest physical address
199      *          to update the GMMPAGE structure with. Pass GMM_GCPHYS_UNSHAREABLE
200      *          when appropriate and NIL_RTHCPHYS when the page wasn't used
201      *          for any specific guest address.
202      *
203      *          GMMR0AllocatePage expects the guest physical address to put in
204      *          the GMMPAGE structure for the page it allocates for this entry.
205      *          Pass NIL_RTHCPHYS and GMM_GCPHYS_UNSHAREABLE as above.
206      *
207      * @output  The host physical address of the allocated page.
208      *          NIL_RTHCPHYS on allocation failure.
209      *
210      * ASSUMES: sizeof(RTHCPHYS) >= sizeof(RTGCPHYS).
211      */
212     RTHCPHYS                    HCPhysGCPhys;
213
214     /** The Page ID.
215      *
216      * @intput  GMMR0AllocateHandyPages expects the Page ID of the page to
217      *          update here. NIL_GMM_PAGEID means no page should be updated.
218      *
219      *          GMMR0AllocatePages requires this to be initialized to
220      *          NIL_GMM_PAGEID currently.
221      *
222      * @output  The ID of the page, NIL_GMM_PAGEID if the allocation failed.
223      */
224     uint32_t                    idPage;
225
226     /** The Page ID of the shared page was replaced by this page.
227      *
228      * @input   GMMR0AllocateHandyPages expects this to indicate a shared
229      *          page that has been replaced by this page and should have its
230      *          reference counter decremented and perhaps be freed up. Use
231      *          NIL_GMM_PAGEID if no shared page was involved.
232      *
233      *          All other APIs expects NIL_GMM_PAGEID here.
234      *
235      * @output  All APIs sets this to NIL_GMM_PAGEID.
236      */
237     uint32_t                    idSharedPage;
238 } GMMPAGEDESC;
239 AssertCompileSize(GMMPAGEDESC, 16);
240 /** Pointer to a page allocation. */
241 typedef GMMPAGEDESC *PGMMPAGEDESC;
242
243 /** GMMPAGEDESC::HCPhysGCPhys value that indicates that the page is shared. */
244 #define GMM_GCPHYS_UNSHAREABLE  (RTHCPHYS)(0xfffffff0)
245
246 GMMR0DECL(int)  GMMR0Init(void);
247 GMMR0DECL(void) GMMR0Term(void);
248 GMMR0DECL(void) GMMR0InitPerVMData(PGVM pGVM);
249 GMMR0DECL(void) GMMR0CleanupVM(PGVM pGVM);
250 GMMR0DECL(int)  GMMR0InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
251                                         GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
252 GMMR0DECL(int)  GMMR0UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
253 GMMR0DECL(int)  GMMR0AllocateHandyPages(PVM pVM, uint32_t cPagesToUpdate, uint32_t cPagesToAlloc, PGMMPAGEDESC paPages);
254 GMMR0DECL(int)  GMMR0AllocatePages(PVM pVM, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount);
255 GMMR0DECL(int)  GMMR0FreePages(PVM pVM, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount);
256 GMMR0DECL(int)  GMMR0BalloonedPages(PVM pVM, uint32_t cBalloonedPages, uint32_t cPagesToFree, PGMMFREEPAGEDESC paPages, bool fCompleted);
257 GMMR0DECL(int)  GMMR0DeflatedBalloon(PVM pVM, uint32_t cPages);
258 GMMR0DECL(int)  GMMR0MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
259 GMMR0DECL(int)  GMMR0SeedChunk(PVM pVM, RTR3PTR pvR3);
260
261
262
263 /**
264  * Request buffer for GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION.
265  * @see GMMR0InitialReservation
266  */
267 typedef struct GMMINITIALRESERVATIONREQ
268 {
269     /** The header. */
270     SUPVMMR0REQHDR  Hdr;
271     uint64_t        cBasePages;         /**< @see GMMR0InitialReservation */
272     uint32_t        cShadowPages;       /**< @see GMMR0InitialReservation */
273     uint32_t        cFixedPages;        /**< @see GMMR0InitialReservation */
274     GMMOCPOLICY     enmPolicy;          /**< @see GMMR0InitialReservation */
275     GMMPRIORITY     enmPriority;        /**< @see GMMR0InitialReservation */
276 } GMMINITIALRESERVATIONREQ;
277 /** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */
278 typedef GMMINITIALRESERVATIONREQ *PGMMINITIALRESERVATIONREQ;
279
280 GMMR0DECL(int)  GMMR0InitialReservationReq(PVM pVM, PGMMINITIALRESERVATIONREQ pReq);
281
282
283 /**
284  * Request buffer for GMMR0UpdateReservationReq / VMMR0_DO_GMM_UPDATE_RESERVATION.
285  * @see GMMR0UpdateReservation
286  */
287 typedef struct GMMUPDATERESERVATIONREQ
288 {
289     /** The header. */
290     SUPVMMR0REQHDR  Hdr;
291     uint64_t        cBasePages;         /**< @see GMMR0UpdateReservation */
292     uint32_t        cShadowPages;       /**< @see GMMR0UpdateReservation */
293     uint32_t        cFixedPages;        /**< @see GMMR0UpdateReservation */
294 } GMMUPDATERESERVATIONREQ;
295 /** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */
296 typedef GMMUPDATERESERVATIONREQ *PGMMUPDATERESERVATIONREQ;
297
298 GMMR0DECL(int)  GMMR0UpdateReservationReq(PVM pVM, PGMMUPDATERESERVATIONREQ pReq);
299
300
301 /**
302  * Request buffer for GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES.
303  * @see GMMR0AllocatePages.
304  */
305 typedef struct GMMALLOCATEPAGESREQ
306 {
307     /** The header. */
308     SUPVMMR0REQHDR  Hdr;
309     /** The account to charge the allocation to. */
310     GMMACCOUNT      enmAccount;
311     /** The number of pages to allocate. */
312     uint32_t        cPages;
313     /** Array of page descriptors. */
314     GMMPAGEDESC     aPages[1];
315 } GMMALLOCATEPAGESREQ;
316 /** Pointer to a GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES request buffer. */
317 typedef GMMALLOCATEPAGESREQ *PGMMALLOCATEPAGESREQ;
318
319 GMMR0DECL(int)  GMMR0AllocatePagesReq(PVM pVM, PGMMALLOCATEPAGESREQ pReq);
320
321
322 /**
323  * Request buffer for GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES.
324  * @see GMMR0FreePages.
325  */
326 typedef struct GMMFREEPAGESREQ
327 {
328     /** The header. */
329     SUPVMMR0REQHDR  Hdr;
330     /** The account this relates to. */
331     GMMACCOUNT      enmAccount;
332     /** The number of pages to free. */
333     uint32_t        cPages;
334     /** Array of free page descriptors. */
335     GMMFREEPAGEDESC aPages[1];
336 } GMMFREEPAGESREQ;
337 /** Pointer to a GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES request buffer. */
338 typedef GMMFREEPAGESREQ *PGMMFREEPAGESREQ;
339
340 GMMR0DECL(int)  GMMR0FreePagesReq(PVM pVM, PGMMFREEPAGESREQ pReq);
341
342
343 /**
344  * Request buffer for GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES.
345  * @see GMMR0BalloonedPages.
346  */
347 typedef struct GMMBALLOONEDPAGESREQ
348 {
349     /** The header. */
350     SUPVMMR0REQHDR  Hdr;
351     /** The number of ballooned pages. */
352     uint32_t        cBalloonedPages;
353     /** The number of pages to free. */
354     uint32_t        cPagesToFree;
355     /** Whether the ballooning request is completed or more pages are still to come. */
356     bool            fCompleted;
357     /** Array of free page descriptors. */
358     GMMFREEPAGEDESC aPages[1];
359 } GMMBALLOONEDPAGESREQ;
360 /** Pointer to a GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES request buffer. */
361 typedef GMMBALLOONEDPAGESREQ *PGMMBALLOONEDPAGESREQ;
362
363 GMMR0DECL(int)  GMMR0BalloonedPagesReq(PVM pVM, PGMMBALLOONEDPAGESREQ pReq);
364
365
366 /**
367  * Request buffer for GMMR0MapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK.
368  * @see GMMR0MapUnmapChunk
369  */
370 typedef struct GMMMAPUNMAPCHUNKREQ
371 {
372     /** The header. */
373     SUPVMMR0REQHDR  Hdr;
374     /** The chunk to map, UINT32_MAX if unmap only. (IN) */
375     uint32_t        idChunkMap;
376     /** The chunk to unmap, UINT32_MAX if map only. (IN) */
377     uint32_t        idChunkUnmap;
378     /** Where the mapping address is returned. (OUT) */
379     RTR3PTR         pvR3;
380 } GMMMAPUNMAPCHUNKREQ;
381 /** Pointer to a GMMR0MapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK request buffer. */
382 typedef GMMMAPUNMAPCHUNKREQ *PGMMMAPUNMAPCHUNKREQ;
383
384 GMMR0DECL(int)  GMMR0MapUnmapChunkReq(PVM pVM, PGMMMAPUNMAPCHUNKREQ pReq);
385
386
387 #ifdef IN_RING3
388 /** @defgroup grp_gmm_r3    The Global Memory Manager Ring-3 API Wrappers
389  * @ingroup grp_gmm
390  * @{
391  */
392 GMMR3DECL(int)  GMMR3InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
393                                         GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
394 GMMR3DECL(int)  GMMR3UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
395 GMMR3DECL(int)  GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
396 GMMR3DECL(int)  GMMR3AllocatePagesPerform(PVM pVM, PGMMALLOCATEPAGESREQ pReq);
397 GMMR3DECL(void) GMMR3AllocatePagesCleanup(PGMMALLOCATEPAGESREQ pReq);
398 GMMR3DECL(int)  GMMR3FreePagesPrepare(PVM pVM, PGMMFREEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
399 GMMR3DECL(int)  GMMR3FreePagesPerform(PVM pVM, PGMMFREEPAGESREQ pReq);
400 GMMR3DECL(void) GMMR3FreePagesCleanup(PGMMFREEPAGESREQ pReq);
401 GMMR3DECL(void) GMMR3FreeAllocatedPages(PVM pVM, GMMALLOCATEPAGESREQ const *pAllocReq);
402 GMMR3DECL(int)  GMMR3DeflatedBalloon(PVM pVM, uint32_t cPages);
403 GMMR3DECL(int)  GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
404 GMMR3DECL(int)  GMMR3SeedChunk(PVM pVM, RTR3PTR pvR3);
405 /** @} */
406 #endif /* IN_RING3 */
407
408 /** @} */
409
410 __END_DECLS
411
412 #endif
413
Note: See TracBrowser for help on using the browser.

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy