VirtualBox

Changeset 29646 in vbox for trunk/src/VBox/VMM/PGMPhys.cpp


Ignore:
Timestamp:
May 18, 2010 3:44:08 PM (15 years ago)
Author:
vboxsync
Message:

Proper shared page cleanup when terminating the VM

File:
1 edited

Legend:

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

    r29626 r29646  
    15361536}
    15371537
     1538/**
     1539 * Frees all RAM during VM termination
     1540 *
     1541 * ASSUMES that the caller owns the PGM lock.
     1542 *
     1543 * @returns VBox status code.
     1544 * @param   pVM     Pointer to the shared VM structure.
     1545 */
     1546int pgmR3PhysRamTerm(PVM pVM)
     1547{
     1548    Assert(PGMIsLockOwner(pVM));
     1549
     1550    /* Reset the memory balloon. */
     1551    int rc = GMMR3BalloonedPages(pVM, GMMBALLOONACTION_RESET, 0);
     1552    AssertRC(rc);
     1553
     1554#ifdef VBOX_WITH_PAGE_SHARING
     1555    /* Clear all registered shared modules. */
     1556    rc = GMMR3ResetSharedModules(pVM);
     1557    AssertRC(rc);
     1558#endif
     1559
     1560    /*
     1561     * We batch up pages that should be freed instead of calling GMM for
     1562     * each and every one of them.
     1563     */
     1564    uint32_t            cPendingPages = 0;
     1565    PGMMFREEPAGESREQ    pReq;
     1566    rc = GMMR3FreePagesPrepare(pVM, &pReq, PGMPHYS_FREE_PAGE_BATCH_SIZE, GMMACCOUNT_BASE);
     1567    AssertLogRelRCReturn(rc, rc);
     1568
     1569    /*
     1570     * Walk the ram ranges.
     1571     */
     1572    for (PPGMRAMRANGE pRam = pVM->pgm.s.pRamRangesR3; pRam; pRam = pRam->pNextR3)
     1573    {
     1574        uint32_t iPage = pRam->cb >> PAGE_SHIFT;
     1575        AssertMsg(((RTGCPHYS)iPage << PAGE_SHIFT) == pRam->cb, ("%RGp %RGp\n", (RTGCPHYS)iPage << PAGE_SHIFT, pRam->cb));
     1576
     1577        /* Replace all RAM pages by ZERO pages. */
     1578        while (iPage-- > 0)
     1579        {
     1580            PPGMPAGE pPage = &pRam->aPages[iPage];
     1581            switch (PGM_PAGE_GET_TYPE(pPage))
     1582            {
     1583                case PGMPAGETYPE_RAM:
     1584                    /* Free all shared pages. Private pages are automatically freed during GMM VM cleanup. */
     1585                    if (PGM_PAGE_IS_SHARED(pPage))
     1586                    {
     1587                        rc = pgmPhysFreePage(pVM, pReq, &cPendingPages, pPage, pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT));
     1588                        AssertLogRelRCReturn(rc, rc);
     1589                    }
     1590                    break;
     1591
     1592                case PGMPAGETYPE_MMIO2_ALIAS_MMIO:
     1593                case PGMPAGETYPE_MMIO2:
     1594                case PGMPAGETYPE_ROM_SHADOW: /* handled by pgmR3PhysRomReset. */
     1595                case PGMPAGETYPE_ROM:
     1596                case PGMPAGETYPE_MMIO:
     1597                    break;
     1598                default:
     1599                    AssertFailed();
     1600            }
     1601        } /* for each page */
     1602    }
     1603
     1604    /*
     1605     * Finish off any pages pending freeing.
     1606     */
     1607    if (cPendingPages)
     1608    {
     1609        rc = GMMR3FreePagesPerform(pVM, pReq, cPendingPages);
     1610        AssertLogRelRCReturn(rc, rc);
     1611    }
     1612    GMMR3FreePagesCleanup(pReq);
     1613    return VINF_SUCCESS;
     1614}
    15381615
    15391616/**
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