Skip to content

Commit 0dca292

Browse files
committed
New experimental --env=RUNCVM_HUGETLB=1 option
- New experimental `--env=RUNCVM_HUGETLB=1` option enables use of preallocated hugetlb memory backend, which can improve performance in some scenarios
1 parent c92d916 commit 0dca292

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ Enable breakpoints (falling to bash shell) during the RunCVM container/VM boot p
339339

340340
`<values>` must be a comma-separated list of: `prenet`, `postnet`, `preqemu`.
341341

342+
### `--env=RUNCVM_HUGETLB=1`
343+
344+
**[EXPERIMENTAL]** Enable use of preallocated hugetlb memory backend, which can improve performance in some scenarios.
345+
342346
## Advanced usage
343347

344348
### Running Docker in a RunCVM container/VM

runcvm-scripts/runcvm-ctr-defaults

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ clean_env() {
1313
RUNCVM_RUNTIME_DEBUG RUNCVM_BIOS_DEBUG RUNCVM_KERNEL_DEBUG \
1414
RUNCVM_KERNEL RUNCVM_KERNEL_ROOT RUNCVM_KERNEL_APPEND RUNCVM_KERNEL_INITRAMFS_PATH RUNCVM_KERNEL_PATH RUNCVM_DISKS \
1515
RUNCVM_UIDGID RUNCVM_VM_MOUNTPOINT RUNCVM_TMPFS \
16-
RUNCVM_CPUS RUNCVM_MEM_SIZE RUNCVM_HAS_HOME
16+
RUNCVM_CPUS RUNCVM_MEM_SIZE RUNCVM_HUGETLB \
17+
RUNCVM_HAS_HOME
1718

1819
# May be set in VM by busybox init process
1920
export -n USER

runcvm-scripts/runcvm-ctr-qemu

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,31 @@ fi
142142
# Disable IPv6, which is currently unsupported, at kernel boot time
143143
APPEND+=(ipv6.disable=1)
144144

145+
# 16-64 works well and is more performant than 1024 in some scenarios.
146+
# For now, stick with original figure.
147+
VIRTIOFS_QUEUE_SIZE=1024
148+
149+
if [ "$RUNCVM_HUGETLB" != "1" ]; then
150+
# Tests suggests prealloc=on slows down mem-path=/dev/shm
151+
MEM_PATH=/dev/shm MEM_PREALLOC=off
152+
MEM_BACKEND="-object memory-backend-file,id=mem,size=$RUNCVM_MEM_SIZE,mem-path=$MEM_PATH,share=on,prealloc=$MEM_PREALLOC"
153+
else
154+
# Fastest performance: +15% CPU/net intensive; 3.5x disk intensive.
155+
MEM_BACKEND="-object memory-backend-memfd,id=mem,size=$RUNCVM_MEM_SIZE,share=on,prealloc=on,hugetlb=on"
156+
fi
157+
145158
ARGS=(
146159
"${OPTS[@]}"
147160
-no-user-config
148161
-nodefaults
149162
-serial $SERIAL
150163
-m "$RUNCVM_MEM_SIZE"
151164
-chardev socket,id=char0,path=$QEMU_VIRTIOFSD_SOCKET
152-
-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs,ats=on
165+
-device vhost-user-fs-pci,queue-size=$VIRTIOFS_QUEUE_SIZE,chardev=char0,tag=myfs,ats=on
153166
-kernel $RUNCVM_KERNEL_PATH
154167
-initrd $RUNCVM_KERNEL_INITRAMFS_PATH
155168
-append "$RUNCVM_KERNEL_ROOT $INIT rw ${APPEND[*]} $PANIC $RUNCVM_KERNEL_APPEND $BREAK"
156-
-object memory-backend-file,id=mem,size="$RUNCVM_MEM_SIZE",mem-path=/dev/shm,share=on
169+
$MEM_BACKEND
157170
-numa node,memdev=mem
158171
-smp $RUNCVM_CPUS
159172
# Configure host/container tap device with PXE roms disabled

runcvm-scripts/runcvm-runtime

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,13 @@ if [ "$COMMAND" = "create" ]; then
427427
fi
428428
log "RUNCVM_MEM_SIZE=$RUNCVM_MEM_SIZE"
429429
set_config_env "RUNCVM_MEM_SIZE" "$RUNCVM_MEM_SIZE"
430-
jq_set "$CFG" --arg size "$RUNCVM_MEM_SIZE" '( .mounts[] | select(.destination == "/dev/shm") ) = {"destination": "/dev/shm","type": "tmpfs","source": "shm","options": ["nosuid","noexec","nodev","mode=1777","size=" + $size]}'
430+
431+
RUNCVM_HUGETLB=$(get_config_env "RUNCVM_HUGETLB")
432+
if [ "$RUNCVM_HUGETLB" != "1" ]; then
433+
jq_set "$CFG" --arg size "$RUNCVM_MEM_SIZE" '( .mounts[] | select(.destination == "/dev/shm") ) = {"destination": "/dev/shm","type": "tmpfs","source": "shm","options": ["nosuid","noexec","nodev","mode=1777","size=" + $size]}'
434+
# else
435+
# --shm-size applies; default 64m.
436+
fi
431437

432438
# In future, set the container memory limit to something reasonable to support
433439
# QEMU + virtiofsd + dnsmasq. Perhaps $RUNCVM_MEM_LIMIT+K (or vice-versa, reduce

0 commit comments

Comments
 (0)