mirror of
https://github.com/expo/bsdiff.git
synced 2026-11-13 20:11:27 -10:00
Previously, bspatch used to read the whole content of a file to be patched into a memory buffer, only to copy this data while generating the new file content, which is written to a second buffer. The said read buffer entails an unnecessary memory allocation requirement, especially since it's being indexed almost linearly. This behavior was further extended to support extents (i.e. a list of <offset, length> pairs), which are used extensively during Chrome OS updates. This change introduces extent files, which let users open files through a layer of extents as ordinary glibc file handles. This in turn allows us to easily convert reads from a memory buffer into direct reads from an extent file. Extent files are buffered on the outer level (done for us by glibc), but otherwise use a system file descriptor for the underlying I/O; this proved to be the most efficient combination when applying actual update payloads. Since we are reading a single byte at a time using fread(2), and since the program is decidedly single-threaded, we shift to using _unlocked variants, which appear to reduce the total update time significantly without otherwise affecting memory/CPU footprint. We expect this to cut bspatch's memory usage by nearly one half. Note that in general it is possible to use the same abstraction for implementing direct writing to the target file; however, due to the way we implement delta updates, there is risk that such writes might clobber the read data, and so further support is needed to mark safe operations (i.e. no read/write dependencies) as such. This CL obsoletes the previous ebuild patch for handling extent arguments, which is therefore removed. It also (i) gets rid of logic for special handling of /dev/fd filenames, which is deemed redundant; (ii) fixes the Makefile (via a separate patch) and changes the ebuild to use it, for uniformity; (iii) updates the ebuild to EAPI version 4; (iv) sets -Wall -Werror and fixes eliminates a warning due to bsdiff.c; (v) enhances man pages for both bsdiff/bspatch. BUG=chromium:229705 TEST=Passes update engine unittests with new bspatch TEST=delta payload with BSDIFF operations updates correctly on x86-alex Change-Id: I4bb4afa42e43279048093e7a7f0ef96406b0c9e0 Reviewed-on: https://gerrit.chromium.org/gerrit/49595 Reviewed-by: Gilad Arnold <[email protected]> Tested-by: Gilad Arnold <[email protected]> Commit-Queue: Gilad Arnold <[email protected]>
78 lines
2.4 KiB
Groff
78 lines
2.4 KiB
Groff
.\"-
|
|
.\" Copyright 2003-2005 Colin Percival
|
|
.\" All rights reserved
|
|
.\"
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
.\" modification, are permitted providing that the following conditions
|
|
.\" are met:
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
.\"
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
.\"
|
|
.\" $FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.1,v 1.1 2005/08/06 01:59:06 cperciva Exp $
|
|
.\"
|
|
.Dd May 18, 2003
|
|
.Dt BSPATCH 1
|
|
.Os FreeBSD
|
|
.Sh NAME
|
|
.Nm bspatch
|
|
.Nd apply a patch built with bsdiff(1)
|
|
.Sh SYNOPSIS
|
|
.Nm
|
|
.Ar oldfile newfile patchfile
|
|
.Op Ar old-extents new-extents
|
|
.Sh DESCRIPTION
|
|
.Nm
|
|
generates
|
|
.Ar newfile
|
|
from
|
|
.Ar oldfile
|
|
and
|
|
.Ar patchfile ,
|
|
where
|
|
.Ar patchfile
|
|
is a binary patch built by
|
|
.Xr bsdiff 1 .
|
|
.Pp
|
|
When provided,
|
|
.Ar old-extents
|
|
and
|
|
.Ar new-extents
|
|
instruct
|
|
.Nm
|
|
to read specific chunks of data from the old file and to write to specific
|
|
locations in the new file, respectively. Each is a comma-separated list of
|
|
extents of the form
|
|
.Ar offset : Ns Ar length ,
|
|
where
|
|
.Ar offset
|
|
is either -1 or a non-negative integer and
|
|
.Ar length
|
|
is a positive integer. An offset value of -1 denotes a sparse extent, namely a
|
|
sequence of zeros that entails neither reading nor writing of actual file
|
|
content.
|
|
.Pp
|
|
.Nm
|
|
uses memory equal to the size of
|
|
.Ar newfile ,
|
|
but can tolerate a very small working set without a dramatic loss
|
|
of performance.
|
|
.Sh SEE ALSO
|
|
.Xr bsdiff 1
|
|
.Sh AUTHORS
|
|
.An Colin Percival Aq [email protected]
|