VirtualBox

Changeset 97925 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Dec 30, 2022 11:00:05 PM (2 years ago)
Author:
vboxsync
Message:

Add/VBoxGuestR0LibPhysHeap.cpp: Use the term 'unlink' rather than 'exclude' for removing a block/chunk from a linked list. Docs updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibPhysHeap.cpp

    r97924 r97925  
    3636
    3737#include <iprt/assert.h>
     38#include <iprt/err.h>
     39#include <iprt/mem.h>
    3840#include <iprt/semaphore.h>
    39 #include <iprt/alloc.h>
    4041
    4142/** @page pg_vbglr0_phys_heap   VBoxGuestLibR0 - Physical memory heap.
     
    4647 * (VBGLDATA::pFreeBlocksHead) doubly linked lists.
    4748 *
    48  * When allocating a block, we search in Free linked list for a suitable free
    49  * block.  If there is no such block, a new chunk is allocated and the new block
    50  * is taken from the new chunk as the only chunk-sized free block. Allocated
    51  * 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 Alloc
    54  * list and move it to free 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 at
    58  * 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.
    5960 *
    6061 * 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.
    6365 */
    6466
     
    298300 * This also update the per-chunk block counts.
    299301 */
    300 static void vbglPhysHeapExcludeBlock(VBGLPHYSHEAPBLOCK *pBlock)
     302static void vbglPhysHeapUnlinkBlock(VBGLPHYSHEAPBLOCK *pBlock)
    301303{
    302304    bool const fAllocated = pBlock->fAllocated;
     
    401403    VBGL_PH_dprintf(("Deleting chunk %p size %x\n", pChunk, pChunk->cbSize));
    402404
    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 */
    404406
    405407    uEnd = (uintptr_t)pChunk + pChunk->cbSize;
     
    412414        uCur += pBlock->cbDataSize + sizeof(VBGLPHYSHEAPBLOCK);
    413415
    414         vbglPhysHeapExcludeBlock(pBlock);
     416        vbglPhysHeapUnlinkBlock(pBlock);
    415417    }
    416418
    417419    VBGL_PH_ASSERT_MSG(uCur == uEnd, ("uCur = %p, uEnd = %p, pChunk->cbSize = %08X\n", uCur, uEnd, pChunk->cbSize));
    418420
    419     /* Exclude chunk from the chunk list */
     421    /* Unlink the chunk from the chunk list. */
    420422    if (pChunk->pNext)
    421423        pChunk->pNext->pPrev = pChunk->pPrev;
     
    548550         * it in the allocated list.
    549551         */
    550         vbglPhysHeapExcludeBlock(pBlock);
     552        vbglPhysHeapUnlinkBlock(pBlock);
    551553        pBlock->fAllocated = true;
    552554        vbglPhysHeapInsertBlock(NULL, pBlock);
     
    619621             */
    620622            VBGL_PH_dprintf(("VbglR0PhysHeapFree: %p size %#x\n", pv, pBlock->cbDataSize));
    621             vbglPhysHeapExcludeBlock(pBlock);
    622 
    623             dumpheap("post exclude");
     623            vbglPhysHeapUnlinkBlock(pBlock);
     624
     625            dumpheap("post unlink");
    624626
    625627            pBlock->fAllocated = false;
     
    648650
    649651                /* Unlink the following node and invalid it. */
    650                 vbglPhysHeapExcludeBlock(pNeighbour);
     652                vbglPhysHeapUnlinkBlock(pNeighbour);
    651653
    652654                pNeighbour->u32Signature = ~VBGL_PH_BLOCKSIGNATURE;
     
    673675                        if (cUnusedChunks > 1)
    674676                        {
    675                             /* Delete current chunk, it will also exclude all free blocks
     677                            /* Delete current chunk, it will also unlink all free blocks
    676678                             * remaining in the chunk from the free list, so the pBlock
    677679                             * will also be invalid after this.
     
    851853    if (pBlock)
    852854        return RTSemFastMutexCreate(&g_vbgldata.mutexHeap);
    853     return VERR_NO_MEMORY;
     855    return VERR_NO_CONT_MEMORY;
    854856}
    855857
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