gmm.h revision 3cc114d9c84cf4a1e3b5225e81527614c30f1d83
/** @file
* GMM - The Global Memory Manager.
*/
/*
* Copyright (C) 2007 InnoTek Systemberatung GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
*/
#ifndef ___VBox_gmm_h
#define ___VBox_gmm_h
/** @defgroup grp_gmm GMM - The Global Memory Manager
* @{
*/
/** @def IN_GMM_R0
* Used to indicate whether we're inside the same link module as the ring 0
* part of the Global Memory Manager or not.
*/
/** @def GMMR0DECL
* Ring 0 GMM export or import declaration.
* @param type The return type of the function declaration.
*/
#ifdef IN_GMM_R0
#else
#endif
/** The chunk shift. (2^20 = 1 MB) */
#define GMM_CHUNK_SHIFT 20
/** The allocation chunk size. */
/** The shift factor for converting a page id into a chunk id. */
/** The NIL Chunk ID value. */
#define NIL_GMM_CHUNKID 0
/** The NIL Page ID value. */
#define NIL_GMM_PAGEID 0
#if 0 /* wrong - these are guest page pfns and not page ids! */
/** Special Page ID used by unassigned pages. */
#define GMM_PAGEID_UNASSIGNED 0x0fffffffU
/** Special Page ID used by unsharable pages.
* Like MMIO2, shadow and heap. This is for later, obviously. */
#define GMM_PAGEID_UNSHARABLE 0x0ffffffeU
/** The end of the valid Page IDs. This is the first special one. */
#define GMM_PAGEID_END 0x0ffffff0U
#endif
/**
* Over-commitment policy.
*/
typedef enum GMMOCPOLICY
{
/** The usual invalid 0 value. */
GMMOCPOLICY_INVALID = 0,
/** No over-commitment, fully backed.
* The GMM guarantees that it will be able to allocate all of the
* guest RAM for a VM with OC policy. */
/** to-be-determined. */
/** The end of the valid policy range. */
/** The usual 32-bit hack. */
GMMOCPOLICY_32BIT_HACK = 0x7fffffff
} GMMOCPOLICY;
/**
* VM / Memory priority.
*/
typedef enum GMMPRIORITY
{
/** The usual invalid 0 value. */
GMMPRIORITY_INVALID = 0,
/** High.
* When ballooning, ask these VMs last.
* When running out of memory, try not to interrupt these VMs. */
/** Normal.
* When ballooning, don't wait to ask these.
/** Low.
* When ballooning, maximize these first.
* When running out of memory, save or kill these VMs. */
/** The end of the valid priority range. */
GMMPRIORITY_END = 0,
/** The custom 32-bit type blowup. */
GMMPRIORITY_32BIT_HACK = 0x7fffffff
} GMMPRIORITY;
/**
* GMM Memory Accounts.
*/
typedef enum GMMACCOUNT
{
/** The customary invalid zero entry. */
GMMACCOUNT_INVALID = 0,
/** Account with the base allocations. */
/** Account with the shadow allocations. */
/** Account with the fixed allocations. */
/** The end of the valid values. */
/** The usual 32-bit value to finish it off. */
GMMACCOUNT_32BIT_HACK = 0x7fffffff
} GMMACCOUNT;
/**
* A page descriptor for use when freeing pages.
* See GMMR0FreePages, GMMR0BalloonedPages.
*/
typedef struct GMMFREEPAGEDESC
{
/** The Page ID of the page to be freed. */
/** Pointer to a page descriptor for freeing pages. */
typedef GMMFREEPAGEDESC *PGMMFREEPAGEDESC;
/**
* A page descriptor for use when updating and allocating pages.
*
* This is a bit complicated because we want to do as much as possible
* with the same structure.
*/
typedef struct GMMPAGEDESC
{
/** The physical address of the page.
*
* @input GMMR0AllocateHandyPages expects the guest physical address
* to update the GMMPAGE structure with. Pass GMM_GCPHYS_UNSHARABLE
* when appropriate and NIL_RTHCPHYS when the page wasn't used
* for any specific guest address.
*
* GMMR0AllocatePage expects the guest physical address to put in
* the GMMPAGE structure for the page it allocates for this entry.
* Pass NIL_RTHCPHYS and GMM_GCPHYS_UNSHARABLE as above.
*
* @output The host physical address of the allocated page.
* NIL_RTHCPHYS on allocation failure.
*
* ASSUMES: sizeof(RTHCPHYS) >= sizeof(RTGCPHYS).
*/
/** The Page ID.
*
* @intput GMMR0AllocateHandyPages expects the Page ID of the page to
* update here. NIL_GMM_PAGEID means no page should be updated.
*
* GMMR0AllocatePages requires this to be initialized to
* NIL_GMM_PAGEID currently.
*
* @output The ID of the page, NIL_GMM_PAGEID if the allocation failed.
*/
/** The Page ID of the shared page was replaced by this page.
*
* @input GMMR0AllocateHandyPages expects this to indicate a shared
* page that has been replaced by this page and should have its
* reference counter decremented and perhaps be freed up. Use
* NIL_GMM_PAGEID if no shared page was involved.
*
* All other APIs expects NIL_GMM_PAGEID here.
*
* @output All APIs sets this to NIL_GMM_PAGEID.
*/
} GMMPAGEDESC;
/** Pointer to a page allocation. */
typedef GMMPAGEDESC *PGMMPAGEDESC;
/** GMMPAGEDESC::HCPhysGCPhys value that indicates that the page is shared. */
GMMR0DECL(int) GMMR0InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
GMMR0DECL(int) GMMR0UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
GMMR0DECL(int) GMMR0AllocateHandyPages(PVM pVM, uint32_t cPagesToUpdate, uint32_t cPagesToAlloc, PGMMPAGEDESC paPages);
GMMR0DECL(int) GMMR0AllocatePages(PVM pVM, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount);
GMMR0DECL(int) GMMR0FreePages(PVM pVM, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount);
GMMR0DECL(int) GMMR0BalloonedPages(PVM pVM, uint32_t cBalloonedPages, uint32_t cPagesToFree, PGMMFREEPAGEDESC paPages);
/** @} */
#endif