Skip to content

Commit

Permalink
Wait for memory balloon allocation
Browse files Browse the repository at this point in the history
On machines with larger memory footprint like >100GB, not waiting for
balloon memory allocation could cause following resctl-bench runs to
fail.
Make the balloon service notify systemd once it completes allocation.
  • Loading branch information
lnyng committed Jan 11, 2024
1 parent f8c32cd commit b4dfc0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rd-agent/src/side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ impl Balloon {
)?;

svc.set_slice(Slice::Sys.name())
// Make sure memory allocation completed once started
.add_prop("Type".into(), systemd::Prop::String("notify".into()))
.add_prop("MemorySwapMax".into(), systemd::Prop::U64(0))
.add_prop(
"Slice".into(),
Expand Down
17 changes: 17 additions & 0 deletions rd-agent/src/side/memory-balloon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
# Copyright (c) Facebook, Inc. and its affiliates

import mmap
import os
import sys
import time
import socket


if len(sys.argv) < 2:
print("Usage: memory-balloon.py BYTES", file=sys.stderr)
sys.exit(1)

try:
sd_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
sd_addr = os.getenv("NOTIFY_SOCKET")
assert sd_addr, "$NOTIFY_SOCKET not available"
sd_socket.connect(sd_addr)
except Exception:
print("Failed to create systemd socket")
raise

nr_pages = int((int(sys.argv[1]) + 4095) / 4096)
mm = mmap.mmap(-1, nr_pages * 4096, flags=mmap.MAP_PRIVATE)

Expand All @@ -21,6 +32,12 @@
print(f"Touched {i * 4096 / (1 << 30):.2f}G")
last_at = time.time()

try:
sd_socket.sendall(b"READY=1")
except Exception:
print("Failed to send ready notification to systemd")
raise

print("Allocation done, sleeping...")
while True:
time.sleep(600)

0 comments on commit b4dfc0b

Please sign in to comment.