blob: fd8100d8c27bdfb2af0f104de9a693fe4151e24b [file] [log] [blame] [view]
Andrew Savageed58f022022-08-12 09:14:48 -07001# Evergreen Binary Compression
2
3## What is Evergreen Binary Compression?
4
5Evergreen Binary Compression is a feature that reduces the amount of space used
6on-device to store Cobalt Core binaries. The binaries are stored compressed,
7using the
8[LZ4 Frame Format](https://github.com/lz4/lz4/blob/dev/doc/lz4_Frame_format.md),
9and decompressed when they are loaded and run. This optional feature is off by
10default but partners can enable it by following the instructions below.
11
12## Storage Savings
13
14Across all reference devices tested, including Raspberry Pi 2, we have seen
15compression ratios just above 2.0. We therefore expect that partners can halve
16the space used for Cobalt binary storage by enabling the feature for all
17installation slots: the system image slot and the writable slots.
18
19## Caveats
20
21### Performance Costs
22
23Because the Cobalt Core shared library must be decompressed before it's loaded,
24there is necessarily some effect on startup latency and CPU memory usage. Based
25on our analysis across a range of devices these effects are relatively small.
26
27For startup latency, we measured an increase in `libcobalt` load time in the
28hundreds of milliseconds for the low-powered Raspberry Pi 2 and in the tens of
29milliseconds for more representative, higher-powered devices. This increase is
30small in the context of overall app load time.
31
32For CPU memory usage, `libcobalt.lz4` is decompressed to an in-memory ELF file
33before the program is loaded. We therefore expect CPU memory usage to
34temporarily increase by roughly the size of the uncompressed `libcobalt` and
35then to return to a normal level once the library is loaded. And this is exactly
36what we've seen in our analysis.
37
38### Incompatibilities
39
40This feature is incompatible with the Memory Mapped file feature that is
41controlled by the `--loader_use_mmap_file` switch. With compression, we lose the
42required 1:1 mapping between the file and virtual memory. So,
43`--loader_use_mmap_file` should not be set if compression is enabled for any
44installation slots (next section).
45
46## Enabling Binary Compression
47
48Separate steps are required in order for a partner to enable compression for a)
49the system image slot and b) (Evergreen-Full only) the 2+ writable slots on a
50device.
51
52Compression for the system image slot is enabled by installing `libcobalt.lz4`
53instead of `libcobalt.so` in the read-only system image slot (i.e., SLOT_0).
54Starting with a to be determined Cobalt 23 release, the open-source releases on
55[GitHub](https://github.com/youtube/cobalt/releases) include separate CRX
56packages, denoted by a "compressed" suffix, that contain the pre-built and
57LZ4-compressed Cobalt Core binary.
58
59Compression for the writable slots is enabled by configuring Cobalt to launch
60with the `--use_compressed_updates` flag:
61
62```
63$ ./loader_app --use_compressed_updates
64```
65
66This flag instructs the Cobalt Updater to request, download, and install
67packages containing compressed Cobalt Core binaries from Google Update and
68Google Downloads. As a result, the device ends up with `libcobalt.lz4` instead
69of `libcobalt.so` in the relevant slot after its next update.
70
71Note that the system image slot is independent from the writable slots with
72respect to the compression feature: the feature can be enabled for the system
73image slot but disabled for the writable slots, or vice versa. However, we
74expect that partners will typically enable the feature for all slots in order to
75take full advantage of the storage reduction.
76
77## Disabling Binary Compression
78
79The compression feature is turned off by default. Once enabled, though, it can
80be disabled by undoing the steps required for enablement.
81
82Compression for the system image slot is disabled by installing the uncompressed
83`libcobalt.so` instead of `libcobalt.lz4` in the read-only system image slot.
84
85Compression for the writable slots is disabled by configuring Cobalt to launch
86**without** the `--use_compressed_updates` flag. The Cobalt Updater will then be
87instructed to request, download, and install packages containing the
88uncompressed Cobalt Core binaries.
89
90Note that disabling compression for the writable slots is eventual in the sense
91that the compressed Cobalt Core binaries in these slots will remain and continue
92to be used until newer versions of Cobalt Core are available on Google Update
93and Google Downloads.
94
95## FAQ
96
97### Should multiple apps that share binaries also share compression settings?
98
99The [Cobalt Evergreen Overview doc](cobalt_evergreen_overview.md) describes
100multi-app support, where multiple Cobalt-based applications share Cobalt Core
101binaries (i.e., they share the same installation slot(s)). When multi-app
102support is used then, yes, the apps should also share compression settings.
103
104For the system image slot, this means that either `libcobalt.lz4` or
105`libcobalt.so` is installed in the one, shared slot.
106
107For the writable slots, this means that the loader app is either launched with
108`--use_compressed_updates` set for all apps or launched without it for all apps.
109Otherwise, the different apps would compete with respect to whether the writable
110slots are upgraded to compressed or uncompressed binaries.