VirtualBox

Ignore:
Timestamp:
Dec 31, 2022 1:23:33 AM (2 years ago)
Author:
vboxsync
Message:

Add/VBoxGuestR0LibPhysHeap.cpp: Modified the free list search to stop when it encounters a free block so large it will probably be quicker to just split it than hope to find a perfect-ish free list match.

File:
1 edited

Legend:

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

    r97927 r97928  
    102102 */
    103103#define VBGL_PH_MAX_FREE_SEARCH         16
     104
     105/** Threshold to stop the block search if a free block is at least this much too big.
     106 *
     107 * May cause more fragmation (depending on usage pattern), but should speed up
     108 * allocation and hopefully reduce cache trashing.
     109 *
     110 * Since we merge adjacent free blocks when we can, free blocks should typically
     111 * be a lot larger that what's requested.  So, it is probably a good idea to
     112 * just chop up a large block rather than keep searching for a perfect-ish
     113 * match.
     114 *
     115 * Undefine this to disable this trick.
     116 */
     117#if defined(DOXYGEN_RUNNING) || 1
     118# define VBGL_PH_STOP_SEARCH_AT_EXCESS   _4K
     119#endif
    104120
    105121/** Threshold at which to split out a tail free block when allocating.
     
    490506    VBGLPHYSHEAPBLOCK *pIter;
    491507    int32_t            cLeft;
     508#ifdef VBGL_PH_STOP_SEARCH_AT_EXCESS
     509    uint32_t           cbAlwaysSplit;
     510#endif
    492511    int                rc;
    493512
     
    498517    AssertStmt(cbSize > 0, cbSize = sizeof(void *));  /* avoid allocating zero bytes */
    499518
    500 
    501519    rc = RTSemFastMutexRequest(g_vbgldata.mutexHeap);
    502520    AssertRCReturn(rc, NULL);
     
    508526     * there to be many blocks in the heap.
    509527     */
    510     cLeft  = VBGL_PH_MAX_FREE_SEARCH;
    511     pBlock = NULL;
     528#ifdef VBGL_PH_STOP_SEARCH_AT_EXCESS
     529    cbAlwaysSplit = cbSize + VBGL_PH_STOP_SEARCH_AT_EXCESS;
     530#endif
     531    cLeft         = VBGL_PH_MAX_FREE_SEARCH;
     532    pBlock        = NULL;
    512533    if (cbSize <= PAGE_SIZE / 4 * 3)
    513534    {
     
    534555                        pFallback = pIter;
    535556                    if (PAGE_SIZE - ((uintptr_t)(pIter + 1) & PAGE_OFFSET_MASK) >= cbSize)
     557                    {
    536558                        if (!pBlock || pIter->cbDataSize < pBlock->cbDataSize)
    537559                            pBlock = pIter;
     560#ifdef VBGL_PH_STOP_SEARCH_AT_EXCESS
     561                        else if (pIter->cbDataSize >= cbAlwaysSplit)
     562                        {
     563                            pBlock = pIter;
     564                            break;
     565                        }
     566#endif
     567                    }
    538568                }
    539569
     
    563593                }
    564594
     595#ifdef VBGL_PH_STOP_SEARCH_AT_EXCESS
     596                if (pIter->cbDataSize >= cbAlwaysSplit)
     597                {
     598                    /* Really big block - no point continue searching! */
     599                    pBlock = pIter;
     600                    break;
     601                }
     602#endif
    565603                /* Looking for a free block with nearest size. */
    566604                if (!pBlock || pIter->cbDataSize < pBlock->cbDataSize)
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