VirtualBox

Ignore:
Timestamp:
Dec 11, 2019 11:56:54 PM (5 years ago)
Author:
vboxsync
Message:

PGMPool,MM: Use ring-0 mapping while in ring-0, so let the page pool do its own allocations rather than going through MMPage*. The MMPage* code is mostly code, but we still need it for a dummy page allocation. I'll address this tomorrow. bugref:9528

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PGMPool.cpp

    r80334 r82555  
    170170    AssertLogRelMsgReturn(cMaxPages <= PGMPOOL_IDX_LAST && cMaxPages >= RT_ALIGN(PGMPOOL_IDX_FIRST, 16),
    171171                          ("cMaxPages=%u (%#x)\n", cMaxPages, cMaxPages), VERR_INVALID_PARAMETER);
    172     cMaxPages = RT_ALIGN(cMaxPages, 16);
     172    AssertCompile(RT_IS_POWER_OF_TWO(PGMPOOL_CFG_MAX_GROW));
     173    if (cMaxPages < PGMPOOL_IDX_LAST)
     174        cMaxPages = RT_ALIGN(cMaxPages, PGMPOOL_CFG_MAX_GROW / 2);
    173175    if (cMaxPages > PGMPOOL_IDX_LAST)
    174176        cMaxPages = PGMPOOL_IDX_LAST;
     
    314316    Assert(!pPool->aPages[NIL_PGMPOOL_IDX].fReusedFlushPending);
    315317
    316 #ifdef VBOX_WITH_STATISTICS
    317318    /*
    318319     * Register statistics.
    319320     */
     321    STAM_REL_REG(pVM, &pPool->StatGrow,                 STAMTYPE_PROFILE,   "/PGM/Pool/Grow",           STAMUNIT_TICKS, "Profiling PGMR0PoolGrow");
     322#ifdef VBOX_WITH_STATISTICS
    320323    STAM_REG(pVM, &pPool->cCurPages,                    STAMTYPE_U16,       "/PGM/Pool/cCurPages",      STAMUNIT_PAGES,             "Current pool size.");
    321324    STAM_REG(pVM, &pPool->cMaxPages,                    STAMTYPE_U16,       "/PGM/Pool/cMaxPages",      STAMUNIT_PAGES,             "Max pool size.");
     
    473476 * @returns VBox status code.
    474477 * @param   pVM     The cross context VM structure.
     478 * @param   pVCpu   The cross context virtual CPU structure of the calling EMT.
    475479 */
    476 VMMR3DECL(int) PGMR3PoolGrow(PVM pVM)
     480VMMR3_INT_DECL(int) PGMR3PoolGrow(PVM pVM, PVMCPU pVCpu)
    477481{
    478     PPGMPOOL pPool = pVM->pgm.s.pPoolR3;
    479     AssertReturn(pPool->cCurPages < pPool->cMaxPages, VERR_PGM_POOL_MAXED_OUT_ALREADY);
    480 
    481     /* With 32-bit guests and no EPT, the CR3 limits the root pages to low
    482        (below 4 GB) memory. */
    483     /** @todo change the pool to handle ROOT page allocations specially when
    484      *        required. */
    485     bool fCanUseHighMemory = HMIsNestedPagingActive(pVM);
    486 
    487     pgmLock(pVM);
    488 
    489     /*
    490      * How much to grow it by?
    491      */
    492     uint32_t cPages = pPool->cMaxPages - pPool->cCurPages;
    493     cPages = RT_MIN(PGMPOOL_CFG_MAX_GROW, cPages);
    494     LogFlow(("PGMR3PoolGrow: Growing the pool by %d (%#x) pages. fCanUseHighMemory=%RTbool\n", cPages, cPages, fCanUseHighMemory));
    495 
    496     for (unsigned i = pPool->cCurPages; cPages-- > 0; i++)
    497     {
    498         PPGMPOOLPAGE pPage = &pPool->aPages[i];
    499 
    500         if (fCanUseHighMemory)
    501             pPage->pvPageR3 = MMR3PageAlloc(pVM);
    502         else
    503             pPage->pvPageR3 = MMR3PageAllocLow(pVM);
    504         if (!pPage->pvPageR3)
    505         {
    506             Log(("We're out of memory!! i=%d fCanUseHighMemory=%RTbool\n", i, fCanUseHighMemory));
    507             pgmUnlock(pVM);
    508             return i ? VINF_SUCCESS : VERR_NO_PAGE_MEMORY;
    509         }
    510         pPage->Core.Key  = MMPage2Phys(pVM, pPage->pvPageR3);
    511         AssertFatal(pPage->Core.Key < _4G || fCanUseHighMemory);
    512         pPage->GCPhys    = NIL_RTGCPHYS;
    513         pPage->enmKind   = PGMPOOLKIND_FREE;
    514         pPage->idx       = pPage - &pPool->aPages[0];
    515         LogFlow(("PGMR3PoolGrow: insert page #%#x - %RHp\n", pPage->idx, pPage->Core.Key));
    516         pPage->iNext     = pPool->iFreeHead;
    517         pPage->iUserHead = NIL_PGMPOOL_USER_INDEX;
    518         pPage->iModifiedNext  = NIL_PGMPOOL_IDX;
    519         pPage->iModifiedPrev  = NIL_PGMPOOL_IDX;
    520         pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
    521         pPage->iMonitoredPrev = NIL_PGMPOOL_IDX;
    522         pPage->iAgeNext  = NIL_PGMPOOL_IDX;
    523         pPage->iAgePrev  = NIL_PGMPOOL_IDX;
    524         /* commit it */
    525         bool fRc = RTAvloHCPhysInsert(&pPool->HCPhysTree, &pPage->Core); Assert(fRc); NOREF(fRc);
    526         pPool->iFreeHead = i;
    527         pPool->cCurPages = i + 1;
    528     }
    529 
    530     pgmUnlock(pVM);
    531     Assert(pPool->cCurPages <= pPool->cMaxPages);
    532     return VINF_SUCCESS;
     482    /* This used to do a lot of stuff, but it has moved to ring-0 (PGMR0PoolGrow). */
     483    AssertReturn(pVM->pgm.s.pPoolR3->cCurPages < pVM->pgm.s.pPoolR3->cMaxPages, VERR_PGM_POOL_MAXED_OUT_ALREADY);
     484    return VMMR3CallR0Emt(pVM, pVCpu, VMMR0_DO_PGM_POOL_GROW, 0, NULL);
    533485}
    534486
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