@threadedstack/wmd-web 0.1.37 → 0.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -6
- package/RELEASE.json +5 -5
- package/package.json +3 -3
- package/src/boot.js +140 -17
- package/src/build/builder.js +4 -3
- package/src/host/ckpt.js +16 -0
- package/wmdpack.wasm +0 -0
package/README.md
CHANGED
|
@@ -200,10 +200,10 @@ const r2 = await buildImage({ ...builderOptions, context, timeoutMs: 30 * 60_000
|
|
|
200
200
|
- **RAM and vCPUs.** The default is 1536 MiB and 2 vCPUs (`ram`, `cpus`). Small builds and the proxy project in the
|
|
201
201
|
plan fit. A build that compiles a native addon or bundles a large app needed 3072 MiB and 4 vCPUs (plan 10.5); a
|
|
202
202
|
single `RUN` step must finish within `timeoutMs`, since BuildKit resumes from its cache only between steps.
|
|
203
|
-
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
2048 MiB it is flat
|
|
203
|
+
- A RAM of 1537 to 2048 MiB stays in memory 0 (the option `ramInMemory0`, on by default since the flip:
|
|
204
|
+
`RAM_IN_MEMORY0.default`; named, only exactly `true` is on and only exactly `false` is off; also `wb.create` of the
|
|
205
|
+
test page), with memory 0 at 4 GiB, a heap reserve of 1663 MiB and an IR budget of 831 MiB at 2048 MiB. `ramInMemory0: false`
|
|
206
|
+
gives the flat layout (the guest's RAM in a memory of its own) there. Above 2048 MiB it is flat. Details: "Guests above 1536 MiB" below.
|
|
207
207
|
- **WebKit** builds Go and Node images and the real projects of the plan, but slower: its code space fills and new
|
|
208
208
|
code runs in the interpreter for a while (a `{t:'slow', reason:'webkit-code-space'}` event says so).
|
|
209
209
|
- In WebKit, node in `RUN` steps runs its JavaScript in the interpreter (D-553, `nodeInterpreted`, an
|
|
@@ -2684,7 +2684,7 @@ engines' memory64 limit), passes `WMD_RAM_FLAT=1` to vm.wasm and hands the memor
|
|
|
2684
2684
|
slack (`flatMaxPages`), whatever the guest's RAM. Leave `maxPages` out for such a boot.
|
|
2685
2685
|
- `flatRam: true|false` forces the layout on or off; unset, it is chosen for `--ram` above 1536 when the engine
|
|
2686
2686
|
has memory64 and `allowLargeRam` is not set. Safari has no memory64: the old limit and its message stay.
|
|
2687
|
-
- `ramInMemory0
|
|
2687
|
+
- `ramInMemory0` (X24, on by default since the flip; `true` names it on, `false` is the way out): a `--ram` above 1536 MiB and up to the engine's limit
|
|
2688
2688
|
(`MEMORY0_RAM_MAX_MIB` in `src/boot.js`: 2048 MiB in Chromium, Firefox and WebKit) keeps its RAM in memory 0,
|
|
2689
2689
|
with no `flatRam` or `allowLargeRam`. Above the limit the boot is flat as without the option. `flatRam: true`
|
|
2690
2690
|
still wins and `flatRam: false` still means memory 0.
|
|
@@ -2711,7 +2711,26 @@ engines' memory64 limit), passes `WMD_RAM_FLAT=1` to vm.wasm and hands the memor
|
|
|
2711
2711
|
- The test page `ckpt.html` with no option at 1537 MiB or more and no `flatRam` now boots flat, as `bootWmd` always
|
|
2712
2712
|
did for the same call. The old page ended at once with the "more than 1536 MiB" error there.
|
|
2713
2713
|
- Checkpoints and restores work as for any guest (proven with the option at 2048 MiB in Chromium, Firefox and WebKit, x24-gate2.md): a checkpoint also holds the RAM memory's written pages (sections
|
|
2714
|
-
`ram-index` and `ram`, header `ramPages`)
|
|
2714
|
+
`ram-index` and `ram`, header `ramPages`).
|
|
2715
|
+
- A restore boots with the RAM layout its checkpoint was taken with (X24 default, `chooseLayout` in `src/boot.js`),
|
|
2716
|
+
whatever the default or the options say: a flat checkpoint boots flat and a memory 0 checkpoint boots memory 0,
|
|
2717
|
+
with the checkpoint's own memory maximum (a `maxPages` the caller passes for the other layout is dropped). It holds
|
|
2718
|
+
for `bootWmd({ restore })`, for a base snapshot (`restoreLazy`, by its header) and for `vm.restore()`. The builder
|
|
2719
|
+
never restores (a machine with a disk takes no checkpoints). It applies where this browser can make the layout:
|
|
2720
|
+
flat needs memory64; memory 0 above 1536 MiB needs the engine's limit or `allowLargeRam`. A checkpoint of another
|
|
2721
|
+
`--ram`, or with a header that does not say its layout plainly, is not moved: it is refused with the text it always
|
|
2722
|
+
had (a different layout still named as such, `boot.maxPages`, `WMD_RAM_FLAT`).
|
|
2723
|
+
- Every boot sends one event `{ t: 'boot', stage: 'layout', layout: 'flat' | 'memory0', why, options, ramMiB, maxPages }`:
|
|
2724
|
+
`why` is `checkpoint`, `flatRam`, `ramInMemory0` (the option named `true`), `default` (the option on by the
|
|
2725
|
+
default), `allowLargeRam` or `ram` (the RAM size alone); `options` is the layout the options alone would have
|
|
2726
|
+
chosen. The test page keeps the last one as `ck.layout`.
|
|
2727
|
+
- The default. `RAM_IN_MEMORY0.default` in `src/boot.js` is the value of `ramInMemory0` when a caller leaves it out
|
|
2728
|
+
(`undefined` or `null`); it is `true` since the flip. Named values: only exactly `true` is on, only exactly
|
|
2729
|
+
`false` is off, anything else is off. With it on, a caller's own `allowLargeRam: true` (without naming the option)
|
|
2730
|
+
keeps its memory 0 layout. The test page's `?asDefault=1` sets it to `true` before the boot (the code path the flip
|
|
2731
|
+
takes), and `?ramInMemory0=0` names the option off. `createBuilder` and `wb.create` follow the same rule.
|
|
2732
|
+
- When the layout is the default's or a checkpoint's, the out-of-memory text names `ramInMemory0: false` or
|
|
2733
|
+
`flatRam: true` instead of "drop the option", which the caller never set.
|
|
2715
2734
|
- A checkpoint, flat or not, reads only the RAM pages the guest has written (vm.wasm's `vm_touched_map`, a bit per
|
|
2716
2735
|
64 KiB set before the first write): a page never written is not read, so the browser never backs it with memory.
|
|
2717
2736
|
|
package/RELEASE.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wmd-web",
|
|
3
3
|
"version": "0.5.1",
|
|
4
|
-
"commit": "
|
|
4
|
+
"commit": "19c9d61297cf7d3c531935ba4e13610730eaf34a",
|
|
5
5
|
"previous": null,
|
|
6
6
|
"decisions": [
|
|
7
7
|
"D-388",
|
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
}
|
|
144
144
|
},
|
|
145
145
|
"files": {
|
|
146
|
-
"README.md": "
|
|
146
|
+
"README.md": "b95e4c26b7ea033060d8a38af27a3b44695ee02f99d870836a61b0e183d94594",
|
|
147
147
|
"edge-site/own/HASHES.txt": "e79eaf7a2e1200dd4f638f87a2faaa3e7ad799af83ebff1c33abb9b68c88cf04",
|
|
148
148
|
"edge-site/own/NOTICES.txt": "8ceca5406ee5833737bd5fa4a41d434bf5e4d26eff6da1e42c693176ee113101",
|
|
149
149
|
"edge-site/own/acorn/LICENSE": "76a876cf886ff9be2a8b5e2e86514fed06223c8c9f0c1e9ee9606e93841e00b7",
|
|
@@ -166,8 +166,8 @@
|
|
|
166
166
|
"package.json": "7d43c05047d0a3ea56b4a7709f48a60de32e15c3bdf328d55435c46637981b40",
|
|
167
167
|
"src/base.js": "982f8e46dbb727ec542a494ebdb884ccd19a31ff4e091425b2d1fc01b0d4754a",
|
|
168
168
|
"src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
|
|
169
|
-
"src/boot.js": "
|
|
170
|
-
"src/build/builder.js": "
|
|
169
|
+
"src/boot.js": "5e2dfbd60cefc01c7cda07957c969d62ce507e56a810098eb4814dad6430c202",
|
|
170
|
+
"src/build/builder.js": "c7794ec15b183213228776c8f4fb0950dec7e621f948358da7de8f90ef4f70ec",
|
|
171
171
|
"src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
|
|
172
172
|
"src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
|
|
173
173
|
"src/build/dockerignore.js": "8fc03d09da020f43ea483979b1183891b71d76f012379ab7813838ea0e53c546",
|
|
@@ -248,7 +248,7 @@
|
|
|
248
248
|
"src/host/ckpt-io.js": "3fbe74f0254c597f10d088c85e8ba72725502d86ae4dd8c6d2bf0821a93c873f",
|
|
249
249
|
"src/host/ckpt-point.js": "42bc16b3f754de3cd4e39f37a0feca2ffd8b4231cd72ec32bd6e1ea734c3c8c7",
|
|
250
250
|
"src/host/ckpt-save.js": "e222571033ae74a4439596c5e90e03b2aa9a5516665dd290f8dd243712294523",
|
|
251
|
-
"src/host/ckpt.js": "
|
|
251
|
+
"src/host/ckpt.js": "4e61414c21089622dd9523aeca78b2fcce6e2cfd74917af5d6891859b0316857",
|
|
252
252
|
"src/host/clock.js": "aba6af3a8b1a985ae340892222e4b482d33afe20f5c8b3a4c7403ce87d1e247c",
|
|
253
253
|
"src/host/ctl.js": "b2b288e9c7f1afa0f81ef7ba69080df5019b3967bc6f8e1a04ce76ba93d0ba04",
|
|
254
254
|
"src/host/disk-map.js": "3d7e0d7d488ce25fc6a0e4dc0a9b1c8fc2af96bac1c03491a1d30be392af268b",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threadedstack/wmd-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/threadedstack/wmd-releases",
|
|
6
6
|
"repository": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"description": "Browser host for wmd's guest vm.wasm (Web Workers + shared memory + WASI preview1)",
|
|
11
11
|
"wmd": {
|
|
12
|
-
"tag": "v0.1.
|
|
13
|
-
"commit": "
|
|
12
|
+
"tag": "v0.1.38",
|
|
13
|
+
"commit": "19c9d61297cf7d3c531935ba4e13610730eaf34a",
|
|
14
14
|
"web": "0.5.1"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
package/src/boot.js
CHANGED
|
@@ -47,7 +47,7 @@ import {
|
|
|
47
47
|
import { ControlClient } from './host/ctl.js'
|
|
48
48
|
import { PAGE as CKPT_PAGE, requestCheckpoint } from './host/ckpt-point.js'
|
|
49
49
|
import {
|
|
50
|
-
CheckpointError, serviceErrorCode, assembleCheckpoint, bootKeyOf, checkCheckpointFits, checkPacksFit, checkVmKeyFits, packDigestsOf, fdTableBytes, parseCheckpoint, restoreFdTable, resumePorts, sha256Hex, validateFdTable,
|
|
50
|
+
CheckpointError, serviceErrorCode, assembleCheckpoint, bootKeyForLayout, bootKeyOf, checkCheckpointFits, checkPacksFit, checkVmKeyFits, packDigestsOf, fdTableBytes, parseCheckpoint, restoreFdTable, resumePorts, sha256Hex, validateFdTable,
|
|
51
51
|
} from './host/ckpt.js'
|
|
52
52
|
import { captureJit, jitSnapStats, modulesOf, ownersNeedingHub, restoreStore } from './host/jit-snap.js'
|
|
53
53
|
export { CheckpointError, memoryStore, opfsStore } from './host/ckpt.js'
|
|
@@ -223,13 +223,15 @@ const fmtMiB = n => (Number.isFinite(n) ? `${Math.round((n / MiB) * 10) / 10} Mi
|
|
|
223
223
|
* maximum is the whole 4 GiB (MEMORY0_SLACK_MIB): `slack` and maxPages cannot give more room there, so the text says a smaller guest RAM or
|
|
224
224
|
* dropping the option (X24). Every other layout gets the one text it always had.
|
|
225
225
|
*/
|
|
226
|
-
export function outOfMemoryText({ memoryBytes, memoryMaxBytes, reason, ramInMemory0 = false }) {
|
|
226
|
+
export function outOfMemoryText({ memoryBytes, memoryMaxBytes, reason, ramInMemory0 = false, named = true }) {
|
|
227
227
|
const head = `out of memory: the emulator used ${fmtMiB(memoryBytes)} of its ${fmtMiB(memoryMaxBytes)} memory maximum and stopped (${reason}); `
|
|
228
228
|
if (ramInMemory0) {
|
|
229
|
+
// `named`: the caller set the option itself. When the default or a checkpoint chose the layout there is no option to drop: say how to ask for the flat layout.
|
|
230
|
+
const way = named ? 'drop the option ramInMemory0 (the flat layout)' : 'ask for the flat layout (ramInMemory0: false, or flatRam: true)'
|
|
229
231
|
return (
|
|
230
232
|
head +
|
|
231
233
|
"the option ramInMemory0 keeps the guest's RAM in memory 0 and fixes its maximum at the whole 4 GiB, so there is no more room to give: " +
|
|
232
|
-
|
|
234
|
+
`use a smaller guest RAM (--ram), or ${way}`
|
|
233
235
|
)
|
|
234
236
|
}
|
|
235
237
|
return head + "give it more room above the guest's RAM (bootWmd maxPages, memoryMaxPages(args, slackMiB))"
|
|
@@ -291,12 +293,27 @@ export function memory0RamLimit(nav = globalThis.navigator, mem64 = haveMemory64
|
|
|
291
293
|
}
|
|
292
294
|
|
|
293
295
|
/**
|
|
294
|
-
* X24:
|
|
295
|
-
*
|
|
296
|
-
|
|
296
|
+
* X24 default (#70): the value of the option `ramInMemory0` when the caller does not name it. This is the one line the flip changes
|
|
297
|
+
* (the test page's `?asDefault=1` and the unit tests set it, so they take the code path the flip takes). Not a caller's setting.
|
|
298
|
+
*/
|
|
299
|
+
export const RAM_IN_MEMORY0 = { default: true }
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Whether the option `ramInMemory0` is on for this value: absent (undefined or null) is RAM_IN_MEMORY0.default; a value that is named
|
|
303
|
+
* is on only when it is exactly true (false, 0, 1, '1', 'true' are off).
|
|
304
|
+
*/
|
|
305
|
+
export function ramInMemory0On(v) {
|
|
306
|
+
return v === undefined || v === null ? RAM_IN_MEMORY0.default === true : v === true
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* X24: whether the option `ramInMemory0` (on for `o.ramInMemory0`, see ramInMemory0On) puts this boot's RAM in memory 0 although it is
|
|
311
|
+
* above MAX_BROWSER_RAM_MIB: true only when the option is on, flatRam is not forced on and --ram is above MAX_BROWSER_RAM_MIB and at
|
|
312
|
+
* most the engine's limit. An option that is on only by the default gives way to a caller's own allowLargeRam: true (its memory 0, its slack).
|
|
297
313
|
*/
|
|
298
314
|
export function wantsRamInMemory0(args, o = {}, nav = globalThis.navigator, mem64 = haveMemory64()) {
|
|
299
|
-
if (o.ramInMemory0
|
|
315
|
+
if (!ramInMemory0On(o.ramInMemory0) || o.flatRam === true) return false
|
|
316
|
+
if ((o.ramInMemory0 === undefined || o.ramInMemory0 === null) && o.allowLargeRam === true) return false
|
|
300
317
|
let mib = 0
|
|
301
318
|
try {
|
|
302
319
|
mib = ramMiB(args, true)
|
|
@@ -444,6 +461,80 @@ export function memoryMaxPages(args, slackMiB = 1024, allowLargeRam = false) {
|
|
|
444
461
|
return Math.min(65536, pages)
|
|
445
462
|
}
|
|
446
463
|
|
|
464
|
+
/**
|
|
465
|
+
* X24 default (#70): the RAM layout a checkpoint (or base snapshot) header says it was taken with: {flat, maxPages}, or null when the header
|
|
466
|
+
* does not say it plainly (no boot description, an environment that is not a list, a memory maximum that is not a whole number of pages
|
|
467
|
+
* between vm.wasm's minimum and 4 GiB, a RAM size in `ramPages` that is not this boot's --ram, ramPages and the environment entry
|
|
468
|
+
* WMD_RAM_FLAT=1 that disagree, or another --ram than `mib`). A null header is refused later by checkCheckpointFits with the text it always had.
|
|
469
|
+
*/
|
|
470
|
+
export function checkpointLayout(h, mib) {
|
|
471
|
+
const d = h && h.bootDesc
|
|
472
|
+
if (!mib || !d || !Array.isArray(d.env) || !Array.isArray(h.args)) return null
|
|
473
|
+
let hm = 0
|
|
474
|
+
try {
|
|
475
|
+
hm = ramMiB(h.args, true)
|
|
476
|
+
} catch {
|
|
477
|
+
return null
|
|
478
|
+
}
|
|
479
|
+
if (hm !== mib) return null
|
|
480
|
+
const mp = d.maxPages
|
|
481
|
+
if (!Number.isInteger(mp) || mp < VM_MIN_PAGES || mp > MEMORY0_MAX_PAGES) return null
|
|
482
|
+
const rp = h.ramPages === undefined ? 0 : h.ramPages
|
|
483
|
+
if (!Number.isInteger(rp) || rp < 0) return null
|
|
484
|
+
const flat = rp > 0
|
|
485
|
+
if (flat !== d.env.includes('WMD_RAM_FLAT=1')) return null
|
|
486
|
+
if (flat && rp !== mib * 16) return null
|
|
487
|
+
return { flat, maxPages: mp }
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* X24 default (#70): the RAM layout of a boot: {flat, maximum (memory 0's maximum, pages), ramPages (the RAM memory's 64 KiB pages, 0 when the
|
|
492
|
+
* RAM is in memory 0), ramMiB, why, options, changed}. The options choose it (flatRam; else the option ramInMemory0, whose value is
|
|
493
|
+
* RAM_IN_MEMORY0.default when absent; else allowLargeRam; else the RAM size), and a checkpoint or base snapshot header, when it says its own
|
|
494
|
+
* layout (checkpointLayout) and this browser can make it, decides instead: a flat checkpoint boots flat and a memory 0 checkpoint boots
|
|
495
|
+
* memory 0, with the checkpoint's memory maximum, whatever the default or the options say. `why` is 'checkpoint', 'flatRam',
|
|
496
|
+
* 'ramInMemory0' (the option named true), 'default' (the option on by the default), 'allowLargeRam' or 'ram' (the RAM size alone);
|
|
497
|
+
* `options` is the layout the options alone would have chosen and `changed` says the checkpoint moved it. Throws what a boot threw
|
|
498
|
+
* for a bad or too big --ram (the old refusal text) and for flatRam: true in a browser with no memory64.
|
|
499
|
+
*/
|
|
500
|
+
export function chooseLayout(args, o = {}, header = null, nav = globalThis.navigator, mem64 = haveMemory64()) {
|
|
501
|
+
let mib = 0
|
|
502
|
+
try {
|
|
503
|
+
mib = ramMiB(args, true)
|
|
504
|
+
} catch {
|
|
505
|
+
mib = 0 // ramMiB (below, or the caller) reports the bad value
|
|
506
|
+
}
|
|
507
|
+
const flat0 = wantsFlatRam(args, o, nav, mem64)
|
|
508
|
+
const whole0 = !flat0 && wantsRamInMemory0(args, o, nav, mem64)
|
|
509
|
+
if (!flat0) ramMiB(args, o.allowLargeRam || whole0) // a bad or too big --ram is a clear error before anything is downloaded
|
|
510
|
+
const maximum0 = o.maxPages || (flat0 ? flatMaxPages(args) : memoryMaxPagesFor(args, o, 1024, nav, mem64))
|
|
511
|
+
const named = o.ramInMemory0 !== undefined && o.ramInMemory0 !== null
|
|
512
|
+
const why0 =
|
|
513
|
+
o.flatRam === true || o.flatRam === false
|
|
514
|
+
? 'flatRam'
|
|
515
|
+
: whole0
|
|
516
|
+
? named
|
|
517
|
+
? 'ramInMemory0'
|
|
518
|
+
: 'default'
|
|
519
|
+
: mib > MAX_BROWSER_RAM_MIB && o.allowLargeRam === true
|
|
520
|
+
? 'allowLargeRam'
|
|
521
|
+
: 'ram'
|
|
522
|
+
const kind = (flat, maxPages) => (flat ? 'flat' : mib > MAX_BROWSER_RAM_MIB && maxPages === MEMORY0_MAX_PAGES ? 'whole' : 'plain')
|
|
523
|
+
const out = (flat, maximum, why, changed) => ({ flat, maximum, ramPages: flat ? mib * 16 : 0, ramMiB: mib, why, options: flat0 ? 'flat' : 'memory0', changed })
|
|
524
|
+
const ck = header ? checkpointLayout(header, mib) : null
|
|
525
|
+
if (ck) {
|
|
526
|
+
// can this browser make the layout the checkpoint has? flat needs a second memory; memory 0 above 1536 MiB needs the engine's limit or allowLargeRam
|
|
527
|
+
const can = ck.flat
|
|
528
|
+
? mem64
|
|
529
|
+
: mib <= MAX_BROWSER_RAM_MIB || (ck.maxPages === MEMORY0_MAX_PAGES && mib <= memory0RamLimit(nav, mem64)) || o.allowLargeRam === true
|
|
530
|
+
if (can) {
|
|
531
|
+
const moved = kind(ck.flat, ck.maxPages) !== kind(flat0, maximum0)
|
|
532
|
+
return out(ck.flat, moved ? ck.maxPages : maximum0, 'checkpoint', moved)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return out(flat0, maximum0, why0, false)
|
|
536
|
+
}
|
|
537
|
+
|
|
447
538
|
/**
|
|
448
539
|
* Time the throttle detector's calibration loop n times now (in its own Worker) and
|
|
449
540
|
* resolve with the fastest run, in ms. A page can call this while it is in the
|
|
@@ -630,13 +721,29 @@ export async function bootWmd(o) {
|
|
|
630
721
|
// The flat layout (host/ram-mem.js): a guest with more RAM than memory 0 can hold gets its RAM in a memory64 of its
|
|
631
722
|
// own. Chosen when --ram is above MAX_BROWSER_RAM_MIB and the engine has memory64 (o.flatRam forces it on or off);
|
|
632
723
|
// without it such a --ram is the error it was.
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
724
|
+
// X24 default (#70): chooseLayout. A restore (o.restore, or a base snapshot's header once it is known) boots with the layout its checkpoint
|
|
725
|
+
// was taken with, whatever the default or the options say; settleLayout makes the second memory of a flat layout and tells the page once.
|
|
726
|
+
const layout0 = chooseLayout(o.args, o, o.restore?.header || null) // a bad or too big --ram is a clear error before anything is downloaded
|
|
727
|
+
let layout = layout0
|
|
728
|
+
let flatRam = layout0.flat
|
|
729
|
+
let maximum = layout0.maximum
|
|
730
|
+
let ramMem = null
|
|
638
731
|
/** The RAM memory's pages (0: the RAM is in memory 0). A checkpoint of a flat guest also holds its RAM memory's pages (sections ram-index, ram). */
|
|
639
|
-
|
|
732
|
+
let ramPages = 0
|
|
733
|
+
let layoutSaid = false
|
|
734
|
+
const settleLayout = L => {
|
|
735
|
+
layout = L
|
|
736
|
+
flatRam = L.flat
|
|
737
|
+
maximum = L.maximum
|
|
738
|
+
const i = env.indexOf('WMD_RAM_FLAT=1')
|
|
739
|
+
if (i >= 0) env.splice(i, 1)
|
|
740
|
+
if (flatRam) env.push('WMD_RAM_FLAT=1')
|
|
741
|
+
ramMem = flatRam ? createRamMemory(L.ramMiB) : null
|
|
742
|
+
ramPages = L.ramPages // = ramMem.buffer.byteLength / CKPT_PAGE: createRamMemory(mib) holds mib * 16 pages
|
|
743
|
+
layoutSaid = true
|
|
744
|
+
be.now('layout', { t: 'boot', stage: 'layout', layout: flatRam ? 'flat' : 'memory0', why: L.why, options: L.options, ramMiB: L.ramMiB, maxPages: L.maximum })
|
|
745
|
+
}
|
|
746
|
+
if (!o.restoreLazy) settleLayout(layout0) // a base snapshot's layout is known when its header is
|
|
640
747
|
// P-B9: checkpoints. restoreIn: the checkpoint's parts (parseCheckpoint refuses a malformed one).
|
|
641
748
|
const ckptOn = !!o.checkpoint || !!o.restore || !!o.restoreLazy
|
|
642
749
|
let restoreIn = o.restore ? parseCheckpoint(o.restore) : null
|
|
@@ -782,12 +889,14 @@ export async function bootWmd(o) {
|
|
|
782
889
|
try {
|
|
783
890
|
const h = await raceAbort(lazyIn.header)
|
|
784
891
|
checkVmKeyFits(h, vmKey)
|
|
892
|
+
settleLayout(chooseLayout(o.args, o, h)) // X24 default: the base snapshot's own layout
|
|
785
893
|
lazyIn.proceed?.() // the reader decodes only from here: a refused header costs what was queued, not the file
|
|
786
894
|
} catch (err) {
|
|
787
895
|
if (signal?.aborted) throw err
|
|
788
896
|
baseRefused(err)
|
|
789
897
|
}
|
|
790
898
|
}
|
|
899
|
+
if (!layoutSaid) settleLayout(layout0) // no base snapshot, or its header was refused: the options' layout
|
|
791
900
|
const tc = absMs()
|
|
792
901
|
be.now('compile', { t: 'boot', stage: 'compile', state: 'start', moduleBytes: vmBytes.byteLength, reused: !!A })
|
|
793
902
|
module = A ? A.module : await raceAbort(WebAssembly.compile(vmBytes))
|
|
@@ -808,9 +917,17 @@ export async function bootWmd(o) {
|
|
|
808
917
|
const tk = absMs()
|
|
809
918
|
let packs
|
|
810
919
|
if (A) {
|
|
811
|
-
bootKey = A.keys.bootKey
|
|
812
|
-
bootDesc = A.keys.bootDesc
|
|
813
920
|
packs = A.keys.packs
|
|
921
|
+
const ad = A.keys.bootDesc
|
|
922
|
+
if (!ad || (ad.maxPages === maximum && Array.isArray(ad.env) && ad.env.includes('WMD_RAM_FLAT=1') === flatRam)) {
|
|
923
|
+
bootKey = A.keys.bootKey
|
|
924
|
+
bootDesc = A.keys.bootDesc
|
|
925
|
+
} else {
|
|
926
|
+
// X24 default: the checkpoint chose another RAM layout than the machine these assets came from had: the same key, with that layout
|
|
927
|
+
const k = await bootKeyForLayout(ad, { flat: flatRam, maxPages: maximum })
|
|
928
|
+
bootKey = k.key
|
|
929
|
+
bootDesc = k.desc
|
|
930
|
+
}
|
|
814
931
|
} else {
|
|
815
932
|
// the boot key samples each pack (head and tail); packs is the full digest of every layer (a SHA-256 tree over 8 MiB pieces), recorded in
|
|
816
933
|
// every checkpoint this boot takes and checked against a base snapshot's before it is used
|
|
@@ -1406,7 +1523,8 @@ export async function bootWmd(o) {
|
|
|
1406
1523
|
memoryBytes: timings.memoryBytes,
|
|
1407
1524
|
memoryMaxBytes: timings.memoryMaxBytes,
|
|
1408
1525
|
reason,
|
|
1409
|
-
ramInMemory0: !flatRam &&
|
|
1526
|
+
ramInMemory0: !flatRam && maximum === MEMORY0_MAX_PAGES && layout.ramMiB > MAX_BROWSER_RAM_MIB, // X24: the whole 4 GiB, no room to give
|
|
1527
|
+
named: o.ramInMemory0 === true, // the caller set the option itself (else the default or a checkpoint chose the layout)
|
|
1410
1528
|
})
|
|
1411
1529
|
emitErr(`\n[wmd-web] ${reason}\n`)
|
|
1412
1530
|
}
|
|
@@ -2014,7 +2132,12 @@ export async function bootWmd(o) {
|
|
|
2014
2132
|
try {
|
|
2015
2133
|
// everything that can fail without harming the running machine comes first: the checkpoint parses and is this boot's
|
|
2016
2134
|
const parsed = parseCheckpoint(ckpt)
|
|
2017
|
-
|
|
2135
|
+
// X24 default (#70): the checkpoint decides the next machine's RAM layout (bootWmd does the same from the same header), so the check is
|
|
2136
|
+
// made against that layout's key, memory maximum and RAM memory, not this machine's
|
|
2137
|
+
const L = chooseLayout(o.args, { ...o, ...over }, parsed.header)
|
|
2138
|
+
let target = { key: bootKey, desc: bootDesc }
|
|
2139
|
+
if (bootDesc && (L.flat !== flatRam || L.maximum !== maximum)) target = await bootKeyForLayout(bootDesc, { flat: L.flat, maxPages: L.maximum })
|
|
2140
|
+
checkCheckpointFits(parsed.header, { vmKey, bootKey: target.key, bootDesc: target.desc, maxPages: L.maximum, ramPages: L.ramPages, hasJit: o.jit !== false, fmaFused: fmaFuses() })
|
|
2018
2141
|
if (!heldAssets) throw new CheckpointError('not-ready', 'this machine was booted without checkpoint support: it has no kept boot files to restore with')
|
|
2019
2142
|
validateFdTable(parsed.ctl, heldAssets.files.length) // the fd table is checked against this boot's files now, not after the old machine is gone
|
|
2020
2143
|
// the boot's own bytes (vm.wasm and its compiled Module, the kernel, the packs, the keys) are reused: nothing is
|
package/src/build/builder.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// is built in the page instead (fast.js), unless fast: false.
|
|
8
8
|
|
|
9
9
|
import { blobBytes } from '../blob.js'
|
|
10
|
-
import { bootWmd, isWebKit } from '../boot.js'
|
|
10
|
+
import { bootWmd, isWebKit, memory0RamLimit, ramInMemory0On } from '../boot.js'
|
|
11
11
|
import { MAIN_PROC_ID, containerBundle, fillRunRequest } from '../host/ctl.js'
|
|
12
12
|
import { DiskError, deleteDisk, openDisk, sweepDisks } from '../host/disk.js'
|
|
13
13
|
import { p9OptsOfVm } from '../host/p9mount.js'
|
|
@@ -397,7 +397,7 @@ function aborted(signal) {
|
|
|
397
397
|
* the packs of an {index, packs} or a store hit must match the index's layer digests
|
|
398
398
|
* @param {{url: string, protocol?: 'wisp'}} o.relay the guest's network
|
|
399
399
|
* @param {number} [o.ram] MiB (default 1536)
|
|
400
|
-
* @param {boolean} [o.ramInMemory0] X24 (default
|
|
400
|
+
* @param {boolean} [o.ramInMemory0] X24 (off by default until the default flips; absent follows boot.js's RAM_IN_MEMORY0.default; only exactly true is on, only exactly false is off): a RAM above 1536 MiB up to the engine's limit (boot.js MEMORY0_RAM_MAX_MIB) stays in memory 0, not flat; above it, flat as today
|
|
401
401
|
* @param {number} [o.cpus] default 2
|
|
402
402
|
* @param {{namespace: string, mib?: number}|false} o.disk BuildKit's storage in OPFS (default 10240 MiB); false: memory
|
|
403
403
|
* @param {string|Uint8Array} o.converter wmdpack.wasm
|
|
@@ -572,7 +572,8 @@ export async function createBuilder(o) {
|
|
|
572
572
|
...(o.features !== undefined ? { features: o.features } : {}), // X23: the guest folder's `features` (text, array or Set) when the files are bytes; with URLs bootWmd reads the folder's file
|
|
573
573
|
args,
|
|
574
574
|
// X24: with o.ramInMemory0 === true (boot.js's rule: only exactly true) a RAM above 1536 MiB up to the engine's limit stays in memory 0 (boot.js decides); above it, flat
|
|
575
|
-
|
|
575
|
+
// X24 default (#70): an option that is absent is boot.js's RAM_IN_MEMORY0.default; false is the way out (flat above 1536 MiB, as before the default)
|
|
576
|
+
...(o.ramInMemory0 === true || (ramInMemory0On(o.ramInMemory0) && ram > 1536 && ram <= memory0RamLimit()) ? { ramInMemory0: true } : ram > 1536 ? { flatRam: true } : {}),
|
|
576
577
|
...(disk ? { disk } : {}),
|
|
577
578
|
onStderr: s => {
|
|
578
579
|
stderr = (stderr + s).slice(-16384)
|
package/src/host/ckpt.js
CHANGED
|
@@ -90,6 +90,22 @@ export async function bootKeyOf({ vmKey, argv, env, preopen, files, services, ma
|
|
|
90
90
|
return { key: await sha256Hex(new TextEncoder().encode(JSON.stringify(desc))), desc }
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* X24 default (#70): a boot description (bootKeyOf's desc) with another RAM layout: the environment entry WMD_RAM_FLAT=1 (kept last, where
|
|
95
|
+
* bootWmd puts it) present or not, and the memory maximum. Nothing else changes.
|
|
96
|
+
*/
|
|
97
|
+
export function bootDescForLayout(desc, { flat, maxPages }) {
|
|
98
|
+
const env = (desc.env || []).filter(e => e !== 'WMD_RAM_FLAT=1')
|
|
99
|
+
if (flat) env.push('WMD_RAM_FLAT=1')
|
|
100
|
+
return { ...desc, env, maxPages }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** X24 default: the key and description of the boot that bootDesc describes, in another RAM layout (no file or pack is read again). */
|
|
104
|
+
export async function bootKeyForLayout(desc, layout) {
|
|
105
|
+
const d = bootDescForLayout(desc, layout)
|
|
106
|
+
return { key: await sha256Hex(new TextEncoder().encode(JSON.stringify(d))), desc: d }
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
/** The ports a resume writes for the guest (vm_resume_args), from the command line. */
|
|
94
110
|
export function resumePorts(args) {
|
|
95
111
|
const get = name => {
|
package/wmdpack.wasm
CHANGED
|
Binary file
|