VirtualBox

Changeset 37195 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 24, 2011 2:00:32 PM (14 years ago)
Author:
vboxsync
Message:

GMMR0: Set list selection function (no real change)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/GMMR0.cpp

    r37193 r37195  
    468468/** The GMMCHUNK::cFree shift count. */
    469469#define GMM_CHUNK_FREE_SET_SHIFT    4
    470 /** The GMMCHUNK::cFree mask for use when considering relinking a chunk. */
    471 #define GMM_CHUNK_FREE_SET_MASK     15
    472 /** The number of lists in set. */
    473 #define GMM_CHUNK_FREE_SET_LISTS    (GMM_CHUNK_NUM_PAGES >> GMM_CHUNK_FREE_SET_SHIFT)
    474470
    475471
     
    485481    uint64_t            idGeneration;
    486482    /** Chunks ordered by increasing number of free pages. */
    487     PGMMCHUNK           apLists[GMM_CHUNK_FREE_SET_LISTS];
     483    PGMMCHUNK           apLists[GMM_CHUNK_NUM_PAGES >> GMM_CHUNK_FREE_SET_SHIFT];
    488484} GMMCHUNKFREESET;
    489485
     
    17061702
    17071703/**
     1704 * Selects the appropriate free list given the number of free pages.
     1705 *
     1706 * @returns Free list index.
     1707 * @param
     1708 */
     1709DECLINLINE(unsigned) gmmR0SelectFreeSetList(unsigned cFree)
     1710{
     1711    return (cFree - 1) >> GMM_CHUNK_FREE_SET_SHIFT;
     1712}
     1713
     1714
     1715/**
    17081716 * Unlinks the chunk from the free list it's currently on (if any).
    17091717 *
     
    17231731            pPrev->pFreeNext = pNext;
    17241732        else
    1725             pSet->apLists[(pChunk->cFree - 1) >> GMM_CHUNK_FREE_SET_SHIFT] = pNext;
     1733            pSet->apLists[gmmR0SelectFreeSetList(pChunk->cFree)] = pNext;
    17261734        if (pNext)
    17271735            pNext->pFreePrev = pPrev;
     
    17581766        pChunk->pSet = pSet;
    17591767        pChunk->pFreePrev = NULL;
    1760         unsigned iList = (pChunk->cFree - 1) >> GMM_CHUNK_FREE_SET_SHIFT;
     1768        unsigned const iList = gmmR0SelectFreeSetList(pChunk->cFree);
    17611769        pChunk->pFreeNext = pSet->apLists[iList];
    17621770        if (pChunk->pFreeNext)
     
    19871995               &&   pOtherSet->cFreePages >= GMM_CHUNK_NUM_PAGES)
    19881996        {
    1989             PGMMCHUNK pChunk = pOtherSet->apLists[GMM_CHUNK_FREE_SET_LISTS - 1];
     1997            PGMMCHUNK pChunk = pOtherSet->apLists[RT_ELEMENTS(pOtherSet->apLists) - 1];
    19901998            while (pChunk && pChunk->cFree != GMM_CHUNK_NUM_PAGES)
    19911999                pChunk = pChunk->pFreeNext;
     
    29102918     * and relink the chunk if necessary.
    29112919     */
    2912     if ((pChunk->cFree & GMM_CHUNK_FREE_SET_MASK) == 0)
     2920    if (gmmR0SelectFreeSetList(pChunk->cFree) != gmmR0SelectFreeSetList(pChunk->cFree + 1))
    29132921    {
    29142922        gmmR0UnlinkChunk(pChunk);
     
    29202928        pChunk->cFree++;
    29212929        pChunk->pSet->cFreePages++;
    2922 
    2923         /*
    2924          * If the chunk becomes empty, consider giving memory back to the host OS.
    2925          *
    2926          * The current strategy is to try give it back if there are other chunks
    2927          * in this free list, meaning if there are at least 240 free pages in this
    2928          * category. Note that since there are probably mappings of the chunk,
    2929          * it won't be freed up instantly, which probably screws up this logic
    2930          * a bit...
    2931          */
    2932         if (RT_UNLIKELY(   pChunk->cFree == GMM_CHUNK_NUM_PAGES
    2933                         && pChunk->pFreeNext
    2934                         && pChunk->pFreePrev /** @todo this is probably misfiring, see reset... */
    2935                         && !pGMM->fLegacyAllocationMode))
    2936             gmmR0FreeChunk(pGMM, NULL, pChunk);
    2937     }
     2930    }
     2931
     2932    /*
     2933     * If the chunk becomes empty, consider giving memory back to the host OS.
     2934     *
     2935     * The current strategy is to try give it back if there are other chunks
     2936     * in this free list, meaning if there are at least 240 free pages in this
     2937     * category. Note that since there are probably mappings of the chunk,
     2938     * it won't be freed up instantly, which probably screws up this logic
     2939     * a bit...
     2940     */
     2941    if (RT_UNLIKELY(   pChunk->cFree == GMM_CHUNK_NUM_PAGES
     2942                    && pChunk->pFreeNext
     2943                    && pChunk->pFreePrev /** @todo this is probably misfiring, see reset... */
     2944                    && !pGMM->fLegacyAllocationMode))
     2945        gmmR0FreeChunk(pGMM, NULL, pChunk);
     2946
    29382947}
    29392948
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