Coverage / crates/flow-init/src/prune.rs 89.8%
212 of 236 lines run, 61 of 70 functions · run #185 on main · run missed
| 1 | //! Pruning a build cache before it is kept (oxygenflow#72, spec §5.4). | |
| 2 | //! | |
| 3 | //! A kept disk starts the next run, so without pruning it carries every | |
| 4 | //! build's files: each crate's artifacts under every hash a lockfile or a | |
| 5 | //! feature set ever gave it. Before a passing job's cache disk goes back | |
| 6 | //! into the pool, the files this run did not use are removed, oldest | |
| 7 | //! first, until what is on the disk is at most a share of its size (the | |
| 8 | //! cap). The microVM's guest init prunes its disks before it powers off, | |
| 9 | //! since only it can see inside them; the runner prunes the syscall | |
| 10 | //! tier's directories itself. Both use this module. | |
| 11 | //! | |
| 12 | //! What the run used is told by the files' times against when the job | |
| 13 | //! started: written (mtime), changed (ctime) or read (atime). Reads are | |
| 14 | //! seen only where the file system records them: the guest mounts a cache | |
| 15 | //! disk `strictatime`; on the runner, where a directory sits on whatever | |
| 16 | //! file system the runner has, each file's atime is set to the epoch | |
| 17 | //! before the job ([`forget_reads`]), so even `relatime` records its | |
| 18 | //! first read. A file system mounted `noatime` records none, and then | |
| 19 | //! nothing is pruned. | |
| 20 | //! | |
| 21 | //! A build tool does not read everything it relies on. Cargo, finding a | |
| 22 | //! crate fresh, reads its fingerprint and only looks at its rlib and | |
| 23 | //! binaries, so their times say nothing. Every name cargo gives a unit's | |
| 24 | //! files carries the unit's hash (`.fingerprint/foo-<hash>/`, | |
| 25 | //! `deps/libfoo-<hash>.rlib`, `build/foo-<hash>/`), so a file stays when | |
| 26 | //! a file this run used carries one of the hashes in its path: a fresh | |
| 27 | //! crate's fingerprint keeps its artifacts. A file with another link | |
| 28 | //! that stays, or under a path the job's outputs name, stays too. What | |
| 29 | //! goes is what this run's build did not touch, which a later build needs | |
| 30 | //! only if an older lockfile comes back, and then cargo rebuilds it. | |
| 31 | | |
| 32 | use ; | |
| 33 | use ; | |
| 34 | use MetadataExt; | |
| 35 | use ; | |
| 36 | use ; | |
| 37 | ||
| 38 | /// The share of a cache disk a kept cache may fill when no runner says | |
| 39 | /// otherwise: room for this run's build and as much again. | |
| 40 | pub const DEFAULT_PERCENT: u8 = 60; | |
| 41 | ||
| 42 | /// What pruning a cache found and did, in bytes of blocks on its disk. | |
| 43 | | |
| 44 | | |
| 45 | | |
| 46 | | |
| 47 | | |
| 48 | | |
| 49 | | |
| 50 | | |
| 51 | | |
| 52 | | |
| 53 | | |
| 54 | | |
| 55 | | |
| 56 | | |
| 57 | | |
| 58 | | |
| 59 | ||
| 60 | | |
| 61 | | |
| 62 | 54× | |
| 63 | 54× | |
| 64 | 54× | |
| 65 | | |
| 66 | | |
| 67 | 35× | |
| 68 | 35× | |
| 69 | 35× | |
| 70 | | |
| 71 | ||
| 72 | 54× | |
| 73 | 54× | |
| 74 | 54× | |
| 75 | ||
| 76 | /// Now, as a job's start to compare file times against. File systems | |
| 77 | /// stamp times from a clock that may lag this one by a tick, so the | |
| 78 | /// moments either side of it are left to pass: nothing done before the | |
| 79 | /// call (such as [`forget_reads`]) can look as though it came after. | |
| 80 | 0× | |
| 81 | 0× | |
| 82 | 0× | |
| 83 | 0× | |
| 84 | 0× | |
| 85 | 0× | |
| 86 | ||
| 87 | /// Whether the file system holding `path` records reads (not `noatime`). | |
| 88 | 7× | |
| 89 | 7× | |
| 90 | 7× | |
| 91 | 7× | |
| 92 | 0× | |
| 93 | 7× | |
| 94 | 7× | |
| 95 | 7× | |
| 96 | ||
| 97 | /// The blocks in use on the file system mounted at `path`, and its size | |
| 98 | /// (as `df` counts them). | |
| 99 | 0× | |
| 100 | 0× | |
| 101 | 0× | |
| 102 | 0× | |
| 103 | 0× | |
| 104 | 0× | |
| 105 | 0× | |
| 106 | 0× | |
| 107 | 0× | |
| 108 | ||
| 109 | /// Set every regular file's atime under `root` to the epoch, its mtime | |
| 110 | /// kept, so the job's first read of each is recorded even on `relatime` | |
| 111 | /// (which records a read only of a file read no later than it changed). | |
| 112 | /// Links are not followed. The count of files. | |
| 113 | 2× | |
| 114 | 2× | |
| 115 | 2× | |
| 116 | 6× | |
| 117 | 6× | |
| 118 | 4× | |
| 119 | 2× | |
| 120 | 2× | |
| 121 | 2× | |
| 122 | 2× | |
| 123 | 2× | |
| 124 | 2× | |
| 125 | 0× | |
| 126 | 0× | |
| 127 | 6× | |
| 128 | 2× | |
| 129 | 0× | |
| 130 | 2× | |
| 131 | | |
| 132 | 2× | |
| 133 | ||
| 134 | /// Each entry under `root` (not `root` itself) with its metadata, parents | |
| 135 | /// before children; links are not followed, nor other file systems | |
| 136 | /// entered. | |
| 137 | 6× | |
| 138 | 6× | |
| 139 | 6× | |
| 140 | 38× | |
| 141 | 32× | |
| 142 | 51× | |
| 143 | 51× | |
| 144 | 51× | |
| 145 | 51× | |
| 146 | 0× | |
| 147 | 51× | |
| 148 | 51× | |
| 149 | 51× | |
| 150 | 26× | |
| 151 | 26× | |
| 152 | | |
| 153 | | |
| 154 | 6× | |
| 155 | 6× | |
| 156 | ||
| 157 | /// The unit hashes in `rel`: a 16-digit lowercase hex word after a `-` | |
| 158 | /// in any of its names, as cargo names a unit's files. | |
| 159 | 29× | + '_ |
| 160 | 89× | |
| 161 | 89× | |
| 162 | 33× | |
| 163 | 347× | |
| 164 | 33× | |
| 165 | 89× | |
| 166 | 29× | |
| 167 | ||
| 168 | 106× | |
| 169 | 106× | |
| 170 | 106× | |
| 171 | ||
| 172 | /// One file, however many names it has. | |
| 173 | | |
| 174 | | |
| 175 | | |
| 176 | | |
| 177 | | |
| 178 | | |
| 179 | | |
| 180 | | |
| 181 | | |
| 182 | ||
| 183 | /// Prune the cache at `root`, a disk of `size` bytes with `before` in | |
| 184 | /// use, down to `percent` of its size, removing only regular files this | |
| 185 | /// run did not use (see the module's notes), those used longest ago | |
| 186 | /// first. `started` is when the job started ([`start_clock`]); `keep` are | |
| 187 | /// paths relative to `root` (the job's outputs) that stay whatever their | |
| 188 | /// times. Under the cap nothing is touched. `after` is `before` less what | |
| 189 | /// was freed. | |
| 190 | 10× | |
| 191 | 10× | |
| 192 | 10× | |
| 193 | 6× | |
| 194 | 4× | |
| 195 | 4× | |
| 196 | 4× | |
| 197 | 4× | |
| 198 | 45× | |
| 199 | 45× | |
| 200 | 23× | |
| 201 | 22× | |
| 202 | 22× | |
| 203 | 22× | |
| 204 | 22× | |
| 205 | 45× | |
| 206 | 11× | |
| 207 | 22× | |
| 208 | 20× | |
| 209 | 20× | |
| 210 | 20× | |
| 211 | 20× | |
| 212 | | |
| 213 | 20× | |
| 214 | 22× | |
| 215 | 22× | |
| 216 | 45× | |
| 217 | | |
| 218 | 4× | |
| 219 | 13× | |
| 220 | 4× | |
| 221 | 4× | |
| 222 | 20× | |
| 223 | 20× | |
| 224 | | |
| 225 | 9× | |
| 226 | 9× | |
| 227 | 20× | |
| 228 | 4× | |
| 229 | 4× | |
| 230 | 4× | |
| 231 | 5× | |
| 232 | 5× | |
| 233 | 1× | |
| 234 | 4× | |
| 235 | 4× | |
| 236 | 4× | |
| 237 | 4× | |
| 238 | 0× | |
| 239 | 4× | |
| 240 | 4× | |
| 241 | 4× | |
| 242 | | |
| 243 | 4× | |
| 244 | 4× | |
| 245 | 4× | |
| 246 | 4× | |
| 247 | 4× | |
| 248 | | |
| 249 | | |
| 250 | 4× | |
| 251 | 4× | |
| 252 | 4× | |
| 253 | 4× | |
| 254 | 5× | |
| 255 | 1× | |
| 256 | 1× | |
| 257 | 0× | |
| 258 | | |
| 259 | | |
| 260 | | |
| 261 | 4× | |
| 262 | 10× | |
| 263 | ||
| 264 | | |
| 265 | | |
| 266 | | |
| 267 | | |
| 268 | | |
| 269 | | |
| 270 | | |
| 271 | | |
| 272 | 26× | |
| 273 | 26× | |
| 274 | 26× | |
| 275 | | |
| 276 | | |
| 277 | 11× | |
| 278 | 11× | |
| 279 | 11× | |
| 280 | 1314816× | |
| 281 | 11× | |
| 282 | 11× | |
| 283 | 11× | |
| 284 | 11× | |
| 285 | 11× | |
| 286 | | |
| 287 | 11× | |
| 288 | 11× | |
| 289 | 11× | |
| 290 | | |
| 291 | | |
| 292 | 1× | |
| 293 | 7× | |
| 294 | 1× | |
| 295 | 1× | |
| 296 | 1× | |
| 297 | 1× | |
| 298 | 1× | |
| 299 | 1× | |
| 300 | | |
| 301 | | |
| 302 | 1× | |
| 303 | 1× | |
| 304 | 1× | |
| 305 | 1× | |
| 306 | 1× | |
| 307 | 1× | |
| 308 | | |
| 309 | | |
| 310 | | |
| 311 | | |
| 312 | | |
| 313 | 1× | |
| 314 | 1× | |
| 315 | 1× | |
| 316 | 1× | |
| 317 | 1× | |
| 318 | 1× | |
| 319 | 1× | |
| 320 | 1× | |
| 321 | 1× | |
| 322 | | |
| 323 | 1× | |
| 324 | | |
| 325 | 1× | |
| 326 | 1× | |
| 327 | 1× | |
| 328 | | |
| 329 | 1× | |
| 330 | 1× | |
| 331 | 9× | |
| 332 | | |
| 333 | 1× | |
| 334 | 1× | |
| 335 | 1× | |
| 336 | 1× | |
| 337 | 1× | |
| 338 | 1× | |
| 339 | | |
| 340 | | |
| 341 | 1× | |
| 342 | 7× | |
| 343 | 7× | |
| 344 | | |
| 345 | 1× | |
| 346 | | |
| 347 | 1× | |
| 348 | 1× | |
| 349 | 5× | |
| 350 | 5× | |
| 351 | | |
| 352 | 1× | |
| 353 | 1× | |
| 354 | | |
| 355 | | |
| 356 | 1× | |
| 357 | 1× | |
| 358 | 1× | |
| 359 | 1× | |
| 360 | 1× | |
| 361 | 1× | |
| 362 | 1× | |
| 363 | 1× | |
| 364 | 1× | |
| 365 | |