VirtualBox

Changeset 21862 in vbox


Ignore:
Timestamp:
Jul 29, 2009 12:23:04 PM (16 years ago)
Author:
vboxsync
Message:

SSM: Preparing for buffering.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/SSM-new.cpp

    r21858 r21862  
    100100 *       - type 2: Raw data record.
    101101 *       - type 3: Raw data compressed by LZF. The data is prefixed by a 8-bit
    102  *                 field countining the length of the uncompressed data given as
    103  *                 a page count.
     102 *                 field countining the length of the uncompressed data given in
     103 *                 1KB units.
    104104 *       - type 4: Named data - length prefixed name followed by the data. This
    105105 *                 type is not implemented yet as we're missing the API part, so
     
    112112 *
    113113 * Record header byte 2 (optionally thru 7) is the size of the following data
    114  * encoded in UTF-8 style.
     114 * encoded in UTF-8 style.  To make buffering simpler and more efficient during
     115 * the save operation, the strict checks enforcing optimal encoding has been
     116 * relaxed for the 2 and 3 byte encodings.
    115117 *
    116118 * (In version 1.2 and earlier the unit data was compressed and not record
     
    256258        AssertLogRelMsgReturn(u32ActualCRC == u32CRC, Msg, VERR_SSM_INTEGRITY_CRC); \
    257259    } while (0)
     260
     261/** The number of bytes to compress is one block.
     262 * Must be a multiple of 1KB.  */
     263#define SSM_ZIP_BLOCK_SIZE                      _4K
     264AssertCompile(SSM_ZIP_BLOCK_SIZE / _1K * _1K == SSM_ZIP_BLOCK_SIZE);
    258265
    259266
     
    19661973            }
    19671974            if (    uHdr.v2_0.cbMaxDecompr > sizeof(pSSM->u.Read.abDataBuffer)
    1968                 ||  uHdr.v2_0.cbMaxDecompr < PAGE_SIZE
     1975                ||  uHdr.v2_0.cbMaxDecompr < _1K
    19691976                ||  (uHdr.v2_0.cbMaxDecompr & 0xff) != 0)
    19701977            {
     
    33513358        for (;;)
    33523359        {
    3353             if (cbBuf >= PAGE_SIZE)
     3360            if (cbBuf >= SSM_ZIP_BLOCK_SIZE)
    33543361            {
    33553362                struct
    33563363                {
    3357                     uint8_t     cPages;
    3358                     uint8_t     abCompr[PAGE_SIZE - (PAGE_SIZE / 16)];
     3364                    uint8_t     cKB;
     3365                    uint8_t     abCompr[SSM_ZIP_BLOCK_SIZE - (SSM_ZIP_BLOCK_SIZE / 16)];
    33593366                } s;
    3360                 AssertCompile(sizeof(s) == PAGE_SIZE - (PAGE_SIZE / 16) + sizeof(uint8_t));
     3367                AssertCompile(sizeof(s) == SSM_ZIP_BLOCK_SIZE - (SSM_ZIP_BLOCK_SIZE / 16) + sizeof(uint8_t));
    33613368
    33623369                size_t cbCompr;
    33633370                rc = RTZipBlockCompress(RTZIPTYPE_LZF, RTZIPLEVEL_FAST, 0 /*fFlags*/,
    3364                                         pvBuf, PAGE_SIZE,
     3371                                        pvBuf, SSM_ZIP_BLOCK_SIZE,
    33653372                                        &s.abCompr[0], sizeof(s.abCompr), &cbCompr);
    33663373                if (RT_SUCCESS(rc))
    33673374                {
    3368                     cbCompr += sizeof(s.cPages);
    3369                     s.cPages = 1;
     3375                    cbCompr += sizeof(s.cKB);
     3376                    s.cKB = SSM_ZIP_BLOCK_SIZE / _1K;
    33703377                    rc = ssmR3DataWriteRecHdr(pSSM, cbCompr, SSM_REC_FLAGS_FIXED | SSM_REC_FLAGS_IMPORTANT | SSM_REC_TYPE_RAW_LZF);
    33713378                    if (RT_FAILURE(rc))
     
    33783385                {
    33793386                    /* Didn't compress very well, store it. */
    3380                     rc = ssmR3DataWriteRecHdr(pSSM, PAGE_SIZE, SSM_REC_FLAGS_FIXED | SSM_REC_FLAGS_IMPORTANT | SSM_REC_TYPE_RAW);
     3387                    rc = ssmR3DataWriteRecHdr(pSSM, SSM_ZIP_BLOCK_SIZE, SSM_REC_FLAGS_FIXED | SSM_REC_FLAGS_IMPORTANT | SSM_REC_TYPE_RAW);
    33813388                    if (RT_FAILURE(rc))
    33823389                        return rc;
    3383                     rc = ssmR3DataWriteRaw(pSSM, pvBuf, PAGE_SIZE);
     3390                    rc = ssmR3DataWriteRaw(pSSM, pvBuf, SSM_ZIP_BLOCK_SIZE);
    33843391                    if (RT_FAILURE(rc))
    33853392                        return rc;
    33863393                }
    3387                 if (cbBuf == PAGE_SIZE)
     3394                if (cbBuf == SSM_ZIP_BLOCK_SIZE)
    33883395                    return VINF_SUCCESS;
    3389                 cbBuf -= PAGE_SIZE;
    3390                 pvBuf = (uint8_t const*)pvBuf + PAGE_SIZE;
     3396                cbBuf -= SSM_ZIP_BLOCK_SIZE;
     3397                pvBuf = (uint8_t const*)pvBuf + SSM_ZIP_BLOCK_SIZE;
    33913398            }
    33923399            else
     
    40854092/** @todo this isn't very efficient, we know we have to read it all, so both
    40864093 *        reading the first byte separately.  */
    4087     uint8_t cPages;
    4088     int rc = ssmR3DataReadV2Raw(pSSM, &cPages, 1);
     4094    uint8_t cKB;
     4095    int rc = ssmR3DataReadV2Raw(pSSM, &cKB, 1);
    40894096    if (RT_FAILURE(rc))
    40904097        return rc;
    4091     pSSM->u.Read.cbRecLeft -= sizeof(cPages);
    4092 
    4093     size_t cbDecompr = (size_t)cPages * PAGE_SIZE;
     4098    pSSM->u.Read.cbRecLeft -= sizeof(cKB);
     4099
     4100    size_t cbDecompr = (size_t)cKB * _1K;
    40944101    AssertLogRelMsgReturn(   cbDecompr >= pSSM->u.Read.cbRecLeft
    40954102                          && cbDecompr <= RT_SIZEOFMEMB(SSMHANDLE, u.Read.abDataBuffer),
     
    42774284                    | ((uint32_t)(abHdr[2] & 0x3f) << 6)
    42784285                    | ((uint32_t)(abHdr[1] & 0x0f) << 12);
     4286#if 0  /* disabled to optimize buffering */
    42794287                AssertLogRelMsgReturn(cb >= 0x00000800 && cb <= 0x0000ffff, ("cb=%#x\n", cb), VERR_SSM_INTEGRITY);
     4288#endif
    42804289                break;
    42814290            case 2:
    42824291                cb =             (abHdr[2] & 0x3f)
    42834292                    | ((uint32_t)(abHdr[1] & 0x1f) << 6);
     4293#if 0  /* disabled to optimize buffering */
    42844294                AssertLogRelMsgReturn(cb >= 0x00000080 && cb <= 0x000007ff, ("cb=%#x\n", cb), VERR_SSM_INTEGRITY);
     4295#endif
    42854296                break;
    42864297            default:
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