gmm.h revision 99cfb4b2e2b340e368182fbf3e5ddd29d4b27180
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * GMM - The Global Memory Manager.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * Copyright (C) 2007-2010 Oracle Corporation
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * available from http://www.virtualbox.org. This file is free software;
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * you can redistribute it and/or modify it under the terms of the GNU
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * General Public License (GPL) as published by the Free Software
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * The contents of this file may alternatively be used under the terms
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * of the Common Development and Distribution License Version 1.0
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * VirtualBox OSE distribution, in which case the provisions of the
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * CDDL are applicable instead of those of the GPL.
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * You may elect to license modified versions of this file under the
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * terms and conditions of either the GPL or the CDDL or both.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/** @defgroup grp_gmm GMM - The Global Memory Manager
b11724409affb86e618d406fae3791ec2c61d184vboxsync/** @def IN_GMM_R0
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * Used to indicate whether we're inside the same link module as the ring 0
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * part of the Global Memory Manager or not.
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** @def GMMR0DECL
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync * Ring 0 GMM export or import declaration.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * @param type The return type of the function declaration.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/** @def IN_GMM_R3
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * Used to indicate whether we're inside the same link module as the ring 3
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * part of the Global Memory Manager or not.
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** @def GMMR3DECL
940534f83612182a14887c7ccac92bfc43cbebd2vboxsync * Ring 3 GMM export or import declaration.
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync * @param type The return type of the function declaration.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync/** The chunk shift. (2^21 = 2 MB) */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** The allocation chunk size. */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** The allocation chunk size in pages. */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync#define GMM_CHUNK_NUM_PAGES (1U << (GMM_CHUNK_SHIFT - PAGE_SHIFT))
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/** The shift factor for converting a page id into a chunk id. */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync#define GMM_CHUNKID_SHIFT (GMM_CHUNK_SHIFT - PAGE_SHIFT)
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/** The last valid Chunk ID value. */
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync#define GMM_CHUNKID_LAST (GMM_PAGEID_LAST >> GMM_CHUNKID_SHIFT)
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** The last valid Page ID value.
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync * The current limit is 2^28 - 1, or almost 1TB if you like.
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync * The constraints are currently dictated by PGMPAGE. */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** Mask out the page index from the Page ID. */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync#define GMM_PAGEID_IDX_MASK ((1U << GMM_CHUNKID_SHIFT) - 1)
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** The NIL Chunk ID value. */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** The NIL Page ID value. */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync#if 0 /* wrong - these are guest page pfns and not page ids! */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/** Special Page ID used by unassigned pages. */
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/** Special Page ID used by unsharable pages.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * Like MMIO2, shadow and heap. This is for later, obviously. */
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/** The end of the valid Page IDs. This is the first special one. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync/** @def GMM_GCPHYS_LAST
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * The last of the valid guest physical address as it applies to GMM pages.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * This must reflect the constraints imposed by the RTGCPHYS type and
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * the guest page frame number used internally in GMMPAGE.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * @note Note this corresponds to GMM_PAGE_PFN_LAST. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync# define GMM_GCPHYS_LAST UINT64_C(0x00000fffffff0000) /* 2^44 (16TB) - 0x10000 */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync# define GMM_GCPHYS_LAST UINT64_C(0x0000000fffff0000) /* 2^36 (64GB) - 0x10000 */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * Over-commitment policy.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** The usual invalid 0 value. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** No over-commitment, fully backed.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * The GMM guarantees that it will be able to allocate all of the
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * guest RAM for a VM with OC policy. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** to-be-determined. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** The end of the valid policy range. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** The usual 32-bit hack. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * VM / Memory priority.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** The usual invalid 0 value. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * When ballooning, ask these VMs last.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * When running out of memory, try not to interrupt these VMs. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** Normal.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * When ballooning, don't wait to ask these.
fb51a02921f8a53cad10e6dd1e25883403a93370vboxsync * When running out of memory, pause, save and/or kill these VMs. */
940534f83612182a14887c7ccac92bfc43cbebd2vboxsync * When ballooning, maximize these first.
4fd422211bfa08d134940933274daafa9f2a3ef7vboxsync * When running out of memory, save or kill these VMs. */
4fd422211bfa08d134940933274daafa9f2a3ef7vboxsync /** The end of the valid priority range. */
940534f83612182a14887c7ccac92bfc43cbebd2vboxsync /** The custom 32-bit type blowup. */
38a1025c152d8cfd52dda13ecccb8f601d5e84ebvboxsync * GMM Memory Accounts.
38a1025c152d8cfd52dda13ecccb8f601d5e84ebvboxsync /** The customary invalid zero entry. */
38a1025c152d8cfd52dda13ecccb8f601d5e84ebvboxsync /** Account with the base allocations. */
38a1025c152d8cfd52dda13ecccb8f601d5e84ebvboxsync /** Account with the shadow allocations. */
20627226661ed2e925ff34f706827529ec880624vboxsync /** Account with the fixed allocations. */
940534f83612182a14887c7ccac92bfc43cbebd2vboxsync /** The end of the valid values. */
fb51a02921f8a53cad10e6dd1e25883403a93370vboxsync /** The usual 32-bit value to finish it off. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * Balloon actions.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsynctypedef enum
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** Invalid zero entry. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** Inflate the balloon. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** Deflate the balloon. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** Puncture the balloon because of VM reset. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** End of the valid actions. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync /** hack forcing the size of the enum to 32-bits. */
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * A page descriptor for use when freeing pages.
9ffc69ee5b1d727cdebfd2b3daa9161a690b9677vboxsync * See GMMR0FreePages, GMMR0BalloonedPages.
typedef struct GMMFREEPAGEDESC
typedef struct GMMPAGEDESC
} GMMPAGEDESC;
typedef struct GMMVMSIZES
} GMMVMSIZES;
typedef struct GMMVMSTATS
bool fBallooningEnabled;
bool fSharedPagingEnabled;
bool fMayAllocate;
} GMMVMSTATS;
typedef struct GMMSTATS
} GMMSTATS;
GMMR0DECL(int) GMMR0InitialReservation(PVM pVM, VMCPUID idCpu, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
GMMR0DECL(int) GMMR0UpdateReservation(PVM pVM, VMCPUID idCpu, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
GMMR0DECL(int) GMMR0AllocateHandyPages(PVM pVM, VMCPUID idCpu, uint32_t cPagesToUpdate, uint32_t cPagesToAlloc, PGMMPAGEDESC paPages);
GMMR0DECL(int) GMMR0AllocatePages(PVM pVM, VMCPUID idCpu, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount);
GMMR0DECL(int) GMMR0AllocateLargePage(PVM pVM, VMCPUID idCpu, uint32_t cbPage, uint32_t *pIdPage, RTHCPHYS *pHCPhys);
GMMR0DECL(int) GMMR0FreePages(PVM pVM, VMCPUID idCpu, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount);
GMMR0DECL(int) GMMR0BalloonedPages(PVM pVM, VMCPUID idCpu, GMMBALLOONACTION enmAction, uint32_t cBalloonedPages);
GMMR0DECL(int) GMMR0MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
GMMR0DECL(int) GMMR0RegisterSharedModule(PVM pVM, VMCPUID idCpu, VBOXOSFAMILY enmGuestOS, char *pszModuleName, char *pszVersion,
GMMR0DECL(int) GMMR0UnregisterSharedModule(PVM pVM, VMCPUID idCpu, char *pszModuleName, char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule);
typedef struct GMMINITIALRESERVATIONREQ
typedef struct GMMUPDATERESERVATIONREQ
typedef struct GMMALLOCATEPAGESREQ
typedef struct GMMFREEPAGESREQ
typedef struct GMMBALLOONEDPAGESREQ
typedef struct GMMMEMSTATSREQ
/** Pointer to a GMMR0QueryHypervisorMemoryStatsReq / VMMR0_DO_GMM_QUERY_HYPERVISOR_MEM_STATS request buffer. */
typedef struct GMMMAPUNMAPCHUNKREQ
typedef struct GMMFREELARGEPAGEREQ
typedef struct GMMREGISTERSHAREDMODULEREQ
/** Pointer to a GMMR0RegisterSharedModuleReq / VMMR0_DO_GMM_REGISTER_SHARED_MODULE request buffer. */
GMMR0DECL(int) GMMR0RegisterSharedModuleReq(PVM pVM, VMCPUID idCpu, PGMMREGISTERSHAREDMODULEREQ pReq);
typedef struct GMMSHAREDREGIONDESC
typedef struct GMMSHAREDMODULE
typedef struct GMMSHAREDPAGEDESC
GMMR0DECL(int) GMMR0SharedModuleCheckPage(PGVM pGVM, PGMMSHAREDMODULE pModule, unsigned idxRegion, unsigned idxPage,
typedef struct GMMUNREGISTERSHAREDMODULEREQ
/** Pointer to a GMMR0UnregisterSharedModuleReq / VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE request buffer. */
GMMR0DECL(int) GMMR0UnregisterSharedModuleReq(PVM pVM, VMCPUID idCpu, PGMMUNREGISTERSHAREDMODULEREQ pReq);
typedef struct GMMFINDDUPLICATEPAGEREQ
bool fDuplicate;
typedef struct GMMQUERYSTATISTICSSREQ
typedef struct GMMRESETSTATISTICSSREQ
#ifdef IN_RING3
GMMR3DECL(int) GMMR3InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
GMMR3DECL(int) GMMR3UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
GMMR3DECL(int) GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
GMMR3DECL(int) GMMR3FreePagesPrepare(PVM pVM, PGMMFREEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
GMMR3DECL(void) GMMR3FreePagesRePrep(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t cPages, GMMACCOUNT enmAccount);
GMMR3DECL(int) GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
GMMR3DECL(int) GMMR3QueryHypervisorMemoryStats(PVM pVM, uint64_t *pcTotalAllocPages, uint64_t *pcTotalFreePages, uint64_t *pcTotalBalloonPages, uint64_t *puTotalBalloonSize);