VirtualBox

Ignore:
Timestamp:
Sep 10, 2007 3:38:23 PM (17 years ago)
Author:
vboxsync
Message:

Use a different allocation method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxGuest/VBoxGuest.cpp

    r4667 r4673  
    457457        for (uint32_t i=pDevExt->MemBalloon.cBalloons;i<u32BalloonSize;i++)
    458458        {
     459#ifndef TARGET_NT4
     460            /*
     461             * Use MmAllocatePagesForMdl to specify the range of physical addresses we wish to use.
     462             */
     463            PHYSICAL_ADDRESS Zero;
     464            PHYSICAL_ADDRESS HighAddr;
     465            Zero.QuadPart = 0;
     466            HighAddr.QuadPart = _4G - 1;
     467            PMDL pMdl = MmAllocatePagesForMdl(Zero, HighAddr, Zero, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE);
     468            if (pMdl)
     469            {
     470                if (MmGetMdlByteCount(pMdl) < VMMDEV_MEMORY_BALLOON_CHUNK_SIZE)
     471                {
     472                    MmFreePagesFromMdl(pMdl);
     473                    ExFreePool(pMdl);
     474                    rc = VERR_NO_MEMORY;
     475                    goto end;
     476                }
     477            }
     478#else
    459479            PVOID pvBalloon;
    460 
    461480            pvBalloon = ExAllocatePoolWithTag(PagedPool, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE, 'MBAL');
    462481            if (!pvBalloon)
     
    482501                __except(EXCEPTION_EXECUTE_HANDLER)
    483502                {
     503                    Log(("MmProbeAndLockPages failed!\n"));
    484504                    rc = VERR_NO_MEMORY;
    485505                    IoFreeMdl (pMdl);
     
    488508                }
    489509            }
     510#endif
    490511
    491512            PPFN_NUMBER pPageDesc = MmGetMdlPfnArray(pMdl);
     
    505526                         "rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc));
    506527
     528#ifndef TARGET_NT4
     529                MmFreePagesFromMdl(pMdl);
     530                ExFreePool(pMdl);
     531#else
    507532                IoFreeMdl (pMdl);
    508533                ExFreePoolWithTag(pvBalloon, 'MBAL');
     534#endif
    509535                goto end;
    510536            }
    511537            else
    512538            {
    513                 dprintf(("VBoxGuest::VBoxGuestSetBalloonSize added 1 MB chunk at %x\n", pvBalloon));
     539#ifndef TARGET_NT4
     540                dprintf(("VBoxGuest::VBoxGuestSetBalloonSize %d MB added chunk at %x\n", i, pMdl));
     541#else
     542                dprintf(("VBoxGuest::VBoxGuestSetBalloonSize %d MB added chunk at %x\n", i, pvBalloon));
     543#endif
    514544                pDevExt->MemBalloon.paMdlMemBalloon[i] = pMdl;
    515545                pDevExt->MemBalloon.cBalloons++;
     
    522552        for (uint32_t i=pDevExt->MemBalloon.cBalloons-1;i>=u32BalloonSize;i--)
    523553        {
    524             PMDL  pMdl      = pDevExt->MemBalloon.paMdlMemBalloon[i];
    525             PVOID pvBalloon = MmGetMdlVirtualAddress(pMdl);
    526 
    527             PPFN_NUMBER pPageDesc = MmGetMdlPfnArray(pMdl);
    528 
    529             /* Copy manually as RTGCPHYS is always 64 bits */
    530             for (uint32_t j=0;j<VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;j++)
    531                 req->aPhysPage[j] = pPageDesc[j];
    532 
    533             req->header.size = RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[VMMDEV_MEMORY_BALLOON_CHUNK_PAGES]);
    534             req->cPages      = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;
    535             req->fInflate    = false;
    536 
    537             rc = VbglGRPerform(&req->header);
    538             if (VBOX_FAILURE(rc) || VBOX_FAILURE(req->header.rc))
    539             {
    540                 AssertMsgFailed(("VBoxGuest::VBoxGuestSetBalloonSize: error issuing request to VMMDev! rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc));
    541                 /* ignore error and just continue; this should never fail */
    542             }
    543 
    544             dprintf(("VBoxGuest::VBoxGuestSetBalloonSize free 1 MB chunk at %x\n", pvBalloon));
    545 
    546             /* Free the ballooned memory */
    547             MmUnlockPages (pMdl);
    548             IoFreeMdl (pMdl);
    549             ExFreePoolWithTag(pvBalloon, 'MBAL');
    550 
    551             pDevExt->MemBalloon.paMdlMemBalloon[i] = NULL;
    552             pDevExt->MemBalloon.cBalloons--;
     554            PMDL  pMdl = pDevExt->MemBalloon.paMdlMemBalloon[i];
     555
     556            Assert(pMdl);
     557            if (pMdl)
     558            {
     559                PVOID pvBalloon = MmGetMdlVirtualAddress(pMdl);
     560
     561                PPFN_NUMBER pPageDesc = MmGetMdlPfnArray(pMdl);
     562
     563                /* Copy manually as RTGCPHYS is always 64 bits */
     564                for (uint32_t j=0;j<VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;j++)
     565                    req->aPhysPage[j] = pPageDesc[j];
     566
     567                req->header.size = RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[VMMDEV_MEMORY_BALLOON_CHUNK_PAGES]);
     568                req->cPages      = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;
     569                req->fInflate    = false;
     570
     571                rc = VbglGRPerform(&req->header);
     572                if (VBOX_FAILURE(rc) || VBOX_FAILURE(req->header.rc))
     573                {
     574                    AssertMsgFailed(("VBoxGuest::VBoxGuestSetBalloonSize: error issuing request to VMMDev! rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc));
     575                    break;
     576                }
     577
     578                dprintf(("VBoxGuest::VBoxGuestSetBalloonSize %d MB free chunk at %x\n", i, pvBalloon));
     579
     580                /* Free the ballooned memory */
     581#ifndef TARGET_NT4
     582                MmFreePagesFromMdl(pMdl);
     583                ExFreePool(pMdl);
     584#else
     585                MmUnlockPages (pMdl);
     586                IoFreeMdl (pMdl);
     587                ExFreePoolWithTag(pvBalloon, 'MBAL');
     588#endif
     589
     590                pDevExt->MemBalloon.paMdlMemBalloon[i] = NULL;
     591                pDevExt->MemBalloon.cBalloons--;
     592            }
    553593        }
    554594    }
     
    593633
    594634            rc = VBoxGuestSetBalloonSize(pDevExt, req->u32BalloonSize);
     635            /* ignore out of memory failures */
     636            if (rc == VERR_NO_MEMORY)
     637                rc = VINF_SUCCESS;
     638
    595639            if (pMemBalloonSize)
    596640                *pMemBalloonSize = pDevExt->MemBalloon.cBalloons;
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