VirtualBox

Changeset 32430 in vbox


Ignore:
Timestamp:
Sep 11, 2010 4:06:37 PM (14 years ago)
Author:
vboxsync
Message:

VD: Little experiment to speed up booting from a high latency storage medium (iSCSI over a WAN network for example) by

increasing small reads and saving the result in a temporary buffer. Subsequent reads can then be served from the buffer
avoiding to read from the medium.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r32277 r32430  
    174174    /** Target image index for merging. */
    175175    unsigned            uMergeTarget;
     176
     177    /** Flag whether boot acceleration is enabled. */
     178    bool                fBootAccelEnabled;
     179    /** Flag whether boot acceleration is currently active. */
     180    bool                fBootAccelActive;
     181    /** Size of the disk, used for read truncation. */
     182    size_t              cbDisk;
     183    /** Size of the configured buffer. */
     184    size_t              cbBootAccelBuffer;
     185    /** Start offset for which the buffer holds data. */
     186    uint64_t            offDisk;
     187    /** Number of valid bytes in the buffer. */
     188    size_t              cbDataValid;
     189    /** The disk buffer. */
     190    uint8_t            *pbData;
    176191} VBOXDISK, *PVBOXDISK;
    177192
     
    14281443                                   uint64_t off, void *pvBuf, size_t cbRead)
    14291444{
     1445    int rc = VINF_SUCCESS;
     1446
    14301447    LogFlow(("%s: off=%#llx pvBuf=%p cbRead=%d\n", __FUNCTION__,
    14311448             off, pvBuf, cbRead));
    14321449    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    1433     int rc = VDRead(pThis->pDisk, off, pvBuf, cbRead);
     1450
     1451    if (!pThis->fBootAccelActive)
     1452        rc = VDRead(pThis->pDisk, off, pvBuf, cbRead);
     1453    else
     1454    {
     1455        /* Can we serve the request from the buffer? */
     1456        if (   off >= pThis->offDisk
     1457            && off - pThis->offDisk < pThis->cbDataValid)
     1458        {
     1459            size_t cbToCopy = RT_MIN(cbRead, pThis->offDisk + pThis->cbDataValid - off);
     1460
     1461            memcpy(pvBuf, pThis->pbData + (off - pThis->offDisk), cbToCopy);
     1462            cbRead -= cbToCopy;
     1463            off    += cbToCopy;
     1464            pvBuf   = (char *)pvBuf + cbToCopy;
     1465        }
     1466
     1467        if (   cbRead > 0
     1468            && cbRead < pThis->cbBootAccelBuffer)
     1469        {
     1470            /* Increase request to the buffer size and read. */
     1471            pThis->cbDataValid = RT_MIN(pThis->cbDisk - off, pThis->cbBootAccelBuffer);
     1472            pThis->offDisk = off;
     1473            rc = VDRead(pThis->pDisk, off, pThis->pbData, pThis->cbDataValid);
     1474            if (RT_FAILURE(rc))
     1475                pThis->cbDataValid = 0;
     1476            else
     1477                memcpy(pvBuf, pThis->pbData, cbRead);
     1478        }
     1479        else if (cbRead >= pThis->cbBootAccelBuffer)
     1480        {
     1481            pThis->fBootAccelActive = false; /* Deactiviate */
     1482        }
     1483    }
     1484
    14341485    if (RT_SUCCESS(rc))
    14351486        Log2(("%s: off=%#llx pvBuf=%p cbRead=%d %.*Rhxd\n", __FUNCTION__,
     
    14491500    Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d %.*Rhxd\n", __FUNCTION__,
    14501501          off, pvBuf, cbWrite, cbWrite, pvBuf));
     1502
     1503    /* Invalidate any buffer if boot acceleration is enabled. */
     1504    if (pThis->fBootAccelActive)
     1505    {
     1506        pThis->cbDataValid = 0;
     1507        pThis->offDisk     = 0;
     1508    }
     1509
    14511510    int rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
    14521511    LogFlow(("%s: returns %Rrc\n", __FUNCTION__, rc));
     
    16141673             uOffset, paSeg, cSeg, cbRead, pvUser));
    16151674    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
     1675
     1676    pThis->fBootAccelActive = false;
     1677
    16161678    int rc = VDAsyncRead(pThis->pDisk, uOffset, cbRead, paSeg, cSeg,
    16171679                         drvvdAsyncReqComplete, pThis, pvUser);
     
    16271689             uOffset, paSeg, cSeg, cbWrite, pvUser));
    16281690    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
     1691
     1692    pThis->fBootAccelActive = false;
     1693
    16291694    int rc = VDAsyncWrite(pThis->pDisk, uOffset, cbWrite, paSeg, cSeg,
    16301695                          drvvdAsyncReqComplete, pThis, pvUser);
     
    17721837
    17731838/**
     1839 * @copydoc FNPDMDRVRESET
     1840 */
     1841static DECLCALLBACK(void) drvvdReset(PPDMDRVINS pDrvIns)
     1842{
     1843    LogFlow(("%s:\n", __FUNCTION__));
     1844    PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
     1845
     1846    if (pThis->fBootAccelEnabled)
     1847    {
     1848        pThis->fBootAccelActive = true;
     1849        pThis->cbDataValid      = 0;
     1850        pThis->offDisk          = 0;
     1851    }
     1852}
     1853
     1854/**
    17741855 * @copydoc FNPDMDRVDESTRUCT
    17751856 */
     
    18081889        pThis->MergeLock = NIL_RTSEMRW;
    18091890    }
     1891    if (pThis->pbData)
     1892        RTMemFree(pThis->pbData);
    18101893}
    18111894
     
    19071990                                          "Format\0Path\0"
    19081991                                          "ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0"
    1909                                           "HostIPStack\0UseNewIo\0"
     1992                                          "HostIPStack\0UseNewIo\0BootAcceleration\0BootAccelerationBuffer\0"
    19101993                                          "SetupMerge\0MergeSource\0MergeTarget\0");
    19111994        }
     
    19982081                rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
    19992082                                      N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"MergePending\" are set"));
     2083                break;
     2084            }
     2085            rc = CFGMR3QueryBoolDef(pCurNode, "BootAcceleration", &pThis->fBootAccelEnabled, false);
     2086            if (RT_FAILURE(rc))
     2087            {
     2088                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     2089                                      N_("DrvVD: Configuration error: Querying \"BootAcceleration\" as boolean failed"));
     2090                break;
     2091            }
     2092            rc = CFGMR3QueryU32Def(pCurNode, "BootAccelerationBuffer", (uint32_t *)&pThis->cbBootAccelBuffer, 16 * _1K);
     2093            if (RT_FAILURE(rc))
     2094            {
     2095                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     2096                                      N_("DrvVD: Configuration error: Querying \"BootAccelerationBuffer\" as integer failed"));
    20002097                break;
    20012098            }
     
    23122409                                    NULL /*pfnDonePrep*/, NULL /*pfnLoadExec*/, drvvdLoadDone);
    23132410
     2411    /* Setup the boot acceleration stuff if enabled. */
     2412    if (RT_SUCCESS(rc) && pThis->fBootAccelEnabled)
     2413    {
     2414        pThis->cbDisk = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
     2415        Assert(pThis->cbDisk > 0);
     2416        pThis->pbData = (uint8_t *)RTMemAllocZ(pThis->cbBootAccelBuffer);
     2417        if (pThis->pbData)
     2418        {
     2419            pThis->fBootAccelActive = true;
     2420            pThis->offDisk          = 0;
     2421            pThis->cbDataValid      = 0;
     2422            LogRel(("VD: Boot acceleration enabled\n"));
     2423        }
     2424        else
     2425            LogRel(("VD: Boot acceleration, out of memory, disabled\n"));
     2426    }
    23142427
    23152428    if (RT_FAILURE(rc))
     
    23602473    drvvdPowerOn,
    23612474    /* pfnReset */
    2362     NULL,
     2475    drvvdReset,
    23632476    /* pfnSuspend */
    23642477    drvvdSuspend,
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