GMM.cpp revision 30868e719f5a45ec4689ecb2616767cb1fd02c28
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * GMM - Global Memory Manager, ring-3 request wrappers.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 2008 Sun Microsystems, Inc.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * This file is part of VirtualBox Open Source Edition (OSE), as
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * available from http://www.virtualbox.org. This file is free software;
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * you can redistribute it and/or modify it under the terms of the GNU
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * General Public License (GPL) as published by the Free Software
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Foundation, in version 2 as it comes in the "COPYING" file of the
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f41f183f628a148860a6d1f0070208cddd45b0c6Bob Halley * Clara, CA 95054 USA or visit http://www.sun.com if you need
f41f183f628a148860a6d1f0070208cddd45b0c6Bob Halley * additional information or have any questions.
9a2127f8335bad323451d7825119cd9f72e32464Mark Andrews/*******************************************************************************
9a2127f8335bad323451d7825119cd9f72e32464Mark Andrews* Header Files *
9a2127f8335bad323451d7825119cd9f72e32464Mark Andrews*******************************************************************************/
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @see GMMR0InitialReservation
b6d52ee5bea1b9d9074698e693b49ce96edff47bMark AndrewsGMMR3DECL(int) GMMR3InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
b6d52ee5bea1b9d9074698e693b49ce96edff47bMark Andrews GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews return VMMR3CallR0(pVM, VMMR0_DO_GMM_INITIAL_RESERVATION, 0, &Req.Hdr);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * @see GMMR0UpdateReservation
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsGMMR3DECL(int) GMMR3UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return VMMR3CallR0(pVM, VMMR0_DO_GMM_UPDATE_RESERVATION, 0, &Req.Hdr);
5c6762838c9e423753723ec2a963164e3d66ac32Mark Andrews * Prepares a GMMR0AllocatePages request.
5c6762838c9e423753723ec2a963164e3d66ac32Mark Andrews * @returns VINF_SUCCESS or VERR_NO_TMP_MEMORY.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param pVM Pointer to the shared VM structure.
fc80027fb54b501cdd88461bf879d078259e0226David Lawrence * @param[out] ppReq Where to store the pointer to the request packet.
37dee1ff94960a61243f611c0f87f8c316815c53Mark Andrews * @param cPages The number of pages that's to be allocated.
37dee1ff94960a61243f611c0f87f8c316815c53Mark Andrews * @param enmAccount The account to charge.
76117ff568dc788ed24937cfea916a18db285960Mark AndrewsGMMR3DECL(int) GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount)
494576ce20cfd98d74955698cf8f7b37dce2f740Mark Andrews uint32_t cb = RT_OFFSETOF(GMMALLOCATEPAGESREQ, aPages[cPages]);
76117ff568dc788ed24937cfea916a18db285960Mark Andrews PGMMALLOCATEPAGESREQ pReq = (PGMMALLOCATEPAGESREQ)RTMemTmpAllocZ(cb);
18d110413cf6416eb339c169b99159d09f690da1Brian Wellington * Performs a GMMR0AllocatePages request.
494576ce20cfd98d74955698cf8f7b37dce2f740Mark Andrews * This will call VMSetError on failure.
494576ce20cfd98d74955698cf8f7b37dce2f740Mark Andrews * @returns VBox status code.
4fd3e3482c7e4ce01e2cf28f13e0152c8e50d746Mark Andrews * @param pVM Pointer to the shared VM structure.
4fd3e3482c7e4ce01e2cf28f13e0152c8e50d746Mark Andrews * @param pReq Pointer to the request (returned by GMMR3AllocatePagesPrepare).
d2b5fe92a4755ce67f2dd6050955782b4fd6b3f3Mark AndrewsGMMR3DECL(int) GMMR3AllocatePagesPerform(PVM pVM, PGMMALLOCATEPAGESREQ pReq)
d2b5fe92a4755ce67f2dd6050955782b4fd6b3f3Mark Andrews for (unsigned i = 0; ; i++)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley int rc = VMMR3CallR0(pVM, VMMR0_DO_GMM_ALLOCATE_PAGES, 0, &pReq->Hdr);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley for (uint32_t iPage = 0; iPage < pReq->cPages; iPage++)
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley Log3(("GMMR3AllocatePagesPerform: idPage=%#x HCPhys=%RHp\n",
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley pReq->aPages[iPage].idPage, pReq->aPages[iPage].HCPhysGCPhys));
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley N_("GMMR0AllocatePages failed to allocate %u pages"),
881702c9c0079cd48a45054fd90d043f3a8b7e11Mark Andrews * Seed another chunk.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley rc = SUPR3PageAlloc(GMM_CHUNK_SIZE >> PAGE_SHIFT, &pvChunk);
922e6a3c2ac4ef900dd9dc99f0cc137f18372583Andreas Gustafsson N_("Out of memory (SUPR3PageAlloc) seeding a %u pages allocation request"),
74cb99072c4b0ebd2ccafcfa284288fa760f7a1aMark Andrews rc = VMMR3CallR0(pVM, VMMR0_DO_GMM_SEED_CHUNK, (uintptr_t)pvChunk, NULL);
4880900113e4d0f17884f3fbdbf4c302e3f9ea91Bob Halley return VMSetError(pVM, rc, RT_SRC_POS, N_("GMM seeding failed"));
6ef838d427c1ea858d2f09194a369134babf8b98Mark Andrews * Cleans up a GMMR0AllocatePages request.
6ef838d427c1ea858d2f09194a369134babf8b98Mark Andrews * @param pReq Pointer to the request (returned by GMMR3AllocatePagesPrepare).
6d831cd0baf7dd2c133f7f9cbf295f3d80cf63a7David LawrenceGMMR3DECL(void) GMMR3AllocatePagesCleanup(PGMMALLOCATEPAGESREQ pReq)
6d7585b3e948dd31bf78321d83ac0e024f44a71bMark Andrews * Prepares a GMMR0FreePages request.
6d5dcd0dc9bdbd679282b1ffc47987d24c3a1346Bob Halley * @returns VINF_SUCCESS or VERR_NO_TMP_MEMORY.
6d7585b3e948dd31bf78321d83ac0e024f44a71bMark Andrews * @param pVM Pointer to the shared VM structure.
1471a520e59ac12b413afa8d8b3158a87af97aa6Bob Halley * @param[out] ppReq Where to store the pointer to the request packet.
1471a520e59ac12b413afa8d8b3158a87af97aa6Bob Halley * @param cPages The number of pages that's to be freed.
1471a520e59ac12b413afa8d8b3158a87af97aa6Bob Halley * @param enmAccount The account to charge.
1471a520e59ac12b413afa8d8b3158a87af97aa6Bob HalleyGMMR3DECL(int) GMMR3FreePagesPrepare(PVM pVM, PGMMFREEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount)
4fd3e3482c7e4ce01e2cf28f13e0152c8e50d746Mark Andrews uint32_t cb = RT_OFFSETOF(GMMFREEPAGESREQ, aPages[cPages]);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews PGMMFREEPAGESREQ pReq = (PGMMFREEPAGESREQ)RTMemTmpAllocZ(cb);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * Re-prepares a GMMR0FreePages request.
GMMR3DECL(void) GMMR3FreePagesRePrep(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t cPages, GMMACCOUNT enmAccount)
if (!cActualPages)
return VINF_SUCCESS;
return rc;
while (iPage-- > 0)
GMMR3DECL(int) GMMR3BalloonedPages(PVM pVM, uint32_t cBalloonedPages, uint32_t cPagesToFree, PGMMFREEPAGEDESC paPages, bool fCompleted)
GMMR3DECL(int) GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3)
return rc;