Skip to content
Open
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
18 changes: 17 additions & 1 deletion helios/src/offload/pool/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,24 @@ fn peer_registration_budget_fails_startup() {

let mut manager = Manager::new();
manager.run();
#[cfg(target_os = "linux")]
let host_bytes = ["arena", "staging"]
.into_iter()
.map(|name| {
use std::os::unix::fs::MetadataExt;
let metadata = std::fs::metadata(manager.shm_directory().join(name)).unwrap();
let bytes = metadata.len();
bytes.saturating_sub(metadata.blocks().saturating_mul(512).min(bytes))
})
.sum::<u64>();
#[cfg(not(target_os = "linux"))]
let host_bytes = 16 << 20;
for rejection in 0..3 {
let reject = rejection != 2;
let reject = match rejection {
0 => host_bytes > 1,
1 => true,
_ => false,
};
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let peer_stream = TcpStream::connect(listener.local_addr().unwrap()).unwrap();
let zero_stream = listener.accept().unwrap().0;
Expand Down
53 changes: 36 additions & 17 deletions selene-manager/tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,50 @@ fn start(
fn over_budget_startup_fails_before_registering_memory() {
let mut manager = Manager::new();
manager.run();
for (budget, expected) in [
(
Budget {
host: Ok(0),
..unlimited()
},
"host budget has 0 bytes left",
),
(
Budget {
devices: vec![(1, false)],
..unlimited()
},
"budget has 1 bytes left",
),
] {
#[cfg(target_os = "linux")]
let host_bytes = ["arena", "staging"]
.into_iter()
.map(|name| {
use std::os::unix::fs::MetadataExt;
let metadata = std::fs::metadata(manager.shm_directory().join(name)).unwrap();
let bytes = metadata.len();
bytes.saturating_sub(metadata.blocks().saturating_mul(512).min(bytes))
})
.sum::<u64>();
#[cfg(not(target_os = "linux"))]
let host_bytes = 16 << 20;
let device_case = (
Budget {
devices: vec![(1, false)],
..unlimited()
},
"budget has 1 bytes left",
);
let cases = if host_bytes > 0 {
vec![
(
Budget {
host: Ok(0),
..unlimited()
},
"host budget has 0 bytes left",
),
device_case,
]
} else {
vec![device_case]
};
for (budget, expected) in cases {
let registrar = Arc::new(Registrar::default());
let reason = start(&manager, registrar.clone(), budget)
.err()
.expect("an unapproved pool must fail startup")
.to_string();
let needs = format!("needs {host_bytes} host bytes");
for text in [
"arena 8388608 bytes",
"staging 8388608 bytes",
"needs 16777216 host bytes",
needs.as_str(),
expected,
"free host/device memory",
"remove --prefix-cache-pool",
Expand Down
17 changes: 15 additions & 2 deletions selene-manager/tests/offload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ fn startup_fails_and_releases_registration_when_a_rank_rejects_the_pool() {

let mut manager = selene_manager::testing::Manager::new();
manager.run();
for local_approved in [true, false] {
#[cfg(target_os = "linux")]
let host_bytes = ["arena", "staging"]
.into_iter()
.map(|name| {
use std::os::unix::fs::MetadataExt;
let metadata = std::fs::metadata(manager.shm_directory().join(name)).unwrap();
let bytes = metadata.len();
bytes.saturating_sub(metadata.blocks().saturating_mul(512).min(bytes))
})
.sum::<u64>();
#[cfg(not(target_os = "linux"))]
let host_bytes = 16 << 20;
for zero_host in [false, true] {
let local_approved = !zero_host || host_bytes == 0;
let options = pool(&manager.address());
let geometry = vec![geometry(64, &[("kv", 4096)], 4096)];
let registrar = Arc::new(TrackingRegistrar::default());
Expand All @@ -32,7 +45,7 @@ fn startup_fails_and_releases_registration_when_a_rank_rejects_the_pool() {
gpu_uuids: vec![[1; 16]],
registration_context: 0,
budget: Budget {
host: Ok(if local_approved { u64::MAX } else { 0 }),
host: Ok(if zero_host { 0 } else { u64::MAX }),
devices: vec![(u64::MAX, false), (u64::MAX, true)],
},
peers: None,
Expand Down
13 changes: 9 additions & 4 deletions selene/src/pool/budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ pub struct Budget {

impl Budget {
pub(super) fn costs(
mut bytes: impl Iterator<Item = u64>,
mut regions: impl Iterator<Item = (u64, u64)>,
) -> std::result::Result<(u64, u64), String> {
bytes.try_fold((0u64, 0u64), |(host, device), bytes| {
regions.try_fold((0u64, 0u64), |(host, device), (bytes, backed_bytes)| {
let additional_host = bytes.saturating_sub(backed_bytes.min(bytes));
Ok((
host.checked_add(bytes).ok_or("pool host bytes overflow")?,
host.checked_add(additional_host)
.ok_or("pool host bytes overflow")?,
device
.checked_add(bytes.div_ceil(512))
.ok_or("pool device bytes overflow")?,
Expand All @@ -40,7 +42,10 @@ impl Budget {
}

pub(super) fn approve(&self, plan: &[PlannedRegion]) -> std::result::Result<(), String> {
let (host, device) = Self::costs(plan.iter().map(|region| region.bytes))?;
let (host, device) = Self::costs(
plan.iter()
.map(|region| (region.bytes, region.backed_bytes)),
)?;
let available_host = self
.host
.as_ref()
Expand Down
112 changes: 109 additions & 3 deletions selene/src/pool/budget/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ fn plan(arena: u64, staging: u64) -> Vec<PlannedRegion> {
PlannedRegion {
name: "arena",
bytes: arena,
backed_bytes: 0,
},
PlannedRegion {
name: "staging",
bytes: staging,
backed_bytes: 0,
},
]
}

#[test]
fn approval_charges_whole_regions_and_each_gpu_before_registration() {
let plan = plan(1 << 30, 1 << 29);
let (host, device) = Budget::costs(plan.iter().map(|region| region.bytes)).unwrap();
let (host, device) = Budget::costs(plan.iter().map(|region| (region.bytes, region.backed_bytes))).unwrap();
assert_eq!((host, device), (3 << 29, 3 << 20));
let budget = Budget {
host: Ok(host),
Expand All @@ -42,17 +44,25 @@ fn approval_charges_whole_regions_and_each_gpu_before_registration() {
devices: vec![(device, false), (device - 1, false)],
};
assert!(budget.approve(&plan).unwrap_err().contains("GPU 1"));
assert!(Budget::costs(self::plan(u64::MAX, 1).iter().map(|region| region.bytes)).is_err());
assert!(
Budget::costs(
self::plan(u64::MAX, 1)
.iter()
.map(|region| (region.bytes, region.backed_bytes))
)
.is_err()
);
}

#[test]
fn remote_staging_and_shared_memory_use_the_same_budget() {
let plan = vec![PlannedRegion {
name: "data-staging",
bytes: 4097,
backed_bytes: 0,
}];
assert_eq!(
Budget::costs(plan.iter().map(|region| region.bytes)).unwrap(),
Budget::costs(plan.iter().map(|region| (region.bytes, region.backed_bytes))).unwrap(),
(4097, 9)
);
let budget = Budget {
Expand All @@ -79,3 +89,99 @@ fn remote_staging_and_shared_memory_use_the_same_budget() {
.contains("no memory observation")
);
}

#[test]
fn preallocated_shm_skips_host_double_count_but_keeps_device_charge() {
let arena = 32u64 << 30;
let staging = 8u64 << 30;
let plan = vec![
PlannedRegion {
name: "arena",
bytes: arena,
backed_bytes: arena,
},
PlannedRegion {
name: "staging",
bytes: staging,
backed_bytes: staging,
},
];
let (host, device) = Budget::costs(
plan.iter()
.map(|region| (region.bytes, region.backed_bytes)),
)
.unwrap();
assert_eq!(host, 0);
assert_eq!(device, (arena + staging) / 512);
// Remaining host budget below 40 GiB approves because tmpfs blocks are already
// deducted from MemAvailable, while GPU registration metadata is still charged.
let budget = Budget {
host: Ok(25u64 << 30),
devices: vec![(device, false), (device, true)],
};
assert!(budget.approve(&plan).is_ok());
assert_eq!(budget.charges(host, device), vec![device, device]);
assert!(
Budget {
host: Ok(25u64 << 30),
devices: vec![(device - 1, false)],
}
.approve(&plan)
.unwrap_err()
.contains("GPU 0")
);
assert!(
Budget {
host: Err("no memory observation".into()),
devices: vec![(device, false)],
}
.approve(&plan)
.unwrap_err()
.contains("no memory observation")
);
}

#[test]
fn partially_backed_shm_charges_only_unbacked_remainder() {
let plan = vec![
PlannedRegion {
name: "arena",
bytes: 16 << 20,
backed_bytes: 12 << 20,
},
PlannedRegion {
name: "staging",
bytes: 4 << 20,
backed_bytes: 8 << 20, // clamped to region.bytes
},
PlannedRegion {
name: "data-staging",
bytes: 2 << 20,
backed_bytes: 0,
},
];
let (host, device) = Budget::costs(
plan.iter()
.map(|region| (region.bytes, region.backed_bytes)),
)
.unwrap();
assert_eq!(host, 6 << 20);
assert_eq!(device, (22 << 20) / 512);
assert!(
Budget {
host: Ok(6 << 20),
devices: vec![(device, false)],
}
.approve(&plan)
.is_ok()
);
assert!(
Budget {
host: Ok((6 << 20) - 1),
devices: vec![(device, false)],
}
.approve(&plan)
.unwrap_err()
.contains("host budget")
);
}
2 changes: 1 addition & 1 deletion selene/src/pool/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl PreparedPool {
Ok(Budget::costs(
self.registered_regions()
.iter()
.map(|region| region.bytes as u64),
.map(|region| (region.bytes as u64, region.backed_bytes)),
)?)
}
pub fn summary(&self) -> Result<String> {
Expand Down
Loading