VirtualBox

source: vbox/trunk/include/VBox/vmm/gmm.h@ 40005

Last change on this file since 40005 was 40005, checked in by vboxsync, 13 years ago

More GMM stats. Added todo regarding GMMR0SharedModuleCheckPage assertion.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 29.7 KB
Line 
1/** @file
2 * GMM - The Global Memory Manager.
3 */
4
5/*
6 * Copyright (C) 2007-2010 Oracle Corporation
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
26#ifndef ___VBox_vmm_gmm_h
27#define ___VBox_vmm_gmm_h
28
29#include <VBox/vmm/gvmm.h>
30#include <VBox/sup.h>
31#include <VBox/param.h>
32#include <iprt/avl.h>
33
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_gmm GMM - The Global Memory Manager
38 * @{
39 */
40
41/** @def IN_GMM_R0
42 * Used to indicate whether we're inside the same link module as the ring 0
43 * part of the Global Memory Manager or not.
44 */
45#ifdef DOXYGEN_RUNNING
46# define IN_GMM_R0
47#endif
48/** @def GMMR0DECL
49 * Ring 0 GMM export or import declaration.
50 * @param type The return type of the function declaration.
51 */
52#ifdef IN_GMM_R0
53# define GMMR0DECL(type) DECLEXPORT(type) VBOXCALL
54#else
55# define GMMR0DECL(type) DECLIMPORT(type) VBOXCALL
56#endif
57
58/** @def IN_GMM_R3
59 * Used to indicate whether we're inside the same link module as the ring 3
60 * part of the Global Memory Manager or not.
61 */
62#ifdef DOXYGEN_RUNNING
63# define IN_GMM_R3
64#endif
65/** @def GMMR3DECL
66 * Ring 3 GMM export or import declaration.
67 * @param type The return type of the function declaration.
68 */
69#ifdef IN_GMM_R3
70# define GMMR3DECL(type) DECLEXPORT(type) VBOXCALL
71#else
72# define GMMR3DECL(type) DECLIMPORT(type) VBOXCALL
73#endif
74
75
76/** The chunk shift. (2^21 = 2 MB) */
77#define GMM_CHUNK_SHIFT 21
78/** The allocation chunk size. */
79#define GMM_CHUNK_SIZE (1U << GMM_CHUNK_SHIFT)
80/** The allocation chunk size in pages. */
81#define GMM_CHUNK_NUM_PAGES (1U << (GMM_CHUNK_SHIFT - PAGE_SHIFT))
82/** The shift factor for converting a page id into a chunk id. */
83#define GMM_CHUNKID_SHIFT (GMM_CHUNK_SHIFT - PAGE_SHIFT)
84/** The last valid Chunk ID value. */
85#define GMM_CHUNKID_LAST (GMM_PAGEID_LAST >> GMM_CHUNKID_SHIFT)
86/** The last valid Page ID value.
87 * The current limit is 2^28 - 1, or almost 1TB if you like.
88 * The constraints are currently dictated by PGMPAGE. */
89#define GMM_PAGEID_LAST (RT_BIT_32(28) - 1)
90/** Mask out the page index from the Page ID. */
91#define GMM_PAGEID_IDX_MASK ((1U << GMM_CHUNKID_SHIFT) - 1)
92/** The NIL Chunk ID value. */
93#define NIL_GMM_CHUNKID 0
94/** The NIL Page ID value. */
95#define NIL_GMM_PAGEID 0
96
97#if 0 /* wrong - these are guest page pfns and not page ids! */
98/** Special Page ID used by unassigned pages. */
99#define GMM_PAGEID_UNASSIGNED 0x0fffffffU
100/** Special Page ID used by unsharable pages.
101 * Like MMIO2, shadow and heap. This is for later, obviously. */
102#define GMM_PAGEID_UNSHARABLE 0x0ffffffeU
103/** The end of the valid Page IDs. This is the first special one. */
104#define GMM_PAGEID_END 0x0ffffff0U
105#endif
106
107
108/** @def GMM_GCPHYS_LAST
109 * The last of the valid guest physical address as it applies to GMM pages.
110 *
111 * This must reflect the constraints imposed by the RTGCPHYS type and
112 * the guest page frame number used internally in GMMPAGE.
113 *
114 * @note Note this corresponds to GMM_PAGE_PFN_LAST. */
115#if HC_ARCH_BITS == 64
116# define GMM_GCPHYS_LAST UINT64_C(0x00000fffffff0000) /* 2^44 (16TB) - 0x10000 */
117#else
118# define GMM_GCPHYS_LAST UINT64_C(0x0000000fffff0000) /* 2^36 (64GB) - 0x10000 */
119#endif
120
121/**
122 * Over-commitment policy.
123 */
124typedef enum GMMOCPOLICY
125{
126 /** The usual invalid 0 value. */
127 GMMOCPOLICY_INVALID = 0,
128 /** No over-commitment, fully backed.
129 * The GMM guarantees that it will be able to allocate all of the
130 * guest RAM for a VM with OC policy. */
131 GMMOCPOLICY_NO_OC,
132 /** to-be-determined. */
133 GMMOCPOLICY_TBD,
134 /** The end of the valid policy range. */
135 GMMOCPOLICY_END,
136 /** The usual 32-bit hack. */
137 GMMOCPOLICY_32BIT_HACK = 0x7fffffff
138} GMMOCPOLICY;
139
140/**
141 * VM / Memory priority.
142 */
143typedef enum GMMPRIORITY
144{
145 /** The usual invalid 0 value. */
146 GMMPRIORITY_INVALID = 0,
147 /** High.
148 * When ballooning, ask these VMs last.
149 * When running out of memory, try not to interrupt these VMs. */
150 GMMPRIORITY_HIGH,
151 /** Normal.
152 * When ballooning, don't wait to ask these.
153 * When running out of memory, pause, save and/or kill these VMs. */
154 GMMPRIORITY_NORMAL,
155 /** Low.
156 * When ballooning, maximize these first.
157 * When running out of memory, save or kill these VMs. */
158 GMMPRIORITY_LOW,
159 /** The end of the valid priority range. */
160 GMMPRIORITY_END,
161 /** The custom 32-bit type blowup. */
162 GMMPRIORITY_32BIT_HACK = 0x7fffffff
163} GMMPRIORITY;
164
165
166/**
167 * GMM Memory Accounts.
168 */
169typedef enum GMMACCOUNT
170{
171 /** The customary invalid zero entry. */
172 GMMACCOUNT_INVALID = 0,
173 /** Account with the base allocations. */
174 GMMACCOUNT_BASE,
175 /** Account with the shadow allocations. */
176 GMMACCOUNT_SHADOW,
177 /** Account with the fixed allocations. */
178 GMMACCOUNT_FIXED,
179 /** The end of the valid values. */
180 GMMACCOUNT_END,
181 /** The usual 32-bit value to finish it off. */
182 GMMACCOUNT_32BIT_HACK = 0x7fffffff
183} GMMACCOUNT;
184
185
186/**
187 * Balloon actions.
188 */
189typedef enum
190{
191 /** Invalid zero entry. */
192 GMMBALLOONACTION_INVALID = 0,
193 /** Inflate the balloon. */
194 GMMBALLOONACTION_INFLATE,
195 /** Deflate the balloon. */
196 GMMBALLOONACTION_DEFLATE,
197 /** Puncture the balloon because of VM reset. */
198 GMMBALLOONACTION_RESET,
199 /** End of the valid actions. */
200 GMMBALLOONACTION_END,
201 /** hack forcing the size of the enum to 32-bits. */
202 GMMBALLOONACTION_MAKE_32BIT_HACK = 0x7fffffff
203} GMMBALLOONACTION;
204
205
206/**
207 * A page descriptor for use when freeing pages.
208 * See GMMR0FreePages, GMMR0BalloonedPages.
209 */
210typedef struct GMMFREEPAGEDESC
211{
212 /** The Page ID of the page to be freed. */
213 uint32_t idPage;
214} GMMFREEPAGEDESC;
215/** Pointer to a page descriptor for freeing pages. */
216typedef GMMFREEPAGEDESC *PGMMFREEPAGEDESC;
217
218
219/**
220 * A page descriptor for use when updating and allocating pages.
221 *
222 * This is a bit complicated because we want to do as much as possible
223 * with the same structure.
224 */
225typedef struct GMMPAGEDESC
226{
227 /** The physical address of the page.
228 *
229 * @input GMMR0AllocateHandyPages expects the guest physical address
230 * to update the GMMPAGE structure with. Pass GMM_GCPHYS_UNSHAREABLE
231 * when appropriate and NIL_RTHCPHYS when the page wasn't used
232 * for any specific guest address.
233 *
234 * GMMR0AllocatePage expects the guest physical address to put in
235 * the GMMPAGE structure for the page it allocates for this entry.
236 * Pass NIL_RTHCPHYS and GMM_GCPHYS_UNSHAREABLE as above.
237 *
238 * @output The host physical address of the allocated page.
239 * NIL_RTHCPHYS on allocation failure.
240 *
241 * ASSUMES: sizeof(RTHCPHYS) >= sizeof(RTGCPHYS).
242 */
243 RTHCPHYS HCPhysGCPhys;
244
245 /** The Page ID.
246 *
247 * @intput GMMR0AllocateHandyPages expects the Page ID of the page to
248 * update here. NIL_GMM_PAGEID means no page should be updated.
249 *
250 * GMMR0AllocatePages requires this to be initialized to
251 * NIL_GMM_PAGEID currently.
252 *
253 * @output The ID of the page, NIL_GMM_PAGEID if the allocation failed.
254 */
255 uint32_t idPage;
256
257 /** The Page ID of the shared page was replaced by this page.
258 *
259 * @input GMMR0AllocateHandyPages expects this to indicate a shared
260 * page that has been replaced by this page and should have its
261 * reference counter decremented and perhaps be freed up. Use
262 * NIL_GMM_PAGEID if no shared page was involved.
263 *
264 * All other APIs expects NIL_GMM_PAGEID here.
265 *
266 * @output All APIs sets this to NIL_GMM_PAGEID.
267 */
268 uint32_t idSharedPage;
269} GMMPAGEDESC;
270AssertCompileSize(GMMPAGEDESC, 16);
271/** Pointer to a page allocation. */
272typedef GMMPAGEDESC *PGMMPAGEDESC;
273
274/** GMMPAGEDESC::HCPhysGCPhys value that indicates that the page is unsharable.
275 * @note This corresponds to GMM_PAGE_PFN_UNSHAREABLE. */
276#if HC_ARCH_BITS == 64
277# define GMM_GCPHYS_UNSHAREABLE UINT64_C(0x00000fffffff1000)
278#else
279# define GMM_GCPHYS_UNSHAREABLE UINT64_C(0x0000000fffff1000)
280#endif
281
282
283/**
284 * The allocation sizes.
285 */
286typedef struct GMMVMSIZES
287{
288 /** The number of pages of base memory.
289 * This is the sum of RAM, ROMs and handy pages. */
290 uint64_t cBasePages;
291 /** The number of pages for the shadow pool. (Can be squeezed for memory.) */
292 uint32_t cShadowPages;
293 /** The number of pages for fixed allocations like MMIO2 and the hyper heap. */
294 uint32_t cFixedPages;
295} GMMVMSIZES;
296/** Pointer to a GMMVMSIZES. */
297typedef GMMVMSIZES *PGMMVMSIZES;
298
299
300/**
301 * GMM VM statistics.
302 */
303typedef struct GMMVMSTATS
304{
305 /** The reservations. */
306 GMMVMSIZES Reserved;
307 /** The actual allocations.
308 * This includes both private and shared page allocations. */
309 GMMVMSIZES Allocated;
310
311 /** The current number of private pages. */
312 uint64_t cPrivatePages;
313 /** The current number of shared pages. */
314 uint64_t cSharedPages;
315 /** The current number of ballooned pages. */
316 uint64_t cBalloonedPages;
317 /** The max number of pages that can be ballooned. */
318 uint64_t cMaxBalloonedPages;
319 /** The number of pages we've currently requested the guest to give us.
320 * This is 0 if no pages currently requested. */
321 uint64_t cReqBalloonedPages;
322 /** The number of pages the guest has given us in response to the request.
323 * This is not reset on request completed and may be used in later decisions. */
324 uint64_t cReqActuallyBalloonedPages;
325 /** The number of pages we've currently requested the guest to take back. */
326 uint64_t cReqDeflatePages;
327 /** The number of shareable module tracked by this VM. */
328 uint32_t cShareableModules;
329
330 /** The current over-commitment policy. */
331 GMMOCPOLICY enmPolicy;
332 /** The VM priority for arbitrating VMs in low and out of memory situation.
333 * Like which VMs to start squeezing first. */
334 GMMPRIORITY enmPriority;
335 /** Whether ballooning is enabled or not. */
336 bool fBallooningEnabled;
337 /** Whether shared paging is enabled or not. */
338 bool fSharedPagingEnabled;
339 /** Whether the VM is allowed to allocate memory or not.
340 * This is used when the reservation update request fails or when the VM has
341 * been told to suspend/save/die in an out-of-memory case. */
342 bool fMayAllocate;
343 /** Explicit alignment. */
344 bool afReserved[1];
345
346
347} GMMVMSTATS;
348
349
350/**
351 * The GMM statistics.
352 */
353typedef struct GMMSTATS
354{
355 /** The maximum number of pages we're allowed to allocate
356 * (GMM::cMaxPages). */
357 uint64_t cMaxPages;
358 /** The number of pages that has been reserved (GMM::cReservedPages). */
359 uint64_t cReservedPages;
360 /** The number of pages that we have over-committed in reservations
361 * (GMM::cOverCommittedPages). */
362 uint64_t cOverCommittedPages;
363 /** The number of actually allocated (committed if you like) pages
364 * (GMM::cAllocatedPages). */
365 uint64_t cAllocatedPages;
366 /** The number of pages that are shared. A subset of cAllocatedPages.
367 * (GMM::cSharedPages) */
368 uint64_t cSharedPages;
369 /** The number of pages that are actually shared between VMs.
370 * (GMM:cDuplicatePages) */
371 uint64_t cDuplicatePages;
372 /** The number of pages that are shared that has been left behind by
373 * VMs not doing proper cleanups (GMM::cLeftBehindSharedPages). */
374 uint64_t cLeftBehindSharedPages;
375 /** The number of current ballooned pages (GMM::cBalloonedPages). */
376 uint64_t cBalloonedPages;
377 /** The number of allocation chunks (GMM::cChunks). */
378 uint32_t cChunks;
379 /** The number of freed chunks ever (GMM::cFreedChunks). */
380 uint32_t cFreedChunks;
381 /** The number of shareable modules (GMM:cShareableModules). */
382 uint64_t cShareableModules;
383 /** Space reserved for later. */
384 uint64_t au64Reserved[2];
385
386 /** Statistics for the specified VM. (Zero filled if not requested.) */
387 GMMVMSTATS VMStats;
388} GMMSTATS;
389/** Pointer to the GMM statistics. */
390typedef GMMSTATS *PGMMSTATS;
391/** Const pointer to the GMM statistics. */
392typedef const GMMSTATS *PCGMMSTATS;
393
394
395GMMR0DECL(int) GMMR0Init(void);
396GMMR0DECL(void) GMMR0Term(void);
397GMMR0DECL(void) GMMR0InitPerVMData(PGVM pGVM);
398GMMR0DECL(void) GMMR0CleanupVM(PGVM pGVM);
399GMMR0DECL(int) GMMR0InitialReservation(PVM pVM, VMCPUID idCpu, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
400 GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
401GMMR0DECL(int) GMMR0UpdateReservation(PVM pVM, VMCPUID idCpu, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
402GMMR0DECL(int) GMMR0AllocateHandyPages(PVM pVM, VMCPUID idCpu, uint32_t cPagesToUpdate, uint32_t cPagesToAlloc, PGMMPAGEDESC paPages);
403GMMR0DECL(int) GMMR0AllocatePages(PVM pVM, VMCPUID idCpu, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount);
404GMMR0DECL(int) GMMR0AllocateLargePage(PVM pVM, VMCPUID idCpu, uint32_t cbPage, uint32_t *pIdPage, RTHCPHYS *pHCPhys);
405GMMR0DECL(int) GMMR0FreePages(PVM pVM, VMCPUID idCpu, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount);
406GMMR0DECL(int) GMMR0FreeLargePage(PVM pVM, VMCPUID idCpu, uint32_t idPage);
407GMMR0DECL(int) GMMR0BalloonedPages(PVM pVM, VMCPUID idCpu, GMMBALLOONACTION enmAction, uint32_t cBalloonedPages);
408GMMR0DECL(int) GMMR0MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
409GMMR0DECL(int) GMMR0SeedChunk(PVM pVM, VMCPUID idCpu, RTR3PTR pvR3);
410GMMR0DECL(int) GMMR0RegisterSharedModule(PVM pVM, VMCPUID idCpu, VBOXOSFAMILY enmGuestOS, char *pszModuleName, char *pszVersion,
411 RTGCPTR GCBaseAddr, uint32_t cbModule, uint32_t cRegions,
412 struct VMMDEVSHAREDREGIONDESC *pRegions);
413GMMR0DECL(int) GMMR0UnregisterSharedModule(PVM pVM, VMCPUID idCpu, char *pszModuleName, char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule);
414GMMR0DECL(int) GMMR0UnregisterAllSharedModules(PVM pVM, VMCPUID idCpu);
415GMMR0DECL(int) GMMR0CheckSharedModules(PVM pVM, PVMCPU pVCpu);
416GMMR0DECL(int) GMMR0ResetSharedModules(PVM pVM, VMCPUID idCpu);
417GMMR0DECL(int) GMMR0CheckSharedModulesStart(PVM pVM);
418GMMR0DECL(int) GMMR0CheckSharedModulesEnd(PVM pVM);
419GMMR0DECL(int) GMMR0QueryStatistics(PGMMSTATS pStats, PSUPDRVSESSION pSession);
420GMMR0DECL(int) GMMR0ResetStatistics(PCGMMSTATS pStats, PSUPDRVSESSION pSession);
421
422/**
423 * Request buffer for GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION.
424 * @see GMMR0InitialReservation
425 */
426typedef struct GMMINITIALRESERVATIONREQ
427{
428 /** The header. */
429 SUPVMMR0REQHDR Hdr;
430 uint64_t cBasePages; /**< @see GMMR0InitialReservation */
431 uint32_t cShadowPages; /**< @see GMMR0InitialReservation */
432 uint32_t cFixedPages; /**< @see GMMR0InitialReservation */
433 GMMOCPOLICY enmPolicy; /**< @see GMMR0InitialReservation */
434 GMMPRIORITY enmPriority; /**< @see GMMR0InitialReservation */
435} GMMINITIALRESERVATIONREQ;
436/** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */
437typedef GMMINITIALRESERVATIONREQ *PGMMINITIALRESERVATIONREQ;
438
439GMMR0DECL(int) GMMR0InitialReservationReq(PVM pVM, VMCPUID idCpu, PGMMINITIALRESERVATIONREQ pReq);
440
441
442/**
443 * Request buffer for GMMR0UpdateReservationReq / VMMR0_DO_GMM_UPDATE_RESERVATION.
444 * @see GMMR0UpdateReservation
445 */
446typedef struct GMMUPDATERESERVATIONREQ
447{
448 /** The header. */
449 SUPVMMR0REQHDR Hdr;
450 uint64_t cBasePages; /**< @see GMMR0UpdateReservation */
451 uint32_t cShadowPages; /**< @see GMMR0UpdateReservation */
452 uint32_t cFixedPages; /**< @see GMMR0UpdateReservation */
453} GMMUPDATERESERVATIONREQ;
454/** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */
455typedef GMMUPDATERESERVATIONREQ *PGMMUPDATERESERVATIONREQ;
456
457GMMR0DECL(int) GMMR0UpdateReservationReq(PVM pVM, VMCPUID idCpu, PGMMUPDATERESERVATIONREQ pReq);
458
459
460/**
461 * Request buffer for GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES.
462 * @see GMMR0AllocatePages.
463 */
464typedef struct GMMALLOCATEPAGESREQ
465{
466 /** The header. */
467 SUPVMMR0REQHDR Hdr;
468 /** The account to charge the allocation to. */
469 GMMACCOUNT enmAccount;
470 /** The number of pages to allocate. */
471 uint32_t cPages;
472 /** Array of page descriptors. */
473 GMMPAGEDESC aPages[1];
474} GMMALLOCATEPAGESREQ;
475/** Pointer to a GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES request buffer. */
476typedef GMMALLOCATEPAGESREQ *PGMMALLOCATEPAGESREQ;
477
478GMMR0DECL(int) GMMR0AllocatePagesReq(PVM pVM, VMCPUID idCpu, PGMMALLOCATEPAGESREQ pReq);
479
480
481/**
482 * Request buffer for GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES.
483 * @see GMMR0FreePages.
484 */
485typedef struct GMMFREEPAGESREQ
486{
487 /** The header. */
488 SUPVMMR0REQHDR Hdr;
489 /** The account this relates to. */
490 GMMACCOUNT enmAccount;
491 /** The number of pages to free. */
492 uint32_t cPages;
493 /** Array of free page descriptors. */
494 GMMFREEPAGEDESC aPages[1];
495} GMMFREEPAGESREQ;
496/** Pointer to a GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES request buffer. */
497typedef GMMFREEPAGESREQ *PGMMFREEPAGESREQ;
498
499GMMR0DECL(int) GMMR0FreePagesReq(PVM pVM, VMCPUID idCpu, PGMMFREEPAGESREQ pReq);
500
501/**
502 * Request buffer for GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES.
503 * @see GMMR0BalloonedPages.
504 */
505typedef struct GMMBALLOONEDPAGESREQ
506{
507 /** The header. */
508 SUPVMMR0REQHDR Hdr;
509 /** The number of ballooned pages. */
510 uint32_t cBalloonedPages;
511 /** Inflate or deflate the balloon. */
512 GMMBALLOONACTION enmAction;
513} GMMBALLOONEDPAGESREQ;
514/** Pointer to a GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES request buffer. */
515typedef GMMBALLOONEDPAGESREQ *PGMMBALLOONEDPAGESREQ;
516
517GMMR0DECL(int) GMMR0BalloonedPagesReq(PVM pVM, VMCPUID idCpu, PGMMBALLOONEDPAGESREQ pReq);
518
519
520/**
521 * Request buffer for GMMR0QueryHypervisorMemoryStatsReq / VMMR0_DO_GMM_QUERY_VMM_MEM_STATS.
522 * @see GMMR0QueryHypervisorMemoryStatsReq.
523 */
524typedef struct GMMMEMSTATSREQ
525{
526 /** The header. */
527 SUPVMMR0REQHDR Hdr;
528 /** The number of allocated pages (out). */
529 uint64_t cAllocPages;
530 /** The number of free pages (out). */
531 uint64_t cFreePages;
532 /** The number of ballooned pages (out). */
533 uint64_t cBalloonedPages;
534 /** The number of shared pages (out). */
535 uint64_t cSharedPages;
536 /** Maximum nr of pages (out). */
537 uint64_t cMaxPages;
538} GMMMEMSTATSREQ;
539/** Pointer to a GMMR0QueryHypervisorMemoryStatsReq / VMMR0_DO_GMM_QUERY_HYPERVISOR_MEM_STATS request buffer. */
540typedef GMMMEMSTATSREQ *PGMMMEMSTATSREQ;
541
542GMMR0DECL(int) GMMR0QueryHypervisorMemoryStatsReq(PVM pVM, PGMMMEMSTATSREQ pReq);
543GMMR0DECL(int) GMMR0QueryMemoryStatsReq(PVM pVM, VMCPUID idCpu, PGMMMEMSTATSREQ pReq);
544
545/**
546 * Request buffer for GMMR0MapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK.
547 * @see GMMR0MapUnmapChunk
548 */
549typedef struct GMMMAPUNMAPCHUNKREQ
550{
551 /** The header. */
552 SUPVMMR0REQHDR Hdr;
553 /** The chunk to map, NIL_GMM_CHUNKID if unmap only. (IN) */
554 uint32_t idChunkMap;
555 /** The chunk to unmap, NIL_GMM_CHUNKID if map only. (IN) */
556 uint32_t idChunkUnmap;
557 /** Where the mapping address is returned. (OUT) */
558 RTR3PTR pvR3;
559} GMMMAPUNMAPCHUNKREQ;
560/** Pointer to a GMMR0MapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK request buffer. */
561typedef GMMMAPUNMAPCHUNKREQ *PGMMMAPUNMAPCHUNKREQ;
562
563GMMR0DECL(int) GMMR0MapUnmapChunkReq(PVM pVM, PGMMMAPUNMAPCHUNKREQ pReq);
564
565
566/**
567 * Request buffer for GMMR0FreeLargePageReq / VMMR0_DO_GMM_FREE_LARGE_PAGE.
568 * @see GMMR0FreeLargePage.
569 */
570typedef struct GMMFREELARGEPAGEREQ
571{
572 /** The header. */
573 SUPVMMR0REQHDR Hdr;
574 /** The Page ID. */
575 uint32_t idPage;
576} GMMFREELARGEPAGEREQ;
577/** Pointer to a GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES request buffer. */
578typedef GMMFREELARGEPAGEREQ *PGMMFREELARGEPAGEREQ;
579
580GMMR0DECL(int) GMMR0FreeLargePageReq(PVM pVM, VMCPUID idCpu, PGMMFREELARGEPAGEREQ pReq);
581
582/** Maximum length of the shared module name string. */
583#define GMM_SHARED_MODULE_MAX_NAME_STRING 128
584/** Maximum length of the shared module version string. */
585#define GMM_SHARED_MODULE_MAX_VERSION_STRING 16
586
587/**
588 * Request buffer for GMMR0RegisterSharedModuleReq / VMMR0_DO_GMM_REGISTER_SHARED_MODULE.
589 * @see GMMR0RegisterSharedModule.
590 */
591typedef struct GMMREGISTERSHAREDMODULEREQ
592{
593 /** The header. */
594 SUPVMMR0REQHDR Hdr;
595 /** Shared module size. */
596 uint32_t cbModule;
597 /** Number of included region descriptors */
598 uint32_t cRegions;
599 /** Base address of the shared module. */
600 RTGCPTR64 GCBaseAddr;
601 /** Guest OS type. */
602 VBOXOSFAMILY enmGuestOS;
603 /** return code. */
604 uint32_t rc;
605 /** Module name */
606 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
607 /** Module version */
608 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
609 /** Shared region descriptor(s). */
610 VMMDEVSHAREDREGIONDESC aRegions[1];
611} GMMREGISTERSHAREDMODULEREQ;
612/** Pointer to a GMMR0RegisterSharedModuleReq / VMMR0_DO_GMM_REGISTER_SHARED_MODULE request buffer. */
613typedef GMMREGISTERSHAREDMODULEREQ *PGMMREGISTERSHAREDMODULEREQ;
614
615GMMR0DECL(int) GMMR0RegisterSharedModuleReq(PVM pVM, VMCPUID idCpu, PGMMREGISTERSHAREDMODULEREQ pReq);
616
617/**
618 * Shared region descriptor
619 */
620typedef struct GMMSHAREDREGIONDESC
621{
622 /** Region base address. */
623 RTGCPTR64 GCRegionAddr;
624 /** Region size. */
625 uint32_t cbRegion;
626 /** Alignment. */
627 uint32_t u32Alignment;
628 /** Pointer to physical GMM page ID array. */
629 uint32_t *paidPages;
630} GMMSHAREDREGIONDESC;
631/** Pointer to a GMMSHAREDREGIONDESC. */
632typedef GMMSHAREDREGIONDESC *PGMMSHAREDREGIONDESC;
633
634
635/**
636 * Shared module registration info (global)
637 */
638typedef struct GMMSHAREDMODULE
639{
640 /** Tree node. */
641 AVLGCPTRNODECORE Core;
642 /** Shared module size. */
643 uint32_t cbModule;
644 /** Number of included region descriptors */
645 uint32_t cRegions;
646 /** Number of users (VMs). */
647 uint32_t cUsers;
648 /** Guest OS family type. */
649 VBOXOSFAMILY enmGuestOS;
650 /** Module name */
651 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
652 /** Module version */
653 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
654 /** Shared region descriptor(s). */
655 GMMSHAREDREGIONDESC aRegions[1];
656} GMMSHAREDMODULE;
657/** Pointer to a GMMSHAREDMODULE. */
658typedef GMMSHAREDMODULE *PGMMSHAREDMODULE;
659
660/**
661 * Page descriptor for GMMR0SharedModuleCheckRange
662 */
663typedef struct GMMSHAREDPAGEDESC
664{
665 /** HC Physical address (in/out) */
666 RTHCPHYS HCPhys;
667 /** GC Physical address (in) */
668 RTGCPHYS GCPhys;
669 /** GMM page id. (in/out) */
670 uint32_t idPage;
671 /** Align at 8 byte boundary. */
672 uint32_t uAlignment;
673} GMMSHAREDPAGEDESC;
674/** Pointer to a GMMSHAREDPAGEDESC. */
675typedef GMMSHAREDPAGEDESC *PGMMSHAREDPAGEDESC;
676
677GMMR0DECL(int) GMMR0SharedModuleCheckPage(PGVM pGVM, PGMMSHAREDMODULE pModule, unsigned idxRegion, unsigned idxPage,
678 PGMMSHAREDPAGEDESC pPageDesc);
679
680/**
681 * Request buffer for GMMR0UnregisterSharedModuleReq / VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE.
682 * @see GMMR0UnregisterSharedModule.
683 */
684typedef struct GMMUNREGISTERSHAREDMODULEREQ
685{
686 /** The header. */
687 SUPVMMR0REQHDR Hdr;
688 /** Shared module size. */
689 uint32_t cbModule;
690 /** Align at 8 byte boundary. */
691 uint32_t u32Alignment;
692 /** Base address of the shared module. */
693 RTGCPTR64 GCBaseAddr;
694 /** Module name */
695 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
696 /** Module version */
697 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
698} GMMUNREGISTERSHAREDMODULEREQ;
699/** Pointer to a GMMR0UnregisterSharedModuleReq / VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE request buffer. */
700typedef GMMUNREGISTERSHAREDMODULEREQ *PGMMUNREGISTERSHAREDMODULEREQ;
701
702GMMR0DECL(int) GMMR0UnregisterSharedModuleReq(PVM pVM, VMCPUID idCpu, PGMMUNREGISTERSHAREDMODULEREQ pReq);
703
704#if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
705/**
706 * Request buffer for GMMR0FindDuplicatePageReq / VMMR0_DO_GMM_FIND_DUPLICATE_PAGE.
707 * @see GMMR0FindDuplicatePage.
708 */
709typedef struct GMMFINDDUPLICATEPAGEREQ
710{
711 /** The header. */
712 SUPVMMR0REQHDR Hdr;
713 /** Page id. */
714 uint32_t idPage;
715 /** Duplicate flag (out) */
716 bool fDuplicate;
717} GMMFINDDUPLICATEPAGEREQ;
718/** Pointer to a GMMR0FindDuplicatePageReq / VMMR0_DO_GMM_FIND_DUPLICATE_PAGE request buffer. */
719typedef GMMFINDDUPLICATEPAGEREQ *PGMMFINDDUPLICATEPAGEREQ;
720
721GMMR0DECL(int) GMMR0FindDuplicatePageReq(PVM pVM, PGMMFINDDUPLICATEPAGEREQ pReq);
722#endif /* VBOX_STRICT && HC_ARCH_BITS == 64 */
723
724
725/**
726 * Request buffer for GMMR0QueryStatisticsReq / VMMR0_DO_GMM_QUERY_STATISTICS.
727 * @see GMMR0QueryStatistics.
728 */
729typedef struct GMMQUERYSTATISTICSSREQ
730{
731 /** The header. */
732 SUPVMMR0REQHDR Hdr;
733 /** The support driver session. */
734 PSUPDRVSESSION pSession;
735 /** The statistics. */
736 GMMSTATS Stats;
737} GMMQUERYSTATISTICSSREQ;
738/** Pointer to a GMMR0QueryStatisticsReq / VMMR0_DO_GMM_QUERY_STATISTICS
739 * request buffer. */
740typedef GMMQUERYSTATISTICSSREQ *PGMMQUERYSTATISTICSSREQ;
741
742GMMR0DECL(int) GMMR0QueryStatisticsReq(PVM pVM, PGMMQUERYSTATISTICSSREQ pReq);
743
744
745/**
746 * Request buffer for GMMR0ResetStatisticsReq / VMMR0_DO_GMM_RESET_STATISTICS.
747 * @see GMMR0ResetStatistics.
748 */
749typedef struct GMMRESETSTATISTICSSREQ
750{
751 /** The header. */
752 SUPVMMR0REQHDR Hdr;
753 /** The support driver session. */
754 PSUPDRVSESSION pSession;
755 /** The statistics to reset.
756 * Any non-zero entry will be reset (if permitted). */
757 GMMSTATS Stats;
758} GMMRESETSTATISTICSSREQ;
759/** Pointer to a GMMR0ResetStatisticsReq / VMMR0_DO_GMM_RESET_STATISTICS
760 * request buffer. */
761typedef GMMRESETSTATISTICSSREQ *PGMMRESETSTATISTICSSREQ;
762
763GMMR0DECL(int) GMMR0ResetStatisticsReq(PVM pVM, PGMMRESETSTATISTICSSREQ pReq);
764
765
766
767#ifdef IN_RING3
768/** @defgroup grp_gmm_r3 The Global Memory Manager Ring-3 API Wrappers
769 * @ingroup grp_gmm
770 * @{
771 */
772GMMR3DECL(int) GMMR3InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
773 GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
774GMMR3DECL(int) GMMR3UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
775GMMR3DECL(int) GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
776GMMR3DECL(int) GMMR3AllocatePagesPerform(PVM pVM, PGMMALLOCATEPAGESREQ pReq);
777GMMR3DECL(void) GMMR3AllocatePagesCleanup(PGMMALLOCATEPAGESREQ pReq);
778GMMR3DECL(int) GMMR3FreePagesPrepare(PVM pVM, PGMMFREEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
779GMMR3DECL(void) GMMR3FreePagesRePrep(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t cPages, GMMACCOUNT enmAccount);
780GMMR3DECL(int) GMMR3FreePagesPerform(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t cActualPages);
781GMMR3DECL(void) GMMR3FreePagesCleanup(PGMMFREEPAGESREQ pReq);
782GMMR3DECL(void) GMMR3FreeAllocatedPages(PVM pVM, GMMALLOCATEPAGESREQ const *pAllocReq);
783GMMR3DECL(int) GMMR3AllocateLargePage(PVM pVM, uint32_t cbPage);
784GMMR3DECL(int) GMMR3FreeLargePage(PVM pVM, uint32_t idPage);
785GMMR3DECL(int) GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
786GMMR3DECL(int) GMMR3SeedChunk(PVM pVM, RTR3PTR pvR3);
787GMMR3DECL(int) GMMR3QueryHypervisorMemoryStats(PVM pVM, uint64_t *pcTotalAllocPages, uint64_t *pcTotalFreePages, uint64_t *pcTotalBalloonPages, uint64_t *puTotalBalloonSize);
788GMMR3DECL(int) GMMR3QueryMemoryStats(PVM pVM, uint64_t *pcAllocPages, uint64_t *pcMaxPages, uint64_t *pcBalloonPages);
789GMMR3DECL(int) GMMR3BalloonedPages(PVM pVM, GMMBALLOONACTION enmAction, uint32_t cBalloonedPages);
790GMMR3DECL(int) GMMR3RegisterSharedModule(PVM pVM, PGMMREGISTERSHAREDMODULEREQ pReq);
791GMMR3DECL(int) GMMR3UnregisterSharedModule(PVM pVM, PGMMUNREGISTERSHAREDMODULEREQ pReq);
792GMMR3DECL(int) GMMR3CheckSharedModules(PVM pVM);
793GMMR3DECL(int) GMMR3ResetSharedModules(PVM pVM);
794
795# if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
796GMMR3DECL(bool) GMMR3IsDuplicatePage(PVM pVM, uint32_t idPage);
797# endif
798
799/** @} */
800#endif /* IN_RING3 */
801
802/** @} */
803
804RT_C_DECLS_END
805
806#endif
807
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette