Changeset 97925 in vbox for trunk/src/VBox/Additions/common
- Timestamp:
- Dec 30, 2022 11:00:05 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibPhysHeap.cpp
r97924 r97925 36 36 37 37 #include <iprt/assert.h> 38 #include <iprt/err.h> 39 #include <iprt/mem.h> 38 40 #include <iprt/semaphore.h> 39 #include <iprt/alloc.h>40 41 41 42 /** @page pg_vbglr0_phys_heap VBoxGuestLibR0 - Physical memory heap. … … 46 47 * (VBGLDATA::pFreeBlocksHead) doubly linked lists. 47 48 * 48 * When allocating a block, we search in Free linked list for a suitable free49 * block. If there is no such block, a new chunk is allocated and the new block50 * is taken from the new chunk as the only chunk-sized free block. Allocated51 * block is excluded from the Free list and goes to Alloc list.52 * 53 * When freeing block, we check the pointer and then exclude block from Alloc54 * list and move it tofree list.55 * 56 * For each chunk we maintain the allocated blocks counter . If 2 (or more)57 * entire chunks are free they are immediately deallocated, so we always have at58 * most 1 free chunk.49 * When allocating a block, we search the free list for a suitable free block. 50 * If there is no such block, a new chunk is allocated and the new block is 51 * taken from the new chunk as the only chunk-sized free block. The allocated 52 * block is unlinked from the free list and goes to alloc list. 53 * 54 * When freeing block, we check the pointer and then unlink the block from the 55 * alloc list and move it to the free list. 56 * 57 * For each chunk we maintain the allocated blocks counter (as well as a count 58 * of free blocks). If 2 (or more) entire chunks are free they are immediately 59 * deallocated, so we always have at most 1 free chunk. 59 60 * 60 61 * When freeing blocks, two subsequent free blocks are always merged together. 61 * Current implementation merges blocks only when there is a block after the 62 * just freed one. 62 * Current implementation merges blocks only when there is a free block after 63 * the just freed one, never when there is one before it as that's too 64 * expensive. 63 65 */ 64 66 … … 298 300 * This also update the per-chunk block counts. 299 301 */ 300 static void vbglPhysHeap ExcludeBlock(VBGLPHYSHEAPBLOCK *pBlock)302 static void vbglPhysHeapUnlinkBlock(VBGLPHYSHEAPBLOCK *pBlock) 301 303 { 302 304 bool const fAllocated = pBlock->fAllocated; … … 401 403 VBGL_PH_dprintf(("Deleting chunk %p size %x\n", pChunk, pChunk->cbSize)); 402 404 403 /* first scan the chunk and exclude (unlink)all blocks from the lists */405 /* first scan the chunk and unlink all blocks from the lists */ 404 406 405 407 uEnd = (uintptr_t)pChunk + pChunk->cbSize; … … 412 414 uCur += pBlock->cbDataSize + sizeof(VBGLPHYSHEAPBLOCK); 413 415 414 vbglPhysHeap ExcludeBlock(pBlock);416 vbglPhysHeapUnlinkBlock(pBlock); 415 417 } 416 418 417 419 VBGL_PH_ASSERT_MSG(uCur == uEnd, ("uCur = %p, uEnd = %p, pChunk->cbSize = %08X\n", uCur, uEnd, pChunk->cbSize)); 418 420 419 /* Exclude chunk from the chunk list*/421 /* Unlink the chunk from the chunk list. */ 420 422 if (pChunk->pNext) 421 423 pChunk->pNext->pPrev = pChunk->pPrev; … … 548 550 * it in the allocated list. 549 551 */ 550 vbglPhysHeap ExcludeBlock(pBlock);552 vbglPhysHeapUnlinkBlock(pBlock); 551 553 pBlock->fAllocated = true; 552 554 vbglPhysHeapInsertBlock(NULL, pBlock); … … 619 621 */ 620 622 VBGL_PH_dprintf(("VbglR0PhysHeapFree: %p size %#x\n", pv, pBlock->cbDataSize)); 621 vbglPhysHeap ExcludeBlock(pBlock);622 623 dumpheap("post exclude");623 vbglPhysHeapUnlinkBlock(pBlock); 624 625 dumpheap("post unlink"); 624 626 625 627 pBlock->fAllocated = false; … … 648 650 649 651 /* Unlink the following node and invalid it. */ 650 vbglPhysHeap ExcludeBlock(pNeighbour);652 vbglPhysHeapUnlinkBlock(pNeighbour); 651 653 652 654 pNeighbour->u32Signature = ~VBGL_PH_BLOCKSIGNATURE; … … 673 675 if (cUnusedChunks > 1) 674 676 { 675 /* Delete current chunk, it will also excludeall free blocks677 /* Delete current chunk, it will also unlink all free blocks 676 678 * remaining in the chunk from the free list, so the pBlock 677 679 * will also be invalid after this. … … 851 853 if (pBlock) 852 854 return RTSemFastMutexCreate(&g_vbgldata.mutexHeap); 853 return VERR_NO_ MEMORY;855 return VERR_NO_CONT_MEMORY; 854 856 } 855 857
Note:
See TracChangeset
for help on using the changeset viewer.