VirtualBox

Changeset 17513 in vbox


Ignore:
Timestamp:
Mar 7, 2009 5:44:48 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43946
Message:

MM,PGM: Fixed page reservation, include a full set of handy pages for the time being. Fixed page counting statistics.

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

Legend:

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

    r17372 r17513  
    322322     * value is 'no overcommitment' (default). See GMMPOLICY.
    323323     */
    324     GMMOCPOLICY enmPolicy;
     324    GMMOCPOLICY enmOcPolicy;
    325325    char sz[64];
    326326    rc = CFGMR3QueryString(CFGMR3GetRoot(pVM), "Policy", sz, sizeof(sz));
     
    329329        if (    !RTStrICmp(sz, "no_oc")
    330330            ||  !RTStrICmp(sz, "no overcommitment"))
    331             enmPolicy = GMMOCPOLICY_NO_OC;
     331            enmOcPolicy = GMMOCPOLICY_NO_OC;
    332332        else
    333333            return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS, "Unknown \"MM/Policy\" value \"%s\"", sz);
    334334    }
    335335    else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    336         enmPolicy = GMMOCPOLICY_NO_OC;
     336        enmOcPolicy = GMMOCPOLICY_NO_OC;
    337337    else
    338338        AssertMsgRCReturn(rc, ("Configuration error: Failed to query string \"MM/Policy\", rc=%Rrc.\n", rc), rc);
     
    364364     * Make the initial memory reservation with GMM.
    365365     */
    366     rc = GMMR3InitialReservation(pVM, cbRam >> PAGE_SHIFT, 1, 1, enmPolicy, enmPriority);
     366    uint64_t cBasePages = (cbRam >> PAGE_SHIFT) + pVM->mm.s.cBasePages;
     367    rc = GMMR3InitialReservation(pVM,
     368                                 RT_MAX(cBasePages + pVM->mm.s.cHandyPages, 1),
     369                                 RT_MAX(pVM->mm.s.cShadowPages, 1),
     370                                 RT_MAX(pVM->mm.s.cFixedPages, 1),
     371                                 enmOcPolicy,
     372                                 enmPriority);
    367373    if (RT_FAILURE(rc))
    368374    {
    369375        if (rc == VERR_GMM_MEMORY_RESERVATION_DECLINED)
    370376            return VMSetError(pVM, rc, RT_SRC_POS,
    371                               N_("Insufficient free memory to start the VM (cbRam=%#RX64 enmPolicy=%d enmPriority=%d)"),
    372                               cbRam, enmPolicy, enmPriority);
     377                              N_("Insufficient free memory to start the VM (cbRam=%#RX64 enmOcPolicy=%d enmPriority=%d)"),
     378                              cbRam, enmOcPolicy, enmPriority);
    373379        return VMSetError(pVM, rc, RT_SRC_POS, "GMMR3InitialReservation(,%#RX64,0,0,%d,%d)",
    374                           cbRam >> PAGE_SHIFT, enmPolicy, enmPriority);
     380                          cbRam >> PAGE_SHIFT, enmOcPolicy, enmPriority);
    375381    }
    376382
     
    409415                rc = PGM3PhysGrowRange(pVM, &GCPhys);
    410416    }
     417#endif
     418
     419#ifdef VBOX_WITH_NEW_PHYS_CODE
     420    /*
     421     * Enabled mmR3UpdateReservation here since we don't want the
     422     * PGMR3PhysRegisterRam calls above mess things up.
     423     */
     424    pVM->mm.s.fDoneMMR3InitPaging = true;
     425    AssertMsg(pVM->mm.s.cBasePages == cBasePages, ("%RX64 != %RX64\n", pVM->mm.s.cBasePages, cBasePages));
    411426#endif
    412427
     
    603618    if (pVM->mm.s.fDoneMMR3InitPaging)
    604619        return GMMR3UpdateReservation(pVM,
    605                                       RT_MAX(pVM->mm.s.cBasePages, 1),
     620                                      RT_MAX(pVM->mm.s.cBasePages + pVM->mm.s.cHandyPages, 1),
    606621                                      RT_MAX(pVM->mm.s.cShadowPages, 1),
    607622                                      RT_MAX(pVM->mm.s.cFixedPages, 1));
     
    627642    if (RT_FAILURE(rc))
    628643    {
    629         VMSetError(pVM, rc, RT_SRC_POS, N_("Failed to reserved physical memory for the RAM (%#RX64 -> %#RX64)"), cOld, pVM->mm.s.cBasePages);
     644        VMSetError(pVM, rc, RT_SRC_POS, N_("Failed to reserved physical memory for the RAM (%#RX64 -> %#RX64 + %#RX32)"),
     645                   cOld, pVM->mm.s.cBasePages, pVM->mm.s.cHandyPages);
    630646        pVM->mm.s.cBasePages = cOld;
     647    }
     648    return rc;
     649}
     650
     651
     652/**
     653 * Interface for PGM to make reservations for handy pages in addition to the
     654 * base memory.
     655 *
     656 * This can be called before MMR3InitPaging.
     657 *
     658 * @returns VBox status code. Will set VM error on failure.
     659 * @param   pVM             The shared VM structure.
     660 * @param   cHandyPages     The number of handy pages.
     661 */
     662VMMR3DECL(int) MMR3ReserveHandyPages(PVM pVM, uint32_t cHandyPages)
     663{
     664    AssertReturn(!pVM->mm.s.cHandyPages, VERR_WRONG_ORDER);
     665
     666    pVM->mm.s.cHandyPages = cHandyPages;
     667    LogFlow(("MMR3ReserveHandyPages: %RU32 (base %RU64)\n", pVM->mm.s.cHandyPages, pVM->mm.s.cBasePages));
     668    int rc = mmR3UpdateReservation(pVM);
     669    if (RT_FAILURE(rc))
     670    {
     671        VMSetError(pVM, rc, RT_SRC_POS, N_("Failed to reserved physical memory for the RAM (%#RX64 + %#RX32)"),
     672                   pVM->mm.s.cBasePages, pVM->mm.s.cHandyPages);
     673        pVM->mm.s.cHandyPages = 0;
    631674    }
    632675    return rc;
  • trunk/src/VBox/VMM/MMInternal.h

    r17251 r17513  
    762762     *          what the guest sees. */
    763763    uint64_t                    cBasePages;
     764    /** The number of handy pages that PGM has reserved (GMM).
     765     * These are kept out of cBasePages and thus out of the saved state. */
     766    uint32_t                    cHandyPages;
    764767    /** The number of shadow pages PGM has reserved (GMM). */
    765768    uint32_t                    cShadowPages;
    766769    /** The number of fixed pages we've reserved (GMM). */
    767770    uint32_t                    cFixedPages;
     771    /** Padding. */
     772    uint32_t                    u32Padding0;
    768773
    769774#ifndef VBOX_WITH_NEW_PHYS_CODE
  • trunk/src/VBox/VMM/PGM.cpp

    r17498 r17513  
    12541254    PGMPhysInvalidatePageR0MapTLB(pVM);
    12551255    PGMPhysInvalidatePageGCMapTLB(pVM);
     1256
     1257#ifdef VBOX_WITH_NEW_PHYS_CODE
     1258    /*
     1259     * For the time being we sport a full set of handy pages in addition to the base
     1260     * memory to simplify things.
     1261     */
     1262    rc = MMR3ReserveHandyPages(pVM, RT_ELEMENTS(pVM->pgm.s.aHandyPages));
     1263    AssertRCReturn(rc, rc);
     1264#endif
    12561265
    12571266    /*
     
    16221631    STAM_REG(pVM, &pPGM->cSharedPages,                      STAMTYPE_U32,     "/PGM/Page/cSharedPages",             STAMUNIT_OCCURENCES,     "The number of shared pages.");
    16231632    STAM_REG(pVM, &pPGM->cZeroPages,                        STAMTYPE_U32,     "/PGM/Page/cZeroPages",               STAMUNIT_OCCURENCES,     "The number of zero backed pages.");
     1633    STAM_REG(pVM, &pPGM->cHandyPages,                       STAMTYPE_U32,     "/PGM/Page/cHandyPages",              STAMUNIT_OCCURENCES,     "The number of handy pages (not included in cAllPages).");
    16241634    STAM_REG(pVM, &pPGM->ChunkR3Map.c,                      STAMTYPE_U32,     "/PGM/ChunkR3Map/c",                      STAMUNIT_OCCURENCES, "Number of mapped chunks.");
    16251635    STAM_REG(pVM, &pPGM->ChunkR3Map.cMax,                   STAMTYPE_U32,     "/PGM/ChunkR3Map/cMax",                   STAMUNIT_OCCURENCES, "Maximum number of mapped chunks.");
     
    16461656    STAM_REG(pVM, &pPGM->StatR3GuestPDWrite,                STAMTYPE_COUNTER, "/PGM/R3/PDWrite",                    STAMUNIT_OCCURENCES,     "The total number of times pgmHCGuestPDWriteHandler() was called.");
    16471657    STAM_REG(pVM, &pPGM->StatR3GuestPDWriteConflict,        STAMTYPE_COUNTER, "/PGM/R3/PDWriteConflict",            STAMUNIT_OCCURENCES,     "The number of times pgmHCGuestPDWriteHandler() detected a conflict.");
     1658#ifndef VBOX_WITH_NEW_PHYS_CODE
    16481659    STAM_REG(pVM, &pPGM->StatR3DynRamTotal,                 STAMTYPE_COUNTER, "/PGM/DynAlloc/TotalAlloc",           STAMUNIT_MEGABYTES,      "Allocated MBs of guest ram.");
    16491660    STAM_REG(pVM, &pPGM->StatR3DynRamGrow,                  STAMTYPE_COUNTER, "/PGM/DynAlloc/Grow",                 STAMUNIT_OCCURENCES,     "Nr of pgmr3PhysGrowRange calls.");
     1661#endif
    16501662
    16511663    /* R0 only: */
  • trunk/src/VBox/VMM/PGMInternal.h

    r17511 r17513  
    27852785    STAMCOUNTER StatR3GuestPDWrite;                 /**< R3: The total number of times pgmHCGuestPDWriteHandler() was called. */
    27862786    STAMCOUNTER StatR3GuestPDWriteConflict;         /**< R3: The number of times GuestPDWriteContlict() detected a conflict. */
     2787#ifndef VBOX_WITH_NEW_PHYS_CODE
    27872788    STAMCOUNTER StatR3DynRamTotal;                  /**< R3: Allocated MBs of guest ram */
    27882789    STAMCOUNTER StatR3DynRamGrow;                   /**< R3: Nr of pgmr3PhysGrowRange calls. */
     2790#endif
    27892791
    27902792    /* R0 only: */
  • trunk/src/VBox/VMM/PGMPhys.cpp

    r17510 r17513  
    519519    while (iPage-- > 0)
    520520        PGM_PAGE_INIT_ZERO(&pNew->aPages[iPage], pVM, PGMPAGETYPE_RAM);
     521
     522    /* Update the page count stats. */
     523    pVM->pgm.s.cZeroPages += cPages;
     524    pVM->pgm.s.cAllPages  += cPages;
    521525
    522526    /*
     
    785789        Assert(PGM_PAGE_GET_TYPE(&pNew->aPages[0]) == PGMPAGETYPE_MMIO);
    786790
     791        /* update the page count stats. */
     792        pVM->pgm.s.cZeroPages += cPages;
     793        pVM->pgm.s.cAllPages  += cPages;
     794
    787795        /* link it */
    788796        pgmR3PhysLinkRamRange(pVM, pNew, pRamPrev);
     
    803811        pNew->cb = pNew->GCPhys = pNew->GCPhysLast = NIL_RTGCPHYS;
    804812        MMHyperFree(pVM, pRam);
     813        pVM->pgm.s.cZeroPages -= cb >> PAGE_SHIFT;
     814        pVM->pgm.s.cAllPages  -= cb >> PAGE_SHIFT;
    805815    }
    806816
     
    854864                    {
    855865                        fAllMMIO = false;
     866                        Assert(PGM_PAGE_GET_TYPE(pPage) != PGMPAGETYPE_MMIO2_ALIAS_MMIO);
    856867                        break;
    857868                    }
     869                    Assert(PGM_PAGE_IS_ZERO(pPage));
    858870                    pPage++;
    859871                }
     
    870882                    pRam->cb = pRam->GCPhys = pRam->GCPhysLast = NIL_RTGCPHYS;
    871883                    MMHyperFree(pVM, pRam);
     884                    pVM->pgm.s.cAllPages -= pRam->cb >> PAGE_SHIFT;
     885                    pVM->pgm.s.cZeroPages -= pRam->cb >> PAGE_SHIFT;
    872886                }
    873887                break;
     
    10031017            }
    10041018
     1019            /* update page count stats */
     1020            pVM->pgm.s.cAllPages     += cPages;
     1021            pVM->pgm.s.cPrivatePages += cPages;
     1022
    10051023            /*
    10061024             * Link it into the list.
     
    10841102                rc = rc2;
    10851103
    1086             rc2 = MMR3AdjustFixedReservation(pVM, -(int32_t)(pCur->RamRange.cb >> PAGE_SHIFT), pCur->RamRange.pszDesc);
     1104            uint32_t const cPages = pCur->RamRange.cb >> PAGE_SHIFT;
     1105            rc2 = MMR3AdjustFixedReservation(pVM, -(int32_t)cPages, pCur->RamRange.pszDesc);
    10871106            AssertRC(rc2);
    10881107            if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
     
    10961115            /*rc = MMHyperFree(pVM, pCur);
    10971116            AssertRCReturn(rc, rc); - not safe, see the alloc call. */
     1117
     1118
     1119            /* update page count stats */
     1120            pVM->pgm.s.cAllPages     -= cPages;
     1121            pVM->pgm.s.cPrivatePages -= cPages;
    10981122
    10991123            /* next */
     
    12181242            PGM_PAGE_SET_STATE(pPageDst, PGM_PAGE_STATE_ALLOCATED);
    12191243
     1244            pVM->pgm.s.cZeroPages--;
    12201245            GCPhys += PAGE_SIZE;
    12211246            pPageSrc++;
     
    12941319            PGM_PAGE_SET_PAGEID(pPageDst, NIL_GMM_PAGEID);
    12951320
     1321            pVM->pgm.s.cZeroPages++;
    12961322            pPageDst++;
    12971323        }
     
    16101636                }
    16111637
     1638                pVM->pgm.s.cAllPages += cPages;
    16121639                pgmR3PhysLinkRamRange(pVM, pRamNew, pRamPrev);
    16131640            }
     
    16261653
    16271654                pRamNew = pRam;
     1655
     1656                pVM->pgm.s.cZeroPages -= cPages;
    16281657            }
     1658            pVM->pgm.s.cPrivatePages += cPages;
     1659
    16291660            pgmUnlock(pVM);
    16301661
     
    17041735                    }
    17051736
     1737                    /* update the page count stats */
     1738                    pVM->pgm.s.cZeroPages += cPages;
     1739                    pVM->pgm.s.cAllPages  += cPages;
     1740
    17061741                    /*
    17071742                     * Insert the ROM range, tell REM and return successfully.
     
    18611896             * out all the dirty pages and replace them by the zero page.
    18621897             */
    1863             if (1)///@todo !pVM->pgm.f.fRamPreAlloc)
     1898            if (!pVM->pgm.s.fRamPreAlloc)
    18641899            {
    18651900                /* Count dirty shadow pages. */
     
    18801915                        if (PGM_PAGE_GET_STATE(&pRom->aPages[iPage].Shadow) != PGM_PAGE_STATE_ZERO)
    18811916                        {
     1917                            Assert(PGM_PAGE_GET_STATE(&pRom->aPages[iPage].Shadow) == PGM_PAGE_STATE_ALLOCATED);
    18821918                            pReq->aPages[iReqPage].idPage = PGM_PAGE_GET_PAGEID(&pRom->aPages[iPage].Shadow);
    18831919                            iReqPage++;
     
    18921928                        if (PGM_PAGE_GET_STATE(&pRom->aPages[iPage].Shadow) != PGM_PAGE_STATE_ZERO)
    18931929                            PGM_PAGE_INIT_ZERO_REAL(&pRom->aPages[iPage].Shadow, pVM, PGMPAGETYPE_ROM_SHADOW);
     1930
     1931                    /* update the page count stats. */
     1932                    pVM->pgm.s.cPrivatePages -= cDirty;
     1933                    pVM->pgm.s.cZeroPages    += cDirty;
    18941934                }
    18951935            }
     
    18991939                for (uint32_t iPage = 0; iPage < cPages; iPage++)
    19001940                {
     1941                    Assert(PGM_PAGE_GET_STATE(&pRom->aPages[iPage].Shadow) != PGM_PAGE_STATE_ZERO);
     1942
    19011943                    const RTGCPHYS GCPhys = pRom->GCPhys + (iPage << PAGE_SHIFT);
    19021944                    rc = pgmPhysPageMakeWritable(pVM, &pRom->aPages[iPage].Shadow, GCPhys);
     
    28202862    }
    28212863
     2864    /* update page count stats. */
     2865    if (PGM_PAGE_IS_SHARED(pPage))
     2866        pVM->pgm.s.cSharedPages--;
     2867    else
     2868        pVM->pgm.s.cPrivatePages--;
     2869    pVM->pgm.s.cZeroPages++;
     2870
    28222871    /*
    28232872     * pPage = ZERO page.
  • trunk/src/VBox/VMM/testcase/tstVMStructGC.cpp

    r17487 r17513  
    225225    GEN_CHECK_OFF(MM, cbRamBase);
    226226    GEN_CHECK_OFF(MM, cBasePages);
     227    GEN_CHECK_OFF(MM, cHandyPages);
    227228    GEN_CHECK_OFF(MM, cShadowPages);
    228229    GEN_CHECK_OFF(MM, cFixedPages);
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