Unverified Commit 52c52ab5 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Add ballooning PID file (#1091)

parent 2a1b13da
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -3,7 +3,9 @@ set -Eeuo pipefail

: "${BALLOONING:="N"}"
: "${BALLOONING_DEBUG:="N"}"
: "${BALLOONING_PID:="$QEMU_DIR/balloon.pid"}"

rm -f "$BALLOONING_PID"
[[ "$BALLOONING" != [Yy1]* ]] && return 0

# By default, the VM is allocated the full amount of RAM configured via RAM_SIZE for its entire lifetime, but if you want
@@ -30,7 +32,7 @@ set -Eeuo pipefail
# Warning: if the container memory limit is reduced at runtime below the guest VM's current memory usage, the container
# may be killed by the OOM killer if the ballooning driver cannot reclaim memory from the guest fast enough.

ballooning() {
balloon() {

  # Wait for qemu PID file to be created
  while [ ! -f "$QEMU_PID" ]; do
@@ -54,12 +56,16 @@ ballooning() {
    BALLOON_ARGS+=(--debug "$BALLOONING_DEBUG")
  fi

  python3 ./balloon.py --qmp-sock "$QEMU_DIR/qemu-qmp-ballooning.sock" --qemu-pid-file "$QEMU_PID" "${BALLOON_ARGS[@]}"
  python3 ./balloon.py --qmp-sock "$QEMU_DIR/qemu-qmp-ballooning.sock" --qemu-pid-file "$QEMU_PID" "${BALLOON_ARGS[@]}" &
  local pid="$!"
  echo "$pid" > "$BALLOONING_PID"
  wait "$pid"
  rm -f -- "$BALLOONING_PID"
}

msg="Starting memory ballooning monitor..."
info "$msg"

( ballooning ) &
( balloon ) &

return 0
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ finish() {
  local i=0
  local pid=""
  local reason=$1
  local pids=( "$TPM_PID" "$WSD_PID" "$WEB_PID" "$PASST_PID" "$DNSMASQ_PID" )
  local pids=( "$TPM_PID" "$WSD_PID" "$WEB_PID" "$PASST_PID" "$DNSMASQ_PID" "${BALLOONING_PID:-}" )

  touch "$QEMU_END"
  (( reason != 0 )) && (( reason != 143 )) && echo "QEMU exitcode: $reason"