VirtualBox

Changeset 97919 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Dec 30, 2022 4:57:42 PM (2 years ago)
Author:
vboxsync
Message:

Add/VBoxGuestR0LibPhysHeap.cpp: Reduced the size of VBGLPHYSHEAPBLOCK: 64-bit: 40 -> 32 bytes; 32-bit: 24 -> 20 bytes.

File:
1 edited

Legend:

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

    r97918 r97919  
    105105*   Structures and Typedefs                                                                                                      *
    106106*********************************************************************************************************************************/
     107/**
     108 * A heap block (within a chunk).
     109 *
     110 * This is used to track a part of a heap chunk that's either free or
     111 * allocated.  The VBGLPHYSHEAPBLOCK::fAllocated member indicates which it is.
     112 */
    107113struct VBGLPHYSHEAPBLOCK
    108114{
     
    111117
    112118    /** Size of user data in the block. Does not include this block header. */
    113     uint32_t cbDataSize;
    114 
    115     uint32_t fu32Flags;
    116 
     119    uint32_t cbDataSize : 31;
     120    /** The top bit indicates whether it's allocated or free. */
     121    uint32_t fAllocated : 1;
     122
     123    /** Pointer to the next block on the list. */
    117124    VBGLPHYSHEAPBLOCK  *pNext;
     125    /** Pointer to the previous block on the list. */
    118126    VBGLPHYSHEAPBLOCK  *pPrev;
    119 
     127    /** Pointer back to the chunk. */
    120128    VBGLPHYSHEAPCHUNK  *pChunk;
    121129};
    122130
     131/**
     132 * A chunk of memory used by the heap for sub-allocations.
     133 *
     134 * There is a list of these.
     135 */
    123136struct VBGLPHYSHEAPCHUNK
    124137{
     
    135148    int32_t cAllocatedBlocks;
    136149
     150    /** Pointer to the next chunk. */
    137151    VBGLPHYSHEAPCHUNK  *pNext;
     152    /** Pointer to the previous chunk. */
    138153    VBGLPHYSHEAPCHUNK  *pPrev;
    139154};
     
    165180   while (pBlock)
    166181   {
    167        VBGL_PH_dprintf(("%p: pNext = %p, pPrev = %p, sign = %08X, size = %8d, flags = %08X, pChunk = %p\n",
    168                         pBlock, pBlock->pNext, pBlock->pPrev, pBlock->u32Signature, pBlock->cbDataSize, pBlock->fu32Flags, pBlock->pChunk));
     182       VBGL_PH_dprintf(("%p: pNext = %p, pPrev = %p, sign = %08X, size = %8d, %s, pChunk = %p\n",
     183                        pBlock, pBlock->pNext, pBlock->pPrev, pBlock->u32Signature, pBlock->cbDataSize,
     184                        pBlock->fAllocated ? "allocated" : "free", pBlock->pChunk));
    169185
    170186       pBlock = pBlock->pNext;
     
    177193   while (pBlock)
    178194   {
    179        VBGL_PH_dprintf(("%p: pNext = %p, pPrev = %p, sign = %08X, size = %8d, flags = %08X, pChunk = %p\n",
    180                         pBlock, pBlock->pNext, pBlock->pPrev, pBlock->u32Signature, pBlock->cbDataSize, pBlock->fu32Flags, pBlock->pChunk));
     195       VBGL_PH_dprintf(("%p: pNext = %p, pPrev = %p, sign = %08X, size = %8d, %s, pChunk = %p\n",
     196                        pBlock, pBlock->pNext, pBlock->pPrev, pBlock->u32Signature, pBlock->cbDataSize,
     197                        pBlock->fAllocated ? "allocated" : "free", pBlock->pChunk));
    181198
    182199       pBlock = pBlock->pNext;
     
    233250    pBlock->u32Signature = VBGL_PH_BLOCKSIGNATURE;
    234251    pBlock->cbDataSize   = cbDataSize;
    235     pBlock->fu32Flags    = 0;
     252    pBlock->fAllocated   = false;
    236253    pBlock->pNext        = NULL;
    237254    pBlock->pPrev        = NULL;
     
    260277        pBlock->pPrev = NULL;
    261278
    262         if (pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED)
     279        if (pBlock->fAllocated)
    263280        {
    264281            pBlock->pNext = g_vbgldata.pAllocBlocksHead;
     
    293310    if (pBlock->pPrev)
    294311        pBlock->pPrev->pNext = pBlock->pNext;
    295     else if (pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED)
     312    else if (pBlock->fAllocated)
    296313    {
    297314        Assert(g_vbgldata.pAllocBlocksHead == pBlock);
     
    487504        VBGL_PH_ASSERT_MSG(pBlock->u32Signature == VBGL_PH_BLOCKSIGNATURE,
    488505                           ("pBlock = %p, pBlock->u32Signature = %08X\n", pBlock, pBlock->u32Signature));
    489         VBGL_PH_ASSERT_MSG((pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED) == 0,
    490                            ("pBlock = %p, pBlock->fu32Flags = %08X\n", pBlock, pBlock->fu32Flags));
     506        VBGL_PH_ASSERT_MSG(!pBlock->fAllocated, ("pBlock = %p\n", pBlock));
    491507
    492508        /* We have a free block, either found or allocated. */
     
    512528
    513529        /* Mark as allocated */
    514         pBlock->fu32Flags |= VBGL_PH_BF_ALLOCATED;
     530        pBlock->fAllocated = true;
    515531
    516532        /* Insert to allocated list */
     
    536552    if (pBlock)
    537553    {
    538         VBGL_PH_ASSERT_MSG((pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED) != 0,
    539                            ("pBlock = %p, pBlock->fu32Flags = %08X\n", pBlock, pBlock->fu32Flags));
    540 
    541         if (pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED)
     554        VBGL_PH_ASSERT_MSG(pBlock->fAllocated, ("pBlock = %p\n", pBlock));
     555
     556        if (pBlock->fAllocated)
    542557            physAddr = pBlock->pChunk->physAddr + (uint32_t)((uintptr_t)pv - (uintptr_t)pBlock->pChunk);
    543558    }
     
    566581    }
    567582
    568     VBGL_PH_ASSERT_MSG((pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED) != 0,
    569                        ("pBlock = %p, pBlock->fu32Flags = %08X\n", pBlock, pBlock->fu32Flags));
     583    VBGL_PH_ASSERT_MSG(pBlock->fAllocated, ("pBlock = %p\n", pBlock));
    570584
    571585    /* Exclude from allocated list */
     
    577591
    578592    /* Mark as free */
    579     pBlock->fu32Flags &= ~VBGL_PH_BF_ALLOCATED;
     593    pBlock->fAllocated = false;
    580594
    581595    /* Insert to free list */
     
    603617
    604618    if (   (uintptr_t)pNeighbour < (uintptr_t)pChunk + pChunk->cbSize
    605         && (pNeighbour->fu32Flags & VBGL_PH_BF_ALLOCATED) == 0)
     619        && !pNeighbour->fAllocated)
    606620    {
    607621        /* The next block is free as well. */
     
    701715                         RTErrInfoSetF(pErrInfo, VERR_INTERNAL_ERROR_3,
    702716                                       "pCurBlock=%p: cbDataSize=%#x\n", pCurBlock, pCurBlock->cbDataSize));
    703             AssertReturn(   pCurBlock->fu32Flags <= VBGL_PH_BF_ALLOCATED,
    704                          RTErrInfoSetF(pErrInfo, VERR_INTERNAL_ERROR_3,
    705                                        "pCurBlock=%p: fu32Flags=%#x\n", pCurBlock, pCurBlock->fu32Flags));
    706             if (pCurBlock->fu32Flags & VBGL_PH_BF_ALLOCATED)
     717            if (pCurBlock->fAllocated)
    707718                cUsedBlocks += 1;
    708719            else
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