GMMR0Internal.h revision a448d0dfcede5c742c35e4aee5f9848a4a61bf18
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/* $Id$ */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @file
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * GMM - The Global Memory Manager, Internal Header.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2007 Oracle Corporation
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * available from http://www.virtualbox.org. This file is free software;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * General Public License (GPL) as published by the Free Software
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#ifndef ___GMMR0Internal_h
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define ___GMMR0Internal_h
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <VBox/vmm/gmm.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/avl.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The allocation sizes.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef struct GMMVMSIZES
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The number of pages of base memory.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This is the sum of RAM, ROMs and handy pages. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint64_t cBasePages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The number of pages for the shadow pool. (Can be squeezed for memory.) */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint32_t cShadowPages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The number of pages for fixed allocations like MMIO2 and the hyper heap. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint32_t cFixedPages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync} GMMVMSIZES;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Pointer to a GMMVMSIZES. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef GMMVMSIZES *PGMMVMSIZES;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Shared module registration info (per VM)
a60be2c64ea23bb7ce4c9998bcd541c4db879fbavboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef struct GMMSHAREDMODULEPERVM
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Tree node. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AVLGCPTRNODECORE Core;
7d6ce198fd361f58bd1ebdeee7772f76b4e58966vboxsync
2fce40121ae472df2fd959fbe19775ed43304a0bvboxsync /** Pointer to global shared module info. */
edde275acba04aca58db4172a163741e3abadfbcvboxsync PGMMSHAREDMODULE pGlobalModule;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Set if another VM registered a different shared module at the same base address. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync bool fCollision;
40839c441cb305d84420565f7ca25403d8177413vboxsync /** Alignment. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync bool bAlignment[3];
7d6ce198fd361f58bd1ebdeee7772f76b4e58966vboxsync
7d6ce198fd361f58bd1ebdeee7772f76b4e58966vboxsync /** Number of included region descriptors */
7d6ce198fd361f58bd1ebdeee7772f76b4e58966vboxsync uint32_t cRegions;
7d6ce198fd361f58bd1ebdeee7772f76b4e58966vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Shared region descriptor(s). */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync GMMSHAREDREGIONDESC aRegions[1];
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync} GMMSHAREDMODULEPERVM;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Pointer to a GMMSHAREDMODULEPERVM. */
edde275acba04aca58db4172a163741e3abadfbcvboxsynctypedef GMMSHAREDMODULEPERVM *PGMMSHAREDMODULEPERVM;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
a1d9d394b49969e730c5a8e037ea2d672a48dbf6vboxsync/** Pointer to a GMM allocation chunk. */
edde275acba04aca58db4172a163741e3abadfbcvboxsynctypedef struct GMMCHUNK *PGMMCHUNK;
edde275acba04aca58db4172a163741e3abadfbcvboxsync
edde275acba04aca58db4172a163741e3abadfbcvboxsync
edde275acba04aca58db4172a163741e3abadfbcvboxsync/** The GMMCHUNK::cFree shift count employed by gmmR0SelectFreeSetList. */
a1d9d394b49969e730c5a8e037ea2d672a48dbf6vboxsync#define GMM_CHUNK_FREE_SET_SHIFT 4
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Index of the list containing completely unused chunks.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The code ASSUMES this is the last list. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define GMM_CHUNK_FREE_SET_UNUSED_LIST (GMM_CHUNK_NUM_PAGES >> GMM_CHUNK_FREE_SET_SHIFT)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
2fce40121ae472df2fd959fbe19775ed43304a0bvboxsync * A set of free chunks.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef struct GMMCHUNKFREESET
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The number of free pages in the set. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint64_t cFreePages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The generation ID for the set. This is incremented whenever
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * something is linked or unlinked from this set. */
2fce40121ae472df2fd959fbe19775ed43304a0bvboxsync uint64_t idGeneration;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Chunks ordered by increasing number of free pages.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * In the final list the chunks are completely unused. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PGMMCHUNK apLists[GMM_CHUNK_FREE_SET_UNUSED_LIST + 1];
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync} GMMCHUNKFREESET;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
2fce40121ae472df2fd959fbe19775ed43304a0bvboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The per-VM GMM data.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef struct GMMPERVM
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Free set for use in bound mode. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync GMMCHUNKFREESET Private;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The reservations. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync GMMVMSIZES Reserved;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The actual allocations.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This includes both private and shared page allocations. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync GMMVMSIZES Allocated;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The current number of private pages. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint64_t cPrivatePages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The current number of shared pages. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint64_t cSharedPages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The current over-commitment policy. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync GMMOCPOLICY enmPolicy;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The VM priority for arbitrating VMs in low and out of memory situation.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Like which VMs to start squeezing first. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync GMMPRIORITY enmPriority;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The current number of ballooned pages. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint64_t cBalloonedPages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The max number of pages that can be ballooned. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint64_t cMaxBalloonedPages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The number of pages we've currently requested the guest to give us.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This is 0 if no pages currently requested. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint64_t cReqBalloonedPages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The number of pages the guest has given us in response to the request.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This is not reset on request completed and may be used in later decisions. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint64_t cReqActuallyBalloonedPages;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The number of pages we've currently requested the guest to take back. */
a60be2c64ea23bb7ce4c9998bcd541c4db879fbavboxsync uint64_t cReqDeflatePages;
a60be2c64ea23bb7ce4c9998bcd541c4db879fbavboxsync
a60be2c64ea23bb7ce4c9998bcd541c4db879fbavboxsync /** Shared module tree (per-vm). */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PAVLGCPTRNODECORE pSharedModuleTree;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Whether ballooning is enabled or not. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync bool fBallooningEnabled;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Whether shared paging is enabled or not. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync bool fSharedPagingEnabled;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
eb259de2a9eac4b4dda56e89f5004671f926bd9bvboxsync /** Whether the VM is allowed to allocate memory or not.
eb259de2a9eac4b4dda56e89f5004671f926bd9bvboxsync * This is used when the reservation update request fails or when the VM has
93e05ea894cefd56ca308d72372b4dd8045bd1eevboxsync * been told to suspend/save/die in an out-of-memory case. */
93e05ea894cefd56ca308d72372b4dd8045bd1eevboxsync bool fMayAllocate;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync} GMMPERVM;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Pointer to the per-VM GMM data. */
a60be2c64ea23bb7ce4c9998bcd541c4db879fbavboxsynctypedef GMMPERVM *PGMMPERVM;
a60be2c64ea23bb7ce4c9998bcd541c4db879fbavboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#endif
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync