VirtualBox

Changeset 37213 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 25, 2011 1:27:48 PM (14 years ago)
Author:
vboxsync
Message:

GMMR0: Harmless changes, I hope.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/GMMR0.cpp

    r37206 r37213  
    165165#include <iprt/mem.h>
    166166#include <iprt/memobj.h>
     167#include <iprt/mp.h>
    167168#include <iprt/semaphore.h>
    168169#include <iprt/string.h>
     
    609610
    610611
     612/**
     613 * Page allocation strategy sketches.
     614 */
     615typedef struct GMMR0ALLOCPAGESTRATEGY
     616{
     617    uint32_t cTries;
     618#if 0
     619    typedef enum GMMR0ALLOCPAGESTRATEGY
     620    {
     621        kGMMR0AllocPageStrategy_Invalid = 0,
     622        kGMMR0AllocPageStrategy_VM,
     623        kGMMR0AllocPageStrategy_NumaNode,
     624        kGMMR0AllocPageStrategy_AnythingGoes,
     625        kGMMR0AllocPageStrategy_End
     626    } GMMR0ALLOCPAGESTRATEGY;
     627#endif
     628} GMMR0ALLOCPAGESTRATEGY;
     629/** Pointer to a page allocation strategy structure. */
     630typedef GMMR0ALLOCPAGESTRATEGY *PGMMR0ALLOCPAGESTRATEGY;
     631
     632
    611633/*******************************************************************************
    612634*   Global Variables                                                           *
     
    11221144
    11231145/**
     1146 * For experimenting with NUMA affinity and such.
     1147 *
     1148 * @returns The current NUMA Node ID.
     1149 */
     1150static uint16_t gmmR0GetCurrentNumaNodeId(void)
     1151{
     1152#if 1
     1153    return GMM_CHUNK_NUMA_ID_UNKNOWN;
     1154#else
     1155    return RTMpCpuId() / 16;
     1156#endif
     1157}
     1158
     1159
     1160
     1161/**
    11241162 * Cleans up when a VM is terminating.
    11251163 *
     
    19341972        pChunk->hGVM        = hGVM;
    19351973        /*pChunk->iFreeHead = 0;*/
    1936         pChunk->idNumaNode  = GMM_CHUNK_NUMA_ID_UNKNOWN;
     1974        pChunk->idNumaNode  = gmmR0GetCurrentNumaNodeId();
    19371975        pChunk->iChunkMtx   = UINT8_MAX;
    19381976        pChunk->fFlags      = fChunkFlags;
     
    20082046    RTR0MEMOBJ hMemObj;
    20092047    int rc = RTR0MemObjAllocPhysNC(&hMemObj, GMM_CHUNK_SIZE, NIL_RTHCPHYS);
    2010     /** @todo Check that RTR0MemObjAllocPhysNC always returns VERR_NO_MEMORY on
    2011      *        allocation failure. */
    20122048    if (RT_SUCCESS(rc))
    20132049    {
     
    20332069 * @param   pSet        Pointer to the free set to grow.
    20342070 * @param   cPages      The number of pages needed.
     2071 * @param   pStrategy   Pointer to the allocation strategy data.  This is input
     2072 *                      and output.
    20352073 *
    20362074 * @remarks Called owning the mutex, but will leave it temporarily while
    20372075 *          allocating the memory!
    20382076 */
    2039 static int gmmR0AllocateMoreChunks(PGMM pGMM, PGVM pGVM, PGMMCHUNKFREESET pSet, uint32_t cPages)
     2077static int gmmR0AllocateMoreChunks(PGMM pGMM, PGVM pGVM, PGMMCHUNKFREESET pSet, uint32_t cPages,
     2078                                   PGMMR0ALLOCPAGESTRATEGY pStrategy)
    20402079{
    20412080    Assert(!pGMM->fLegacyAllocationMode);
     
    20542093        {
    20552094            PGMMCHUNK pChunk = pOtherSet->apLists[RT_ELEMENTS(pOtherSet->apLists) - 1];
    2056             while (pChunk && pChunk->cFree != GMM_CHUNK_NUM_PAGES)
     2095            while (   pChunk
     2096                   && pChunk->cFree != GMM_CHUNK_NUM_PAGES)
    20572097                pChunk = pChunk->pFreeNext;
    20582098            if (!pChunk)
     
    21792219 *                              See GMMPAGEDESC for details on what is expected on input.
    21802220 * @param   enmAccount          The account to charge.
    2181  */
    2182 static int gmmR0AllocatePages(PGMM pGMM, PGVM pGVM, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount)
     2221 * @param   pStrategy           Pointer to the allocation strategy data.  This
     2222 *                              is input and output.
     2223 */
     2224static int gmmR0AllocatePages(PGMM pGMM, PGVM pGVM, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount,
     2225                              PGMMR0ALLOCPAGESTRATEGY pStrategy)
    21832226{
    21842227    /*
     
    21912234    {
    21922235        case GMMACCOUNT_BASE:
    2193             if (RT_UNLIKELY(pGVM->gmm.s.Allocated.cBasePages + pGVM->gmm.s.cBalloonedPages + cPages > pGVM->gmm.s.Reserved.cBasePages))
     2236            if (RT_UNLIKELY(  pGVM->gmm.s.Allocated.cBasePages + pGVM->gmm.s.cBalloonedPages + cPages
     2237                            > pGVM->gmm.s.Reserved.cBasePages))
    21942238            {
    21952239                Log(("gmmR0AllocatePages:Base: Reserved=%#llx Allocated+Ballooned+Requested=%#llx+%#llx+%#x!\n",
     
    22192263
    22202264    /*
    2221      * Check if we need to allocate more memory or not. In bound memory mode this
     2265     * Check if we need to allocate more memory or not.  In bound memory mode this
    22222266     * is a bit extra work but it's easier to do it upfront than bailing out later.
    22232267     */
     
    22252269    if (pSet->cFreePages < cPages)
    22262270        return VERR_GMM_SEED_ME;
     2271
     2272/** @todo Rewrite this to use the page array for storing chunk IDs and other
     2273 *        state info needed to avoid the multipass sillyness. */
    22272274    if (pGMM->fBoundMemoryMode)
    22282275    {
     
    23422389
    23432390    return VINF_SUCCESS;
     2391}
     2392
     2393
     2394/**
     2395 * Determins the initial page allocation strategy and initializes the data
     2396 * structure.
     2397 *
     2398 * @param   pGMM                Pointer to the GMM instance data.
     2399 * @param   pGVM                Pointer to the shared VM structure.
     2400 * @param   pStrategy           The data structure to initialize.
     2401 */
     2402static void gmmR0AllocatePagesInitStrategy(PGMM pGMM, PGVM pGVM, PGMMR0ALLOCPAGESTRATEGY pStrategy)
     2403{
     2404    pStrategy->cTries = 0;
    23442405}
    23452406
     
    25232584             * Note! gmmR0AllocateMoreChunks may leave the protection of the mutex!
    25242585             */
     2586            GMMR0ALLOCPAGESTRATEGY Strategy;
     2587            gmmR0AllocatePagesInitStrategy(pGMM, pGVM, &Strategy);
    25252588            while (RT_SUCCESS(rc))
    25262589            {
    2527                 rc = gmmR0AllocatePages(pGMM, pGVM, cPagesToAlloc, paPages, GMMACCOUNT_BASE);
     2590                rc = gmmR0AllocatePages(pGMM, pGVM, cPagesToAlloc, paPages, GMMACCOUNT_BASE, &Strategy);
    25282591                if (    rc != VERR_GMM_SEED_ME
    25292592                    ||  pGMM->fLegacyAllocationMode)
    25302593                    break;
    2531                 rc = gmmR0AllocateMoreChunks(pGMM, pGVM, &pGMM->Private, cPagesToAlloc);
     2594                rc = gmmR0AllocateMoreChunks(pGMM, pGVM, &pGMM->Private, cPagesToAlloc, &Strategy);
    25322595            }
    25332596        }
     
    26112674             * Note! gmmR0AllocateMoreChunks may leave the protection of the mutex!
    26122675             */
     2676            GMMR0ALLOCPAGESTRATEGY Strategy;
     2677            gmmR0AllocatePagesInitStrategy(pGMM, pGVM, &Strategy);
    26132678            while (RT_SUCCESS(rc))
    26142679            {
    2615                 rc = gmmR0AllocatePages(pGMM, pGVM, cPages, paPages, enmAccount);
     2680                rc = gmmR0AllocatePages(pGMM, pGVM, cPages, paPages, enmAccount, &Strategy);
    26162681                if (    rc != VERR_GMM_SEED_ME
    26172682                    ||  pGMM->fLegacyAllocationMode)
    26182683                    break;
    2619                 rc = gmmR0AllocateMoreChunks(pGMM, pGVM, &pGMM->Private, cPages);
     2684                rc = gmmR0AllocateMoreChunks(pGMM, pGVM, &pGMM->Private, cPages, &Strategy);
    26202685            }
    26212686        }
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