VirtualBox

Changeset 643 in vbox for trunk/src


Ignore:
Timestamp:
Feb 5, 2007 4:57:01 PM (18 years ago)
Author:
vboxsync
Message:

Ignore writing data blocks consisting of all zeroes to a VDI block which
already contains all zeroes. Avoids the need to compact a VDI somewhat.

File:
1 edited

Legend:

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

    r294 r643  
    17191719
    17201720    /* loop through blocks */
    1721     int rc;
     1721    int rc = VINF_SUCCESS;
    17221722    for (;;)
    17231723    {
     
    17271727        else
    17281728            to_write = cbBlock - offWrite;
     1729
     1730        /* All callers write less than a VDI block right now (assuming
     1731         * default VDI block size). So not worth optimizing for the case
     1732         * where a full block is overwritten (no copying required).
     1733         * Checking whether a block is all zeroes after the write is too
     1734         * expensive (would require reading the rest of the block). */
    17291735
    17301736        if (pDisk->cImages > 1)
     
    17541760        }
    17551761
     1762        /* If the destination block is unallocated at this point, it's either
     1763         * a zero block or a block which hasn't been used so far (which also
     1764         * means that it's a zero block. Don't need to write anything to this
     1765         * block if the data consists of just zeroes. */
     1766        bool fBlockZeroed = false; /* assume data, for blocks already with data */
     1767        if (!IS_VDI_IMAGE_BLOCK_ALLOCATED(pImage->paBlocks[uBlock]))
     1768        {
     1769            /* Check block for data. */
     1770            fBlockZeroed = true;    /* Block is zeroed flag. */
     1771            for (unsigned i = 0; i < (to_write >> 2); i++)
     1772                if (((uint32_t *)pvBuf)[i] != 0)
     1773                {
     1774                    /* Block is not zeroed! */
     1775                    fBlockZeroed = false;
     1776                    break;
     1777                }
     1778        }
     1779
    17561780        /* Actually write the data into block. */
    1757         rc = vdiWriteInBlock(pDisk, pImage, uBlock, offWrite, to_write, pvBuf);
     1781        if (!fBlockZeroed)
     1782            rc = vdiWriteInBlock(pDisk, pImage, uBlock, offWrite, to_write, pvBuf);
    17581783
    17591784        cbToWrite -= to_write;
     
    24832508 * @param   pfnProgress     Progress callback. Optional.
    24842509 * @param   pvUser          User argument for the progress callback.
    2485  * @remark  Only used by vditool
    24862510 */
    24872511IDER3DECL(int) VDIShrinkImage(const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser)
     
    26042628
    26052629                /* Check block for data. */
    2606                 bool flBlockZeroed = true;    /* Block is zeroed flag. */
     2630                bool fBlockZeroed = true;    /* Block is zeroed flag. */
    26072631                for (unsigned i = 0; i < (cbBlock >> 2); i++)
    26082632                    if (((uint32_t *)pvBuf)[i] != 0)
    26092633                    {
    26102634                        /* Block is not zeroed! */
    2611                         flBlockZeroed = false;
     2635                        fBlockZeroed = false;
    26122636                        break;
    26132637                    }
    26142638
    2615                 if (!flBlockZeroed)
     2639                if (!fBlockZeroed)
    26162640                {
    26172641                    /* Block has a data, may be it must be moved. */
     
    41014125/**
    41024126 * internal: debug image dump.
    4103  * 
     4127 *
    41044128 * @remark  Only used by tstVDI.
    41054129 */
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