VirtualBox

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

最後變更 在這個檔案從92326是 92326,由 vboxsync 提交於 3 年 前

VMM/GMM,PGM: Optimize zeroing of RAM allocations by not doing it again if the OS already zeroed an allocation. bugref:10093

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 30.4 KB
 
1/** @file
2 * GMM - The Global Memory Manager.
3 */
4
5/*
6 * Copyright (C) 2007-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.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_INCLUDED_vmm_gmm_h
27#define VBOX_INCLUDED_vmm_gmm_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/vmm/gvmm.h>
33#include <VBox/sup.h>
34#include <VBox/param.h>
35#include <VBox/ostypes.h>
36#include <iprt/avl.h>
37
38
39RT_C_DECLS_BEGIN
40
41/** @defgroup grp_gmm GMM - The Global Memory Manager
42 * @ingroup grp_vmm
43 * @{
44 */
45
46/** @def IN_GMM_R0
47 * Used to indicate whether we're inside the same link module as the ring 0
48 * part of the Global Memory Manager or not.
49 */
50#ifdef DOXYGEN_RUNNING
51# define IN_GMM_R0
52#endif
53/** @def GMMR0DECL
54 * Ring 0 GMM export or import declaration.
55 * @param type The return type of the function declaration.
56 */
57#ifdef IN_GMM_R0
58# define GMMR0DECL(type) DECLEXPORT(type) VBOXCALL
59#else
60# define GMMR0DECL(type) DECLIMPORT(type) VBOXCALL
61#endif
62
63/** @def IN_GMM_R3
64 * Used to indicate whether we're inside the same link module as the ring 3
65 * part of the Global Memory Manager or not.
66 */
67#ifdef DOXYGEN_RUNNING
68# define IN_GMM_R3
69#endif
70/** @def GMMR3DECL
71 * Ring 3 GMM export or import declaration.
72 * @param type The return type of the function declaration.
73 */
74#ifdef IN_GMM_R3
75# define GMMR3DECL(type) DECLEXPORT(type) VBOXCALL
76#else
77# define GMMR3DECL(type) DECLIMPORT(type) VBOXCALL
78#endif
79
80
81/** The chunk shift. (2^21 = 2 MB) */
82#define GMM_CHUNK_SHIFT 21
83/** The allocation chunk size. */
84#define GMM_CHUNK_SIZE (1U << GMM_CHUNK_SHIFT)
85/** The allocation chunk size in pages. */
86#define GMM_CHUNK_NUM_PAGES (1U << (GMM_CHUNK_SHIFT - PAGE_SHIFT))
87/** The shift factor for converting a page id into a chunk id. */
88#define GMM_CHUNKID_SHIFT (GMM_CHUNK_SHIFT - PAGE_SHIFT)
89/** The last valid Chunk ID value. */
90#define GMM_CHUNKID_LAST (GMM_PAGEID_LAST >> GMM_CHUNKID_SHIFT)
91/** The last valid Page ID value. */
92#define GMM_PAGEID_LAST UINT32_C(0xfffffff0)
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_GMMPAGEDESC_PHYS 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_GMMPAGEDESC_PHYS and GMM_GCPHYS_UNSHAREABLE as above.
240 *
241 * @output The host physical address of the allocated page.
242 * NIL_GMMPAGEDESC_PHYS on allocation failure.
243 *
244 * ASSUMES: sizeof(RTHCPHYS) >= sizeof(RTGCPHYS) and that physical addresses are
245 * limited to 63 or fewer bits (52 by AMD64 arch spec).
246 */
247 RTHCPHYS HCPhysGCPhys : 63;
248 /** Set if the memory was zeroed. */
249 RTHCPHYS fZeroed : 1;
250
251 /** The Page ID.
252 *
253 * @input GMMR0AllocateHandyPages expects the Page ID of the page to
254 * update here. NIL_GMM_PAGEID means no page should be updated.
255 *
256 * GMMR0AllocatePages requires this to be initialized to
257 * NIL_GMM_PAGEID currently.
258 *
259 * @output The ID of the page, NIL_GMM_PAGEID if the allocation failed.
260 */
261 uint32_t idPage;
262
263 /** The Page ID of the shared page was replaced by this page.
264 *
265 * @input GMMR0AllocateHandyPages expects this to indicate a shared
266 * page that has been replaced by this page and should have its
267 * reference counter decremented and perhaps be freed up. Use
268 * NIL_GMM_PAGEID if no shared page was involved.
269 *
270 * All other APIs expects NIL_GMM_PAGEID here.
271 *
272 * @output All APIs sets this to NIL_GMM_PAGEID.
273 */
274 uint32_t idSharedPage;
275} GMMPAGEDESC;
276AssertCompileSize(GMMPAGEDESC, 16);
277/** Pointer to a page allocation. */
278typedef GMMPAGEDESC *PGMMPAGEDESC;
279
280/** Special NIL value for GMMPAGEDESC::HCPhysGCPhys. */
281#define NIL_GMMPAGEDESC_PHYS UINT64_C(0x7fffffffffffffff)
282
283/** GMMPAGEDESC::HCPhysGCPhys value that indicates that the page is unsharable.
284 * @note This corresponds to GMM_PAGE_PFN_UNSHAREABLE. */
285#if HC_ARCH_BITS == 64
286# define GMM_GCPHYS_UNSHAREABLE UINT64_C(0x00000fffffff1000)
287#else
288# define GMM_GCPHYS_UNSHAREABLE UINT64_C(0x0000000fffff1000)
289#endif
290
291
292/**
293 * The allocation sizes.
294 */
295typedef struct GMMVMSIZES
296{
297 /** The number of pages of base memory.
298 * This is the sum of RAM, ROMs and handy pages. */
299 uint64_t cBasePages;
300 /** The number of pages for the shadow pool. (Can be squeezed for memory.) */
301 uint32_t cShadowPages;
302 /** The number of pages for fixed allocations like MMIO2 and the hyper heap. */
303 uint32_t cFixedPages;
304} GMMVMSIZES;
305/** Pointer to a GMMVMSIZES. */
306typedef GMMVMSIZES *PGMMVMSIZES;
307
308
309/**
310 * GMM VM statistics.
311 */
312typedef struct GMMVMSTATS
313{
314 /** The reservations. */
315 GMMVMSIZES Reserved;
316 /** The actual allocations.
317 * This includes both private and shared page allocations. */
318 GMMVMSIZES Allocated;
319
320 /** The current number of private pages. */
321 uint64_t cPrivatePages;
322 /** The current number of shared pages. */
323 uint64_t cSharedPages;
324 /** The current number of ballooned pages. */
325 uint64_t cBalloonedPages;
326 /** The max number of pages that can be ballooned. */
327 uint64_t cMaxBalloonedPages;
328 /** The number of pages we've currently requested the guest to give us.
329 * This is 0 if no pages currently requested. */
330 uint64_t cReqBalloonedPages;
331 /** The number of pages the guest has given us in response to the request.
332 * This is not reset on request completed and may be used in later decisions. */
333 uint64_t cReqActuallyBalloonedPages;
334 /** The number of pages we've currently requested the guest to take back. */
335 uint64_t cReqDeflatePages;
336 /** The number of shareable module tracked by this VM. */
337 uint32_t cShareableModules;
338
339 /** The current over-commitment policy. */
340 GMMOCPOLICY enmPolicy;
341 /** The VM priority for arbitrating VMs in low and out of memory situation.
342 * Like which VMs to start squeezing first. */
343 GMMPRIORITY enmPriority;
344 /** Whether ballooning is enabled or not. */
345 bool fBallooningEnabled;
346 /** Whether shared paging is enabled or not. */
347 bool fSharedPagingEnabled;
348 /** Whether the VM is allowed to allocate memory or not.
349 * This is used when the reservation update request fails or when the VM has
350 * been told to suspend/save/die in an out-of-memory case. */
351 bool fMayAllocate;
352 /** Explicit alignment. */
353 bool afReserved[1];
354
355
356} GMMVMSTATS;
357
358
359/**
360 * The GMM statistics.
361 */
362typedef struct GMMSTATS
363{
364 /** The maximum number of pages we're allowed to allocate
365 * (GMM::cMaxPages). */
366 uint64_t cMaxPages;
367 /** The number of pages that has been reserved (GMM::cReservedPages). */
368 uint64_t cReservedPages;
369 /** The number of pages that we have over-committed in reservations
370 * (GMM::cOverCommittedPages). */
371 uint64_t cOverCommittedPages;
372 /** The number of actually allocated (committed if you like) pages
373 * (GMM::cAllocatedPages). */
374 uint64_t cAllocatedPages;
375 /** The number of pages that are shared. A subset of cAllocatedPages.
376 * (GMM::cSharedPages) */
377 uint64_t cSharedPages;
378 /** The number of pages that are actually shared between VMs.
379 * (GMM:cDuplicatePages) */
380 uint64_t cDuplicatePages;
381 /** The number of pages that are shared that has been left behind by
382 * VMs not doing proper cleanups (GMM::cLeftBehindSharedPages). */
383 uint64_t cLeftBehindSharedPages;
384 /** The number of current ballooned pages (GMM::cBalloonedPages). */
385 uint64_t cBalloonedPages;
386 /** The number of allocation chunks (GMM::cChunks). */
387 uint32_t cChunks;
388 /** The number of freed chunks ever (GMM::cFreedChunks). */
389 uint32_t cFreedChunks;
390 /** The number of shareable modules (GMM:cShareableModules). */
391 uint64_t cShareableModules;
392 /** The current chunk freeing generation use by the per-VM TLB validation (GMM::idFreeGeneration). */
393 uint64_t idFreeGeneration;
394 /** Space reserved for later. */
395 uint64_t au64Reserved[1];
396
397 /** Statistics for the specified VM. (Zero filled if not requested.) */
398 GMMVMSTATS VMStats;
399} GMMSTATS;
400/** Pointer to the GMM statistics. */
401typedef GMMSTATS *PGMMSTATS;
402/** Const pointer to the GMM statistics. */
403typedef const GMMSTATS *PCGMMSTATS;
404
405
406GMMR0DECL(int) GMMR0Init(void);
407GMMR0DECL(void) GMMR0Term(void);
408GMMR0DECL(int) GMMR0InitPerVMData(PGVM pGVM);
409GMMR0DECL(void) GMMR0CleanupVM(PGVM pGVM);
410GMMR0DECL(int) GMMR0InitialReservation(PGVM pGVM, VMCPUID idCpu, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
411 GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
412GMMR0DECL(int) GMMR0UpdateReservation(PGVM pGVM, VMCPUID idCpu, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
413GMMR0DECL(int) GMMR0AllocateHandyPages(PGVM pGVM, VMCPUID idCpu, uint32_t cPagesToUpdate,
414 uint32_t cPagesToAlloc, PGMMPAGEDESC paPages);
415GMMR0DECL(int) GMMR0AllocatePages(PGVM pGVM, VMCPUID idCpu, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount);
416GMMR0DECL(int) GMMR0AllocateLargePage(PGVM pGVM, VMCPUID idCpu, uint32_t cbPage, uint32_t *pIdPage, RTHCPHYS *pHCPhys);
417GMMR0DECL(int) GMMR0FreePages(PGVM pGVM, VMCPUID idCpu, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount);
418GMMR0DECL(int) GMMR0FreeLargePage(PGVM pGVM, VMCPUID idCpu, uint32_t idPage);
419GMMR0DECL(int) GMMR0BalloonedPages(PGVM pGVM, VMCPUID idCpu, GMMBALLOONACTION enmAction, uint32_t cBalloonedPages);
420GMMR0DECL(int) GMMR0MapUnmapChunk(PGVM pGVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
421GMMR0DECL(int) GMMR0PageIdToVirt(PGVM pGVM, uint32_t idPage, void **ppv);
422GMMR0DECL(int) GMMR0RegisterSharedModule(PGVM pGVM, VMCPUID idCpu, VBOXOSFAMILY enmGuestOS, char *pszModuleName,
423 char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule, uint32_t cRegions,
424 struct VMMDEVSHAREDREGIONDESC const *paRegions);
425GMMR0DECL(int) GMMR0UnregisterSharedModule(PGVM pGVM, VMCPUID idCpu, char *pszModuleName, char *pszVersion,
426 RTGCPTR GCBaseAddr, uint32_t cbModule);
427GMMR0DECL(int) GMMR0UnregisterAllSharedModules(PGVM pGVM, VMCPUID idCpu);
428GMMR0DECL(int) GMMR0CheckSharedModules(PGVM pGVM, VMCPUID idCpu);
429GMMR0DECL(int) GMMR0ResetSharedModules(PGVM pGVM, VMCPUID idCpu);
430GMMR0DECL(int) GMMR0QueryStatistics(PGMMSTATS pStats, PSUPDRVSESSION pSession);
431GMMR0DECL(int) GMMR0ResetStatistics(PCGMMSTATS pStats, PSUPDRVSESSION pSession);
432
433/**
434 * Request buffer for GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION.
435 * @see GMMR0InitialReservation
436 */
437typedef struct GMMINITIALRESERVATIONREQ
438{
439 /** The header. */
440 SUPVMMR0REQHDR Hdr;
441 uint64_t cBasePages; /**< @see GMMR0InitialReservation */
442 uint32_t cShadowPages; /**< @see GMMR0InitialReservation */
443 uint32_t cFixedPages; /**< @see GMMR0InitialReservation */
444 GMMOCPOLICY enmPolicy; /**< @see GMMR0InitialReservation */
445 GMMPRIORITY enmPriority; /**< @see GMMR0InitialReservation */
446} GMMINITIALRESERVATIONREQ;
447/** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */
448typedef GMMINITIALRESERVATIONREQ *PGMMINITIALRESERVATIONREQ;
449
450GMMR0DECL(int) GMMR0InitialReservationReq(PGVM pGVM, VMCPUID idCpu, PGMMINITIALRESERVATIONREQ pReq);
451
452
453/**
454 * Request buffer for GMMR0UpdateReservationReq / VMMR0_DO_GMM_UPDATE_RESERVATION.
455 * @see GMMR0UpdateReservation
456 */
457typedef struct GMMUPDATERESERVATIONREQ
458{
459 /** The header. */
460 SUPVMMR0REQHDR Hdr;
461 uint64_t cBasePages; /**< @see GMMR0UpdateReservation */
462 uint32_t cShadowPages; /**< @see GMMR0UpdateReservation */
463 uint32_t cFixedPages; /**< @see GMMR0UpdateReservation */
464} GMMUPDATERESERVATIONREQ;
465/** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */
466typedef GMMUPDATERESERVATIONREQ *PGMMUPDATERESERVATIONREQ;
467
468GMMR0DECL(int) GMMR0UpdateReservationReq(PGVM pGVM, VMCPUID idCpu, PGMMUPDATERESERVATIONREQ pReq);
469
470
471/**
472 * Request buffer for GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES.
473 * @see GMMR0AllocatePages.
474 */
475typedef struct GMMALLOCATEPAGESREQ
476{
477 /** The header. */
478 SUPVMMR0REQHDR Hdr;
479 /** The account to charge the allocation to. */
480 GMMACCOUNT enmAccount;
481 /** The number of pages to allocate. */
482 uint32_t cPages;
483 /** Array of page descriptors. */
484 GMMPAGEDESC aPages[1];
485} GMMALLOCATEPAGESREQ;
486/** Pointer to a GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES request buffer. */
487typedef GMMALLOCATEPAGESREQ *PGMMALLOCATEPAGESREQ;
488
489GMMR0DECL(int) GMMR0AllocatePagesReq(PGVM pGVM, VMCPUID idCpu, PGMMALLOCATEPAGESREQ pReq);
490
491
492/**
493 * Request buffer for GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES.
494 * @see GMMR0FreePages.
495 */
496typedef struct GMMFREEPAGESREQ
497{
498 /** The header. */
499 SUPVMMR0REQHDR Hdr;
500 /** The account this relates to. */
501 GMMACCOUNT enmAccount;
502 /** The number of pages to free. */
503 uint32_t cPages;
504 /** Array of free page descriptors. */
505 GMMFREEPAGEDESC aPages[1];
506} GMMFREEPAGESREQ;
507/** Pointer to a GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES request buffer. */
508typedef GMMFREEPAGESREQ *PGMMFREEPAGESREQ;
509
510GMMR0DECL(int) GMMR0FreePagesReq(PGVM pGVM, VMCPUID idCpu, PGMMFREEPAGESREQ pReq);
511
512/**
513 * Request buffer for GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES.
514 * @see GMMR0BalloonedPages.
515 */
516typedef struct GMMBALLOONEDPAGESREQ
517{
518 /** The header. */
519 SUPVMMR0REQHDR Hdr;
520 /** The number of ballooned pages. */
521 uint32_t cBalloonedPages;
522 /** Inflate or deflate the balloon. */
523 GMMBALLOONACTION enmAction;
524} GMMBALLOONEDPAGESREQ;
525/** Pointer to a GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES request buffer. */
526typedef GMMBALLOONEDPAGESREQ *PGMMBALLOONEDPAGESREQ;
527
528GMMR0DECL(int) GMMR0BalloonedPagesReq(PGVM pGVM, VMCPUID idCpu, PGMMBALLOONEDPAGESREQ pReq);
529
530
531/**
532 * Request buffer for GMMR0QueryHypervisorMemoryStatsReq / VMMR0_DO_GMM_QUERY_VMM_MEM_STATS.
533 * @see GMMR0QueryHypervisorMemoryStatsReq.
534 */
535typedef struct GMMMEMSTATSREQ
536{
537 /** The header. */
538 SUPVMMR0REQHDR Hdr;
539 /** The number of allocated pages (out). */
540 uint64_t cAllocPages;
541 /** The number of free pages (out). */
542 uint64_t cFreePages;
543 /** The number of ballooned pages (out). */
544 uint64_t cBalloonedPages;
545 /** The number of shared pages (out). */
546 uint64_t cSharedPages;
547 /** Maximum nr of pages (out). */
548 uint64_t cMaxPages;
549} GMMMEMSTATSREQ;
550/** Pointer to a GMMR0QueryHypervisorMemoryStatsReq / VMMR0_DO_GMM_QUERY_HYPERVISOR_MEM_STATS request buffer. */
551typedef GMMMEMSTATSREQ *PGMMMEMSTATSREQ;
552
553GMMR0DECL(int) GMMR0QueryHypervisorMemoryStatsReq(PGMMMEMSTATSREQ pReq);
554GMMR0DECL(int) GMMR0QueryMemoryStatsReq(PGVM pGVM, VMCPUID idCpu, PGMMMEMSTATSREQ pReq);
555
556/**
557 * Request buffer for GMMR0MapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK.
558 * @see GMMR0MapUnmapChunk
559 */
560typedef struct GMMMAPUNMAPCHUNKREQ
561{
562 /** The header. */
563 SUPVMMR0REQHDR Hdr;
564 /** The chunk to map, NIL_GMM_CHUNKID if unmap only. (IN) */
565 uint32_t idChunkMap;
566 /** The chunk to unmap, NIL_GMM_CHUNKID if map only. (IN) */
567 uint32_t idChunkUnmap;
568 /** Where the mapping address is returned. (OUT) */
569 RTR3PTR pvR3;
570} GMMMAPUNMAPCHUNKREQ;
571/** Pointer to a GMMR0MapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK request buffer. */
572typedef GMMMAPUNMAPCHUNKREQ *PGMMMAPUNMAPCHUNKREQ;
573
574GMMR0DECL(int) GMMR0MapUnmapChunkReq(PGVM pGVM, PGMMMAPUNMAPCHUNKREQ pReq);
575
576
577/**
578 * Request buffer for GMMR0FreeLargePageReq / VMMR0_DO_GMM_FREE_LARGE_PAGE.
579 * @see GMMR0FreeLargePage.
580 */
581typedef struct GMMFREELARGEPAGEREQ
582{
583 /** The header. */
584 SUPVMMR0REQHDR Hdr;
585 /** The Page ID. */
586 uint32_t idPage;
587} GMMFREELARGEPAGEREQ;
588/** Pointer to a GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES request buffer. */
589typedef GMMFREELARGEPAGEREQ *PGMMFREELARGEPAGEREQ;
590
591GMMR0DECL(int) GMMR0FreeLargePageReq(PGVM pGVM, VMCPUID idCpu, PGMMFREELARGEPAGEREQ pReq);
592
593/** Maximum length of the shared module name string, terminator included. */
594#define GMM_SHARED_MODULE_MAX_NAME_STRING 128
595/** Maximum length of the shared module version string, terminator included. */
596#define GMM_SHARED_MODULE_MAX_VERSION_STRING 16
597
598/**
599 * Request buffer for GMMR0RegisterSharedModuleReq / VMMR0_DO_GMM_REGISTER_SHARED_MODULE.
600 * @see GMMR0RegisterSharedModule.
601 */
602typedef struct GMMREGISTERSHAREDMODULEREQ
603{
604 /** The header. */
605 SUPVMMR0REQHDR Hdr;
606 /** Shared module size. */
607 uint32_t cbModule;
608 /** Number of included region descriptors */
609 uint32_t cRegions;
610 /** Base address of the shared module. */
611 RTGCPTR64 GCBaseAddr;
612 /** Guest OS type. */
613 VBOXOSFAMILY enmGuestOS;
614 /** return code. */
615 uint32_t rc;
616 /** Module name */
617 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
618 /** Module version */
619 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
620 /** Shared region descriptor(s). */
621 VMMDEVSHAREDREGIONDESC aRegions[1];
622} GMMREGISTERSHAREDMODULEREQ;
623/** Pointer to a GMMR0RegisterSharedModuleReq / VMMR0_DO_GMM_REGISTER_SHARED_MODULE request buffer. */
624typedef GMMREGISTERSHAREDMODULEREQ *PGMMREGISTERSHAREDMODULEREQ;
625
626GMMR0DECL(int) GMMR0RegisterSharedModuleReq(PGVM pGVM, VMCPUID idCpu, PGMMREGISTERSHAREDMODULEREQ pReq);
627
628/**
629 * Shared region descriptor
630 */
631typedef struct GMMSHAREDREGIONDESC
632{
633 /** The page offset where the region starts. */
634 uint32_t off;
635 /** Region size - adjusted by the region offset and rounded up to a
636 * page. */
637 uint32_t cb;
638 /** Pointer to physical GMM page ID array. */
639 uint32_t *paidPages;
640} GMMSHAREDREGIONDESC;
641/** Pointer to a GMMSHAREDREGIONDESC. */
642typedef GMMSHAREDREGIONDESC *PGMMSHAREDREGIONDESC;
643
644
645/**
646 * Shared module registration info (global)
647 */
648typedef struct GMMSHAREDMODULE
649{
650 /** Tree node (keyed by a hash of name & version). */
651 AVLLU32NODECORE Core;
652 /** Shared module size. */
653 uint32_t cbModule;
654 /** Number of included region descriptors */
655 uint32_t cRegions;
656 /** Number of users (VMs). */
657 uint32_t cUsers;
658 /** Guest OS family type. */
659 VBOXOSFAMILY enmGuestOS;
660 /** Module name */
661 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
662 /** Module version */
663 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
664 /** Shared region descriptor(s). */
665 GMMSHAREDREGIONDESC aRegions[1];
666} GMMSHAREDMODULE;
667/** Pointer to a GMMSHAREDMODULE. */
668typedef GMMSHAREDMODULE *PGMMSHAREDMODULE;
669
670/**
671 * Page descriptor for GMMR0SharedModuleCheckRange
672 */
673typedef struct GMMSHAREDPAGEDESC
674{
675 /** HC Physical address (in/out) */
676 RTHCPHYS HCPhys;
677 /** GC Physical address (in) */
678 RTGCPHYS GCPhys;
679 /** GMM page id. (in/out) */
680 uint32_t idPage;
681 /** CRC32 of the page in strict builds (0 if page not available).
682 * In non-strict build this serves as structure alignment. */
683 uint32_t u32StrictChecksum;
684} GMMSHAREDPAGEDESC;
685/** Pointer to a GMMSHAREDPAGEDESC. */
686typedef GMMSHAREDPAGEDESC *PGMMSHAREDPAGEDESC;
687
688GMMR0DECL(int) GMMR0SharedModuleCheckPage(PGVM pGVM, PGMMSHAREDMODULE pModule, uint32_t idxRegion, uint32_t idxPage,
689 PGMMSHAREDPAGEDESC pPageDesc);
690
691/**
692 * Request buffer for GMMR0UnregisterSharedModuleReq / VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE.
693 * @see GMMR0UnregisterSharedModule.
694 */
695typedef struct GMMUNREGISTERSHAREDMODULEREQ
696{
697 /** The header. */
698 SUPVMMR0REQHDR Hdr;
699 /** Shared module size. */
700 uint32_t cbModule;
701 /** Align at 8 byte boundary. */
702 uint32_t u32Alignment;
703 /** Base address of the shared module. */
704 RTGCPTR64 GCBaseAddr;
705 /** Module name */
706 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
707 /** Module version */
708 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
709} GMMUNREGISTERSHAREDMODULEREQ;
710/** Pointer to a GMMR0UnregisterSharedModuleReq / VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE request buffer. */
711typedef GMMUNREGISTERSHAREDMODULEREQ *PGMMUNREGISTERSHAREDMODULEREQ;
712
713GMMR0DECL(int) GMMR0UnregisterSharedModuleReq(PGVM pGVM, VMCPUID idCpu, PGMMUNREGISTERSHAREDMODULEREQ pReq);
714
715#if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
716/**
717 * Request buffer for GMMR0FindDuplicatePageReq / VMMR0_DO_GMM_FIND_DUPLICATE_PAGE.
718 * @see GMMR0FindDuplicatePage.
719 */
720typedef struct GMMFINDDUPLICATEPAGEREQ
721{
722 /** The header. */
723 SUPVMMR0REQHDR Hdr;
724 /** Page id. */
725 uint32_t idPage;
726 /** Duplicate flag (out) */
727 bool fDuplicate;
728} GMMFINDDUPLICATEPAGEREQ;
729/** Pointer to a GMMR0FindDuplicatePageReq / VMMR0_DO_GMM_FIND_DUPLICATE_PAGE request buffer. */
730typedef GMMFINDDUPLICATEPAGEREQ *PGMMFINDDUPLICATEPAGEREQ;
731
732GMMR0DECL(int) GMMR0FindDuplicatePageReq(PGVM pGVM, PGMMFINDDUPLICATEPAGEREQ pReq);
733#endif /* VBOX_STRICT && HC_ARCH_BITS == 64 */
734
735
736/**
737 * Request buffer for GMMR0QueryStatisticsReq / VMMR0_DO_GMM_QUERY_STATISTICS.
738 * @see GMMR0QueryStatistics.
739 */
740typedef struct GMMQUERYSTATISTICSSREQ
741{
742 /** The header. */
743 SUPVMMR0REQHDR Hdr;
744 /** The support driver session. */
745 PSUPDRVSESSION pSession;
746 /** The statistics. */
747 GMMSTATS Stats;
748} GMMQUERYSTATISTICSSREQ;
749/** Pointer to a GMMR0QueryStatisticsReq / VMMR0_DO_GMM_QUERY_STATISTICS
750 * request buffer. */
751typedef GMMQUERYSTATISTICSSREQ *PGMMQUERYSTATISTICSSREQ;
752
753GMMR0DECL(int) GMMR0QueryStatisticsReq(PGVM pGVM, PGMMQUERYSTATISTICSSREQ pReq);
754
755
756/**
757 * Request buffer for GMMR0ResetStatisticsReq / VMMR0_DO_GMM_RESET_STATISTICS.
758 * @see GMMR0ResetStatistics.
759 */
760typedef struct GMMRESETSTATISTICSSREQ
761{
762 /** The header. */
763 SUPVMMR0REQHDR Hdr;
764 /** The support driver session. */
765 PSUPDRVSESSION pSession;
766 /** The statistics to reset.
767 * Any non-zero entry will be reset (if permitted). */
768 GMMSTATS Stats;
769} GMMRESETSTATISTICSSREQ;
770/** Pointer to a GMMR0ResetStatisticsReq / VMMR0_DO_GMM_RESET_STATISTICS
771 * request buffer. */
772typedef GMMRESETSTATISTICSSREQ *PGMMRESETSTATISTICSSREQ;
773
774GMMR0DECL(int) GMMR0ResetStatisticsReq(PGVM pGVM, PGMMRESETSTATISTICSSREQ pReq);
775
776
777
778#ifdef IN_RING3
779/** @defgroup grp_gmm_r3 The Global Memory Manager Ring-3 API Wrappers
780 * @{
781 */
782GMMR3DECL(int) GMMR3InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
783 GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
784GMMR3DECL(int) GMMR3UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
785GMMR3DECL(int) GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
786GMMR3DECL(int) GMMR3AllocatePagesPerform(PVM pVM, PGMMALLOCATEPAGESREQ pReq);
787GMMR3DECL(void) GMMR3AllocatePagesCleanup(PGMMALLOCATEPAGESREQ pReq);
788GMMR3DECL(int) GMMR3FreePagesPrepare(PVM pVM, PGMMFREEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
789GMMR3DECL(void) GMMR3FreePagesRePrep(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t cPages, GMMACCOUNT enmAccount);
790GMMR3DECL(int) GMMR3FreePagesPerform(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t cActualPages);
791GMMR3DECL(void) GMMR3FreePagesCleanup(PGMMFREEPAGESREQ pReq);
792GMMR3DECL(void) GMMR3FreeAllocatedPages(PVM pVM, GMMALLOCATEPAGESREQ const *pAllocReq);
793GMMR3DECL(int) GMMR3AllocateLargePage(PVM pVM, uint32_t cbPage);
794GMMR3DECL(int) GMMR3FreeLargePage(PVM pVM, uint32_t idPage);
795GMMR3DECL(int) GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
796GMMR3DECL(int) GMMR3QueryHypervisorMemoryStats(PVM pVM, uint64_t *pcTotalAllocPages, uint64_t *pcTotalFreePages, uint64_t *pcTotalBalloonPages, uint64_t *puTotalBalloonSize);
797GMMR3DECL(int) GMMR3QueryMemoryStats(PVM pVM, uint64_t *pcAllocPages, uint64_t *pcMaxPages, uint64_t *pcBalloonPages);
798GMMR3DECL(int) GMMR3BalloonedPages(PVM pVM, GMMBALLOONACTION enmAction, uint32_t cBalloonedPages);
799GMMR3DECL(int) GMMR3RegisterSharedModule(PVM pVM, PGMMREGISTERSHAREDMODULEREQ pReq);
800GMMR3DECL(int) GMMR3UnregisterSharedModule(PVM pVM, PGMMUNREGISTERSHAREDMODULEREQ pReq);
801GMMR3DECL(int) GMMR3CheckSharedModules(PVM pVM);
802GMMR3DECL(int) GMMR3ResetSharedModules(PVM pVM);
803
804# if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
805GMMR3DECL(bool) GMMR3IsDuplicatePage(PVM pVM, uint32_t idPage);
806# endif
807
808/** @} */
809#endif /* IN_RING3 */
810
811/** @} */
812
813RT_C_DECLS_END
814
815#endif /* !VBOX_INCLUDED_vmm_gmm_h */
816
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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