VirtualBox

Changeset 18880 in vbox


Ignore:
Timestamp:
Apr 14, 2009 9:42:01 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
45904
Message:

PGM/MM: Implemented the /RamPreAlloc CFGM option.

Location:
trunk/src/VBox/VMM
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/MM.cpp

    r18792 r18880  
    429429    else
    430430        rc = PGMR3PhysRegisterRam(pVM, 0, RT_MIN(cbRam, offRamHole), "Base RAM");
    431     if (    RT_SUCCESS(rc)
    432         &&  fPreAlloc)
    433     {
    434         /** @todo RamPreAlloc should be handled at the very end of the VM creation. (lazy bird) */
    435         return VM_SET_ERROR(pVM, VERR_NOT_IMPLEMENTED, "TODO: RamPreAlloc");
    436     }
    437431
    438432    /*
  • trunk/src/VBox/VMM/PGM.cpp

    r18861 r18880  
    12091209    }
    12101210
    1211     rc = CFGMR3QueryBoolDef(pCfgPGM, "RamPreAlloc", &pVM->pgm.s.fRamPreAlloc, false);
     1211    rc = CFGMR3QueryBoolDef(CFGMR3GetRoot(pVM), "RamPreAlloc", &pVM->pgm.s.fRamPreAlloc, false);
    12121212    AssertLogRelRCReturn(rc, rc);
    12131213
     
    18731873    else
    18741874        pVM->pgm.s.GCPhys4MBPSEMask = RT_BIT_64(32) - 1;
     1875
     1876    /*
     1877     * Allocate memory if we're supposed to do that.
     1878     */
     1879    if (pVM->pgm.s.fRamPreAlloc)
     1880        rc = pgmR3PhysRamPreAllocate(pVM);
    18751881
    18761882    LogRel(("PGMR3InitFinalize: 4 MB PSE mask %RGp\n", pVM->pgm.s.GCPhys4MBPSEMask));
  • trunk/src/VBox/VMM/PGMInternal.h

    r18746 r18880  
    28332833
    28342834
     2835int             pgmPhysAllocPage(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys);
    28352836int             pgmPhysPageLoadIntoTlb(PPGM pPGM, RTGCPHYS GCPhys);
    28362837int             pgmPhysPageLoadIntoTlbWithPage(PPGM pPGM, PPGMPAGE pPage, RTGCPHYS GCPhys);
     
    28432844VMMDECL(int)    pgmPhysRomWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
    28442845#ifdef IN_RING3
    2845 int             pgmR3PhysChunkMap(PVM pVM, uint32_t idChunk, PPPGMCHUNKR3MAP ppChunk);
    28462846void            pgmR3PhysRelinkRamRanges(PVM pVM);
     2847int             pgmR3PhysRamPreAllocate(PVM pVM);
    28472848int             pgmR3PhysRamReset(PVM pVM);
    28482849int             pgmR3PhysRomReset(PVM pVM);
     2850int             pgmR3PhysChunkMap(PVM pVM, uint32_t idChunk, PPPGMCHUNKR3MAP ppChunk);
    28492851
    28502852int             pgmR3PoolInit(PVM pVM);
     
    28822884#endif
    28832885
     2886int             pgmR3ExitShadowModeBeforePoolFlush(PVM pVM);
     2887int             pgmR3ReEnterShadowModeAfterPoolFlush(PVM pVM);
     2888
    28842889void            pgmMapSetShadowPDEs(PVM pVM, PPGMMAPPING pMap, unsigned iNewPDE);
    28852890void            pgmMapClearShadowPDEs(PVM pVM, PPGMPOOLPAGE pShwPageCR3, PPGMMAPPING pMap, unsigned iOldPDE, bool fDeactivateCR3);
  • trunk/src/VBox/VMM/PGMPhys.cpp

    r18873 r18880  
    10191019    REMR3NotifyPhysRamRegister(pVM, GCPhys, cb, REM_NOTIFY_PHYS_RAM_FLAGS_RAM);
    10201020
     1021    return VINF_SUCCESS;
     1022}
     1023
     1024
     1025/**
     1026 * Worker called by PGMR3InitFinalize if we're configured to pre-allocate RAM.
     1027 *
     1028 * We do this late in the init process so that all the ROM and MMIO ranges have
     1029 * been registered already and we don't go wasting memory on them.
     1030 *
     1031 * @returns VBox status code.
     1032 *
     1033 * @param   pVM     Pointer to the shared VM structure.
     1034 */
     1035int pgmR3PhysRamPreAllocate(PVM pVM)
     1036{
     1037    Assert(pVM->pgm.s.fRamPreAlloc);
     1038    Log(("pgmR3PhysRamPreAllocate: enter\n"));
     1039
     1040    /*
     1041     * Walk the RAM ranges and allocate all RAM pages, halt at
     1042     * the first allocation error.
     1043     */
     1044    uint64_t cPages = 0;
     1045    uint64_t NanoTS = RTTimeNanoTS();
     1046    pgmLock(pVM);
     1047    for (PPGMRAMRANGE pRam = pVM->pgm.s.pRamRangesR3; pRam; pRam = pRam->pNextR3)
     1048    {
     1049        PPGMPAGE    pPage  = &pRam->aPages[0];
     1050        RTGCPHYS    GCPhys = pRam->GCPhys;
     1051        uint32_t    cLeft  = pRam->cb >> PAGE_SHIFT;
     1052        while (cLeft-- > 0)
     1053        {
     1054            if (PGM_PAGE_GET_TYPE(pPage) == PGMPAGETYPE_RAM)
     1055            {
     1056                switch (PGM_PAGE_GET_STATE(pPage))
     1057                {
     1058                    case PGM_PAGE_STATE_ZERO:
     1059                    {
     1060                        int rc = pgmPhysAllocPage(pVM, pPage, GCPhys);
     1061                        if (RT_FAILURE(rc))
     1062                        {
     1063                            LogRel(("PGM: RAM Pre-allocation failed at %RGp (in %s) with rc=%Rrc\n", GCPhys, pRam->pszDesc, rc));
     1064                            pgmUnlock(pVM);
     1065                            return rc;
     1066                        }
     1067                        cPages++;
     1068                        break;
     1069                    }
     1070
     1071                    case PGM_PAGE_STATE_ALLOCATED:
     1072                    case PGM_PAGE_STATE_WRITE_MONITORED:
     1073                    case PGM_PAGE_STATE_SHARED:
     1074                        /* nothing to do here. */
     1075                        break;
     1076                }
     1077            }
     1078
     1079            /* next */
     1080            pPage++;
     1081            GCPhys += PAGE_SIZE;
     1082        }
     1083    }
     1084    pgmUnlock(pVM);
     1085    NanoTS = RTTimeNanoTS() - NanoTS;
     1086
     1087    LogRel(("PGM: Pre-allocated %llu pages in %llu ms\n", cPages, NanoTS / 1000000));
     1088    Log(("pgmR3PhysRamPreAllocate: returns VINF_SUCCESS\n"));
    10211089    return VINF_SUCCESS;
    10221090}
     
    14891557    int rc = MMR3AdjustFixedReservation(pVM, cPages, pszDesc);
    14901558    if (RT_SUCCESS(rc))
    1491     {   
     1559    {
    14921560        void *pvPages;
    14931561        PSUPPAGE paPages = (PSUPPAGE)RTMemTmpAlloc(cPages * sizeof(SUPPAGE));
     
    14971565        {
    14981566            memset(pvPages, 0, cPages * PAGE_SIZE);
    1499    
     1567
    15001568            /*
    15011569             * Create the MMIO2 range record for it.
     
    15201588                pNew->RamRange.cb           = cb;
    15211589                //pNew->RamRange.fFlags     = 0; /// @todo MMIO2 flag?
    1522    
     1590
    15231591                pNew->RamRange.pvR3         = pvPages;
    1524    
     1592
    15251593                uint32_t iPage = cPages;
    15261594                while (iPage-- > 0)
     
    15301598                                  PGMPAGETYPE_MMIO2, PGM_PAGE_STATE_ALLOCATED);
    15311599                }
    1532    
     1600
    15331601                /* update page count stats */
    15341602                pVM->pgm.s.cAllPages     += cPages;
    15351603                pVM->pgm.s.cPrivatePages += cPages;
    1536    
     1604
    15371605                /*
    15381606                 * Link it into the list.
     
    15411609                pNew->pNextR3 = pVM->pgm.s.pMmio2RangesR3;
    15421610                pVM->pgm.s.pMmio2RangesR3 = pNew;
    1543    
     1611
    15441612                *ppv = pvPages;
    15451613                RTMemTmpFree(paPages);
    15461614                return VINF_SUCCESS;
    15471615            }
    1548    
     1616
    15491617            SUPR3PageFreeEx(pvPages, cPages);
    15501618        }
  • trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp

    r18716 r18880  
    334334 *
    335335 * @remarks This function shouldn't really fail, however if it does
    336  *          it probably means we've screwed up the size of the amount
    337  *          and/or the low-water mark of handy pages. Or, that some
    338  *          device I/O is causing a lot of pages to be allocated while
    339  *          while the host is in a low-memory condition.
     336 *          it probably means we've screwed up the size of handy pages and/or
     337 *          the low-water mark. Or, that some device I/O is causing a lot of
     338 *          pages to be allocated while while the host is in a low-memory
     339 *          condition. This latter should be handled elsewhere and in a more
     340 *          controlled manner, it's on the @bugref{3170} todo list...
    340341 */
    341342int pgmPhysAllocPage(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys)
Note: See TracChangeset for help on using the changeset viewer.

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