VirtualBox

Changeset 5064 in vbox


Ignore:
Timestamp:
Sep 26, 2007 6:37:49 PM (17 years ago)
Author:
vboxsync
Message:

GMM.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/gvm.h

    r5031 r5064  
    6464        struct GMMPERVM     s;
    6565#endif
    66         uint8_t             padding[64];
     66        uint8_t             padding[256];
    6767    } gmm;
    6868
  • trunk/src/VBox/VMM/VMMR0/GMMR0.cpp

    r5035 r5064  
    603603 * Initializes the per-VM data for the GMM.
    604604 *
     605 * This is called from within the GVMM lock (from GVMMR0CreateVM)
     606 * and should only initialize the data members so GMMR0CleanupVM
     607 * can deal with them. We reserve no memory or anything here,
     608 * that's done later in GMMR0InitVM.
     609 *
    605610 * @param   pGVM    Pointer to the Global VM structure.
    606611 */
    607612GMMR0DECL(void) GMMR0InitPerVMData(PGVM pGVM)
    608613{
    609     pGVM->gmm.s.cRAMPages = 0;
    610     pGVM->gmm.s.cPrivatePages = 0;
    611     pGVM->gmm.s.cSharedPages = 0;
    612     pGVM->gmm.s.enmPolicy = GMMOCPOLICY_TBD;
    613     pGVM->gmm.s.enmPriority = GMMPRIORITY_NORMAL;
     614    AssertCompile(RT_SIZEOFMEMB(GVM,gmm.s) <= RT_SIZEOFMEMB(GVM,gmm.padding));
     615    AssertRelease(RT_SIZEOFMEMB(GVM,gmm.s) <= RT_SIZEOFMEMB(GVM,gmm.padding));
     616
     617    //pGVM->gmm.s.cBasePages = 0;
     618    //pGVM->gmm.s.cPrivatePages = 0;
     619    //pGVM->gmm.s.cSharedPages = 0;
     620    pGVM->gmm.s.enmPolicy = GMMOCPOLICY_INVALID;
     621    pGVM->gmm.s.enmPriority = GMMPRIORITY_INVALID;
     622    pGVM->gmm.s.fMayAllocate = false;
    614623}
    615624
     
    623632{
    624633    LogFlow(("GMMR0CleanupVM: pGVM=%p:{.pVM=%p, .hSelf=%#x}\n", pGVM, pGVM->pVM, pGVM->hSelf));
     634
     635    /*
     636     * The policy is 'INVALID' until the initial reservation
     637     * request has been serviced.
     638     */
     639    if (    pGVM->gmm.s.enmPolicy <= GMMOCPOLICY_INVALID
     640        ||  pGVM->gmm.s.enmPolicy >= GMMOCPOLICY_END)
     641    {
     642    }
     643
    625644
    626645    PGMM pGMM;
    627646    GMM_GET_VALID_INSTANCE_VOID(pGMM);
    628647
    629     int rc =  RTSemFastMutexRequest(pGMM->Mtx);
     648    int rc = RTSemFastMutexRequest(pGMM->Mtx);
    630649    AssertRC(rc);
    631650
    632651    /*
    633      * If it's the last VM around, we can skip walking all the chunk looking 
     652     * If it's the last VM around, we can skip walking all the chunk looking
    634653     * for the pages owned by this VM and instead flush the whole shebang.
    635654     *
     
    637656     * references behind (shouldn't happen of course, but you never know).
    638657     */
    639     if (pGMM->cActiveVMs == 1)
    640     {
    641        
     658    pGMM->cActiveVMs--;
     659    if (!pGMM->cActiveVMs)
     660    {
     661
     662
    642663    }
    643     else if (pGVM->gmm.s.cPrivatePages)
     664    else if (0)//pGVM->gmm.s.cPrivatePages)
    644665    {
    645666        /*
     
    654675         * longer needed.
    655676         */
    656        
     677
    657678    }
    658679
     
    660681
    661682    /* trash the data */
    662     pGVM->gmm.s.cRAMPages = 0;
    663     pGVM->gmm.s.cPrivatePages = 0;
    664     pGVM->gmm.s.cSharedPages = 0;
     683//    pGVM->gmm.s.cBasePages = 0;
     684//    pGVM->gmm.s.cPrivatePages = 0;
     685//    pGVM->gmm.s.cSharedPages = 0;
    665686    pGVM->gmm.s.enmPolicy = GMMOCPOLICY_INVALID;
    666687    pGVM->gmm.s.enmPriority = GMMPRIORITY_INVALID;
     
    717738                cShared++;
    718739
    719         /* 
     740        /*
    720741         * Did it add up?
    721742         */
     
    724745                        ||  pChunk->cShared != cShared))
    725746        {
    726             SUPR0Printf("GMM: Chunk %p/%#x has bogus stats - free=%d/%d private=%d/%d shared=%d/%d\n", 
     747            SUPR0Printf("GMM: Chunk %p/%#x has bogus stats - free=%d/%d private=%d/%d shared=%d/%d\n",
    727748                        pChunk->cFree, cFree, pChunk->cPrivate, cPrivate, pChunk->cShared, cShared);
    728749            pChunk->cFree = cFree;
     
    736757
    737758
    738 
     759/**
     760 * The initial resource reservations.
     761 *
     762 * This will make memory reservations according to policy and priority. If there isn't
     763 * sufficient resources available to sustain the VM this function will fail and all
     764 * future allocations requests will fail as well.
     765 *
     766 * @returns VBox status code.
     767 * @retval  VERR_GMM_NOT_SUFFICENT_MEMORY
     768 * @retval  VERR_GMM_
     769 *
     770 * @param   pVM             Pointer to the shared VM structure.
     771 * @param   cBasePages      The number of pages of RAM. This is *only* the RAM, it does
     772 *                          not take additional pages for the ROMs and MMIO2 into account.
     773 *                          These allocations will have to be reported when the initialization
     774 *                          process has completed.
     775 * @param   cShadowPages    The max number of pages that will be allocated for shadow pageing structures.
     776 * @param   enmPolicy       The OC policy to use on this VM.
     777 * @param   enmPriority     The priority in an out-of-memory situation.
     778 */
     779GMMR0DECL(int) GMMR0InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority)
     780{
     781    LogFlow(("GMMR0InitialReservation: pVM=%p cBasePages=%#llx cShadowPages=%#x enmPolicy=%d enmPriority=%d\n",
     782             pVM, cBasePages, cShadowPages, enmPolicy, enmPriority));
     783
     784    /*
     785     * Validate, get basics and take the semaphore.
     786     */
     787    PGMM pGMM;
     788    GMM_GET_VALID_INSTANCE(pGMM, VERR_INTERNAL_ERROR);
     789    PGVM pGVM = GVMMR0ByVM(pVM);
     790    if (!pVM)
     791        return VERR_INVALID_PARAMETER;
     792
     793    int rc = RTSemFastMutexRequest(pGMM->Mtx);
     794    AssertRC(rc);
     795
     796
     797    pGMM->cActiveVMs++;
     798
     799
     800
     801    RTSemFastMutexRelease(pGMM->Mtx);
     802    LogFlow(("GMMR0InitialReservation: returns %Rrc\n", rc));
     803    return rc;
     804}
     805
     806
     807/**
     808 * This updates the memory reservation with the additional MMIO2 and ROM pages.
     809 *
     810 * @returns VBox status code.
     811 * @retval  VERR_GMM_NOT_SUFFICENT_MEMORY
     812 *
     813 * @param   pVM             Pointer to the shared VM structure.
     814 * @param   cExtraPages     The number of pages that makes up ROM ranges outside the normal
     815 *                          RAM and MMIO2 memory.
     816 * @param   cMisc           Miscellaneous fixed commitments like the heap, VM structure and such.
     817 */
     818GMMR0DECL(int) GMMR0ReservationUpdate(PVM pVM, uint64_t cExtraPages)
     819{
     820    LogFlow(("GMMR0ReservationUpdate: pVM=%p cExtraPages=%#llx\n", pVM, cExtraPages));
     821
     822    /*
     823     * Validate, get basics and take the semaphore.
     824     */
     825    PGMM pGMM;
     826    GMM_GET_VALID_INSTANCE(pGMM, VERR_INTERNAL_ERROR);
     827    PGVM pGVM = GVMMR0ByVM(pVM);
     828    if (!pVM)
     829        return VERR_INVALID_PARAMETER;
     830
     831    int rc = RTSemFastMutexRequest(pGMM->Mtx);
     832    AssertRC(rc);
     833
     834
     835
     836    RTSemFastMutexRelease(pGMM->Mtx);
     837    LogFlow(("GMMR0ReservationUpdate: returns %Rrc\n", rc));
     838    return rc;
     839}
     840
     841
     842
  • trunk/src/VBox/VMM/VMMR0/GMMR0Internal.h

    r5033 r5064  
    2222#include <VBox/gmm.h>
    2323
     24/**
     25 * The allocation sizes.
     26 */
     27typedef struct GMMVMSIZES
     28{
     29    /** The number of pages of base memory.
     30     * This is the sum of RAM, ROMs and handy pages. */
     31    uint64_t        cBasePages;
     32    /** The number of pages for the shadow pool. (Can be sequeezed for memory.) */
     33    uint32_t        cShadowPages;
     34    /** The number of pages for fixed allocations like MMIO2 and the hyper heap. */
     35    uint32_t        cFixedPages;
     36} GMMVMSIZES;
     37typedef GMMVMSIZES *PGMMVMSIZES;
     38
    2439
    2540/**
     
    2843typedef struct GMMPERVM
    2944{
    30     /** The ram size, in pages. */
    31     uint64_t        cRAMPages;
    32     /** The number of private pages. */
     45    /** The reservations. */
     46    GMMVMSIZES      Reserved;
     47    /** The actual allocations. */
     48    GMMVMSIZES      Allocated;
     49    /** The current number of private pages. */
    3350    uint64_t        cPrivatePages;
    34     /** The number of shared pages. */
     51    /** The current number of shared pages. */
    3552    uint64_t        cSharedPages;
     53    /** The current number of ballooned pages. */
     54    uint64_t        cBalloonedPages;
     55    /** The max number of pages that can be ballooned. */
     56    uint64_t        cMaxBalloonedPages;
    3657    /** The current over-comitment policy. */
    3758    GMMOCPOLICY     enmPolicy;
    3859    /** The VM priority for arbitrating VMs in an out-of-memory situation. */
    3960    GMMPRIORITY     enmPriority;
     61    /** Whether the VM is allowed to allocate memory or not.
     62     * This is used when the reservation update request fails or when the VM has
     63     * been told to suspend/save/die in an out-of-memory case. */
     64    bool            fMayAllocate;
    4065} GMMPERVM;
    4166/** Pointer to the per-VM GMM data. */
Note: See TracChangeset for help on using the changeset viewer.

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