Skip to content

Commit a5e058a

Browse files
committed
fix: reduce heap to 2.25 GiB and re-enable initrd mapping on restore
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 3647224 commit a5e058a

4 files changed

Lines changed: 13 additions & 26 deletions

File tree

examples/python-agent-driver/hl_pydriver.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,6 @@ static void py_initialize_once(void)
259259
" except Exception as _e:\n"
260260
" sys.stderr.write(f'warn: preload {_mod} failed: {_e}\\n')\n");
261261

262-
/* Exercise pyarrow's pandas shim so it imports pandas_compat,
263-
* vendored.version, etc. during warmup. Without this, the shim
264-
* lazily imports these on first use, but after snapshot restore
265-
* (without initrd re-mapping) the .py files are zeroed pages. */
266-
PyRun_SimpleString(
267-
"try:\n"
268-
" import pyarrow.pandas_compat\n"
269-
" import pyarrow.vendored.version\n"
270-
" import pandas as _pd\n"
271-
" _pd.DataFrame({'_': ['x']})\n"
272-
" del _pd\n"
273-
"except Exception:\n"
274-
" pass\n");
275-
276262
/* Monkey-patch zipfile.ZipInfo.__init__ to clamp pre-1980 timestamps.
277263
* Unikraft's ramfs reports epoch-0 (1970) for file mtimes; Python's
278264
* zipfile rejects timestamps before 1980, breaking openpyxl's XLSX

host/src/bin/pydriver_run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> Result<()> {
4444
let t_evolve = Instant::now();
4545
let mut sandbox = Sandbox::builder(&kernel)
4646
.initrd_file(&initrd)
47-
.heap_size(5 * 512 * 1024 * 1024)
47+
.heap_size(2304 * 1024 * 1024)
4848
.build()?;
4949
eprintln!(
5050
"[timing] evolve={:.1}ms",

host/src/bin/pyhl.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ fn cmd_setup(args: SetupArgs) -> Result<()> {
451451
{
452452
let mut builder = Sandbox::builder(&dst_kernel)
453453
.initrd_file(&dst_initrd)
454-
.heap_size(5 * 512 * 1024 * 1024);
454+
.heap_size(2304 * 1024 * 1024);
455455
for p in &setup_preopens {
456456
builder = builder.preopen(p.clone());
457457
}
@@ -593,13 +593,12 @@ fn cmd_run(args: RunArgs) -> Result<()> {
593593
listen_ports.is_some(),
594594
)?;
595595

596-
// No initrd re-mapping: the snapshot already contains all initrd
597-
// pages compacted into its blob with rebuilt page tables.
596+
let initrd = home.join(INITRD_FILE);
598597
let t_load = Instant::now();
599598
let mut sandbox = Sandbox::from_snapshot_file_configured(
600599
&snapshot,
601600
&run_preopens,
602-
None,
601+
Some(&initrd),
603602
network.as_ref(),
604603
listen_ports.as_ref(),
605604
)?;

host/src/pyhl.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ pub fn install(opts: &InstallOptions<'_>) -> Result<InstallReport> {
197197
{
198198
let mut builder = Sandbox::builder(&dst_kernel)
199199
.initrd_file(&dst_initrd)
200-
.heap_size(5 * 512 * 1024 * 1024);
200+
.heap_size(2304 * 1024 * 1024);
201201
for p in opts.mounts {
202202
builder = builder.preopen(p.clone());
203203
}
@@ -274,12 +274,14 @@ impl Runtime {
274274
snap.display()
275275
);
276276
}
277-
// No initrd re-mapping needed: the snapshot already contains all
278-
// initrd pages (the snapshot walker compacts every mapped page,
279-
// including file-mapped initrd pages, into the blob and rebuilds
280-
// page tables to point at the compacted locations).
281-
let sandbox =
282-
Sandbox::from_snapshot_file_configured(&snap, mounts, None, network, listen_ports)?;
277+
let initrd = home.join(INITRD_FILE);
278+
let sandbox = Sandbox::from_snapshot_file_configured(
279+
&snap,
280+
mounts,
281+
Some(&initrd),
282+
network,
283+
listen_ports,
284+
)?;
283285
Ok(Self {
284286
sandbox,
285287
first_run: true,

0 commit comments

Comments
 (0)