VirtualBox

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

Last change on this file since 67990 was 62476, checked in by vboxsync, 8 years ago

(C) 2016

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