VirtualBox

Ignore:
Timestamp:
Mar 14, 2007 3:45:32 AM (18 years ago)
Author:
vboxsync
Message:

Partial fix for the VirtualBox startup hang - don't allocate contiguous memory when a normal allocation will do (128KB for the page pool was almost choking the kernel at times). TODO: put the VM structure on a diet or convert it to a low non-contiguous memory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp

    r394 r1460  
    8181    switch (pMemDarwin->Core.enmType)
    8282    {
     83        case RTR0MEMOBJTYPE_LOW:
    8384        case RTR0MEMOBJTYPE_PAGE:
    8485            IOFreeAligned(pMemDarwin->Core.pv, pMemDarwin->Core.cb);
    8586            break;
    86 
    87         /*case RTR0MEMOBJTYPE_LOW: => RTR0MEMOBJTYPE_CONT
    88             break;*/
    8987
    9088        case RTR0MEMOBJTYPE_CONT:
     
    168166int rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
    169167{
     168#if 1
     169    /*
     170     * Allocating 128KB for the low page pool can bit a bit exhausting on the kernel,
     171     * it frequnetly causes the entire box to lock up on startup.
     172     *
     173     * So, try allocate the memory using IOMallocAligned first and if we get any high
     174     * physical memory we'll release it and fall back on IOMAllocContiguous.
     175     */
     176    int rc = VERR_NO_PAGE_MEMORY;
     177    AssertCompile(sizeof(IOPhysicalAddress) == 4);
     178    void *pv = IOMallocAligned(cb, PAGE_SIZE);
     179    if (pv)
     180    {
     181        IOMemoryDescriptor *pMemDesc = IOMemoryDescriptor::withAddress((vm_address_t)pv, cb, kIODirectionInOut, kernel_task);
     182        if (pMemDesc)
     183        {
     184            /*
     185             * Check if it's all below 4GB.
     186             */
     187            for (IOByteCount off = 0; off < cb; off += PAGE_SIZE)
     188            {
     189                addr64_t Addr = pMemDesc->getPhysicalSegment64(off, NULL);
     190                if (Addr > (uint32_t)(_4G - PAGE_SIZE))
     191                {
     192                    /* Ok, we failed, fall back on contiguous allocation. */
     193                    pMemDesc->release();
     194                    IOFreeAligned(pv, cb);
     195                    return rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable);
     196                }
     197            }
     198
     199            /*
     200             * Create the IPRT memory object.
     201             */
     202            PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)rtR0MemObjNew(sizeof(*pMemDarwin), RTR0MEMOBJTYPE_LOW, pv, cb);
     203            if (pMemDarwin)
     204            {
     205                pMemDarwin->pMemDesc = pMemDesc;
     206                *ppMem = &pMemDarwin->Core;
     207                return VINF_SUCCESS;
     208            }
     209
     210            rc = VERR_NO_MEMORY;
     211            pMemDesc->release();
     212        }
     213        else
     214            rc = VERR_MEMOBJ_INIT_FAILED;
     215        IOFreeAligned(pv, cb);
     216    }
     217    return rc;
     218
     219#else
     220
    170221    /*
    171222     * IOMallocContiguous is the most suitable API.
    172223     */
    173224    return rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable);
     225#endif
    174226}
    175227
     
    289341
    290342    /*
    291      * Just in case IOMallocContigus doesn't work right, we can try fall back
     343     * Just in case IOMallocContiguous doesn't work right, we can try fall back
    292344     * on a contiguous allcation.
    293345     */
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