Skip to content
  • Alberto Garcia's avatar
    46cd1e8a
    qcow2: Skip copy-on-write when allocating a zero cluster · 46cd1e8a
    Alberto Garcia authored
    
    
    Since commit c8bb23cb when a write
    request results in a new allocation QEMU first tries to see if the
    rest of the cluster outside the written area contains only zeroes.
    
    In that case, instead of doing a normal copy-on-write operation and
    writing explicit zero buffers to disk, the code zeroes the whole
    cluster efficiently using pwrite_zeroes() with BDRV_REQ_NO_FALLBACK.
    
    This improves performance very significantly but it only happens when
    we are writing to an area that was completely unallocated before. Zero
    clusters (QCOW2_CLUSTER_ZERO_*) are treated like normal clusters and
    are therefore slower to allocate.
    
    This happens because the code uses bdrv_is_allocated_above() rather
    bdrv_block_status_above(). The former is not as accurate for this
    purpose but it is faster. However in the case of qcow2 the underlying
    call does already report zero clusters just fine so there is no reason
    why we cannot use that information.
    
    After testing 4KB writes on an image that only contains zero clusters
    this patch results in almost five times more IOPS.
    
    Signed-off-by: default avatarAlberto Garcia <berto@igalia.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Message-Id: <6d77cab968c501c44d6e1089b9bc91b04170b49e.1603731354.git.berto@igalia.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    46cd1e8a
    qcow2: Skip copy-on-write when allocating a zero cluster
    Alberto Garcia authored
    
    
    Since commit c8bb23cb when a write
    request results in a new allocation QEMU first tries to see if the
    rest of the cluster outside the written area contains only zeroes.
    
    In that case, instead of doing a normal copy-on-write operation and
    writing explicit zero buffers to disk, the code zeroes the whole
    cluster efficiently using pwrite_zeroes() with BDRV_REQ_NO_FALLBACK.
    
    This improves performance very significantly but it only happens when
    we are writing to an area that was completely unallocated before. Zero
    clusters (QCOW2_CLUSTER_ZERO_*) are treated like normal clusters and
    are therefore slower to allocate.
    
    This happens because the code uses bdrv_is_allocated_above() rather
    bdrv_block_status_above(). The former is not as accurate for this
    purpose but it is faster. However in the case of qcow2 the underlying
    call does already report zero clusters just fine so there is no reason
    why we cannot use that information.
    
    After testing 4KB writes on an image that only contains zero clusters
    this patch results in almost five times more IOPS.
    
    Signed-off-by: default avatarAlberto Garcia <berto@igalia.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Message-Id: <6d77cab968c501c44d6e1089b9bc91b04170b49e.1603731354.git.berto@igalia.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Loading