Skip to content

Agent Mesh

scale: share one rootfs instead of copying it per agent

Antonio Ojeae11e08502295
diff --git a/scripts/launch-microvms.sh b/scripts/launch-microvms.sh
index 6774c3a9..f109fca9 100755
--- a/scripts/launch-microvms.sh
+++ b/scripts/launch-microvms.sh
@@ -194,7 +194,7 @@ EOF
fc_put "$API_SOCKET" /boot-source "{
\"kernel_image_path\": \"$WORKDIR/vmlinux.bin\",
- \"boot_args\": \"console=ttyS0 reboot=k panic=1 pci=off\"
+ \"boot_args\": \"console=ttyS0 reboot=k panic=1 pci=off ro\"
}"
fc_put "$API_SOCKET" /machine-config "{
@@ -202,12 +202,15 @@ EOF
\"mem_size_mib\": $VM_MEM_MIB
}"
- cp "$WORKDIR/rootfs.ext4" "$WORKDIR/rootfs-$VM_ID.ext4"
+ # One rootfs, shared read-only by every sandbox. A private copy per agent
+ # is 500 MB of disk and a 500 MB write before the guest can even boot,
+ # which at a thousand agents exhausts the disk long before the memory. The
+ # guest gives itself tmpfs for the few paths that must be writable.
fc_put "$API_SOCKET" /drives/rootfs "{
\"drive_id\": \"rootfs\",
- \"path_on_host\": \"$WORKDIR/rootfs-$VM_ID.ext4\",
+ \"path_on_host\": \"$WORKDIR/rootfs.ext4\",
\"is_root_device\": true,
- \"is_read_only\": false
+ \"is_read_only\": true
}"
# Guest CID 3 is the first available guest CID. Connections the guest makes
diff --git a/scripts/microvm-init.sh b/scripts/microvm-init.sh
index 860cce35..e12d5229 100755
--- a/scripts/microvm-init.sh
+++ b/scripts/microvm-init.sh
@@ -19,6 +19,17 @@ mount -t proc proc /proc 2>/dev/null || true
mount -t sysfs sysfs /sys 2>/dev/null || true
mount -t devtmpfs devtmpfs /dev 2>/dev/null || true
+# The root filesystem is shared read-only by every sandbox on the host, because
+# a private 500 MB copy per agent is half a terabyte at a thousand agents and
+# the disk is the first thing to run out. Nothing here needs to persist, so the
+# few paths that must be writable are given tmpfs and the rest stays shared.
+mount -t tmpfs tmpfs /tmp 2>/dev/null || true
+if ! touch /etc/.writable 2>/dev/null; then
+ mkdir -p /tmp/etc && cp -a /etc/. /tmp/etc/ 2>/dev/null || true
+ mount --bind /tmp/etc /etc 2>/dev/null || true
+fi
+rm -f /etc/.writable 2>/dev/null || true
+
TASK="${AGENT_TASK:-Describe the tools you have and what each is for.}"
# The kernel hands PID 1 an empty environment, so there is no PATH to inherit