Skip to content

Commit 022e11a

Browse files
authored
Merge pull request #299 from facebookexperimental/wait_balloon
Wait for memory balloon allocation
2 parents f8c32cd + b4dfc0b commit 022e11a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

rd-agent/src/side.rs

+2
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ impl Balloon {
512512
)?;
513513

514514
svc.set_slice(Slice::Sys.name())
515+
// Make sure memory allocation completed once started
516+
.add_prop("Type".into(), systemd::Prop::String("notify".into()))
515517
.add_prop("MemorySwapMax".into(), systemd::Prop::U64(0))
516518
.add_prop(
517519
"Slice".into(),

rd-agent/src/side/memory-balloon.py

+17
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22
# Copyright (c) Facebook, Inc. and its affiliates
33

44
import mmap
5+
import os
56
import sys
67
import time
8+
import socket
79

810

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

15+
try:
16+
sd_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
17+
sd_addr = os.getenv("NOTIFY_SOCKET")
18+
assert sd_addr, "$NOTIFY_SOCKET not available"
19+
sd_socket.connect(sd_addr)
20+
except Exception:
21+
print("Failed to create systemd socket")
22+
raise
23+
1324
nr_pages = int((int(sys.argv[1]) + 4095) / 4096)
1425
mm = mmap.mmap(-1, nr_pages * 4096, flags=mmap.MAP_PRIVATE)
1526

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

35+
try:
36+
sd_socket.sendall(b"READY=1")
37+
except Exception:
38+
print("Failed to send ready notification to systemd")
39+
raise
40+
2441
print("Allocation done, sleeping...")
2542
while True:
2643
time.sleep(600)

0 commit comments

Comments
 (0)