Changeset 37213 in vbox for trunk/src/VBox
- Timestamp:
- May 25, 2011 1:27:48 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR0/GMMR0.cpp
r37206 r37213 165 165 #include <iprt/mem.h> 166 166 #include <iprt/memobj.h> 167 #include <iprt/mp.h> 167 168 #include <iprt/semaphore.h> 168 169 #include <iprt/string.h> … … 609 610 610 611 612 /** 613 * Page allocation strategy sketches. 614 */ 615 typedef 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. */ 630 typedef GMMR0ALLOCPAGESTRATEGY *PGMMR0ALLOCPAGESTRATEGY; 631 632 611 633 /******************************************************************************* 612 634 * Global Variables * … … 1122 1144 1123 1145 /** 1146 * For experimenting with NUMA affinity and such. 1147 * 1148 * @returns The current NUMA Node ID. 1149 */ 1150 static 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 /** 1124 1162 * Cleans up when a VM is terminating. 1125 1163 * … … 1934 1972 pChunk->hGVM = hGVM; 1935 1973 /*pChunk->iFreeHead = 0;*/ 1936 pChunk->idNumaNode = GMM_CHUNK_NUMA_ID_UNKNOWN;1974 pChunk->idNumaNode = gmmR0GetCurrentNumaNodeId(); 1937 1975 pChunk->iChunkMtx = UINT8_MAX; 1938 1976 pChunk->fFlags = fChunkFlags; … … 2008 2046 RTR0MEMOBJ hMemObj; 2009 2047 int rc = RTR0MemObjAllocPhysNC(&hMemObj, GMM_CHUNK_SIZE, NIL_RTHCPHYS); 2010 /** @todo Check that RTR0MemObjAllocPhysNC always returns VERR_NO_MEMORY on2011 * allocation failure. */2012 2048 if (RT_SUCCESS(rc)) 2013 2049 { … … 2033 2069 * @param pSet Pointer to the free set to grow. 2034 2070 * @param cPages The number of pages needed. 2071 * @param pStrategy Pointer to the allocation strategy data. This is input 2072 * and output. 2035 2073 * 2036 2074 * @remarks Called owning the mutex, but will leave it temporarily while 2037 2075 * allocating the memory! 2038 2076 */ 2039 static int gmmR0AllocateMoreChunks(PGMM pGMM, PGVM pGVM, PGMMCHUNKFREESET pSet, uint32_t cPages) 2077 static int gmmR0AllocateMoreChunks(PGMM pGMM, PGVM pGVM, PGMMCHUNKFREESET pSet, uint32_t cPages, 2078 PGMMR0ALLOCPAGESTRATEGY pStrategy) 2040 2079 { 2041 2080 Assert(!pGMM->fLegacyAllocationMode); … … 2054 2093 { 2055 2094 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) 2057 2097 pChunk = pChunk->pFreeNext; 2058 2098 if (!pChunk) … … 2179 2219 * See GMMPAGEDESC for details on what is expected on input. 2180 2220 * @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 */ 2224 static int gmmR0AllocatePages(PGMM pGMM, PGVM pGVM, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount, 2225 PGMMR0ALLOCPAGESTRATEGY pStrategy) 2183 2226 { 2184 2227 /* … … 2191 2234 { 2192 2235 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)) 2194 2238 { 2195 2239 Log(("gmmR0AllocatePages:Base: Reserved=%#llx Allocated+Ballooned+Requested=%#llx+%#llx+%#x!\n", … … 2219 2263 2220 2264 /* 2221 * Check if we need to allocate more memory or not. In bound memory mode this2265 * Check if we need to allocate more memory or not. In bound memory mode this 2222 2266 * is a bit extra work but it's easier to do it upfront than bailing out later. 2223 2267 */ … … 2225 2269 if (pSet->cFreePages < cPages) 2226 2270 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. */ 2227 2274 if (pGMM->fBoundMemoryMode) 2228 2275 { … … 2342 2389 2343 2390 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 */ 2402 static void gmmR0AllocatePagesInitStrategy(PGMM pGMM, PGVM pGVM, PGMMR0ALLOCPAGESTRATEGY pStrategy) 2403 { 2404 pStrategy->cTries = 0; 2344 2405 } 2345 2406 … … 2523 2584 * Note! gmmR0AllocateMoreChunks may leave the protection of the mutex! 2524 2585 */ 2586 GMMR0ALLOCPAGESTRATEGY Strategy; 2587 gmmR0AllocatePagesInitStrategy(pGMM, pGVM, &Strategy); 2525 2588 while (RT_SUCCESS(rc)) 2526 2589 { 2527 rc = gmmR0AllocatePages(pGMM, pGVM, cPagesToAlloc, paPages, GMMACCOUNT_BASE );2590 rc = gmmR0AllocatePages(pGMM, pGVM, cPagesToAlloc, paPages, GMMACCOUNT_BASE, &Strategy); 2528 2591 if ( rc != VERR_GMM_SEED_ME 2529 2592 || pGMM->fLegacyAllocationMode) 2530 2593 break; 2531 rc = gmmR0AllocateMoreChunks(pGMM, pGVM, &pGMM->Private, cPagesToAlloc );2594 rc = gmmR0AllocateMoreChunks(pGMM, pGVM, &pGMM->Private, cPagesToAlloc, &Strategy); 2532 2595 } 2533 2596 } … … 2611 2674 * Note! gmmR0AllocateMoreChunks may leave the protection of the mutex! 2612 2675 */ 2676 GMMR0ALLOCPAGESTRATEGY Strategy; 2677 gmmR0AllocatePagesInitStrategy(pGMM, pGVM, &Strategy); 2613 2678 while (RT_SUCCESS(rc)) 2614 2679 { 2615 rc = gmmR0AllocatePages(pGMM, pGVM, cPages, paPages, enmAccount );2680 rc = gmmR0AllocatePages(pGMM, pGVM, cPages, paPages, enmAccount, &Strategy); 2616 2681 if ( rc != VERR_GMM_SEED_ME 2617 2682 || pGMM->fLegacyAllocationMode) 2618 2683 break; 2619 rc = gmmR0AllocateMoreChunks(pGMM, pGVM, &pGMM->Private, cPages );2684 rc = gmmR0AllocateMoreChunks(pGMM, pGVM, &pGMM->Private, cPages, &Strategy); 2620 2685 } 2621 2686 }
Note:
See TracChangeset
for help on using the changeset viewer.