Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for memory balloon allocation #299

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading