Skip to content

Commit 534537c

Browse files
original-el8R4yHarrisclaude
authored
Bound Windows integrated-GPU cache sizing by available commit (#175)
* eos: accept volumes whose performance sector hint exceeds the logical sector The direct-I/O check rejected this NVMe with "direct I/O sector size 32768 does not divide 4096" because it read PhysicalBytesPerSectorForPerformance, which is a hint, not a constraint. The check now covers LogicalBytesPerSector and PhysicalBytesPerSectorForAtomicity. Validation: eos tests report 5 passed; 4096-byte unbuffered reads were measured completing on this device, and package serving reads through the same path. Limitations: measured on one NVMe; volumes that genuinely cannot support 4096-byte unbuffered reads still fail the check. Design-Signed-Off-By: Hermes Agent (deepseek-v4.1-flash); design-review=1c01 Signed-off-by: R4yharris <harray86@me.com> Signed-off-by: Jason Cook <1637905+original-el8@users.noreply.github.com> * runtime_package: read the primary container for an empty relative name A payload entry whose relative name is empty denotes the primary container, but asset_path joined the empty name onto the entry directory and returned the directory itself. Loading a package then failed reading the tokenizer. asset_path now returns the container path when the relative name is empty and joins otherwise. Validation: a published package loads and serves; chat completions return with finish_reason stop. runtime_package tests report 108 passed. Limitations: the remaining failure in that module is authenticated_handles_survive_rename_and_replacement, which conflicts with the immutability guard in eos::windows::direct_read_guard (FILE_SHARE_READ only) and needs a maintainer decision, not a patch here. Design-Signed-Off-By: Hermes Agent (deepseek-v4.1-flash); design-review=1c01 Signed-off-by: R4yharris <harray86@me.com> Signed-off-by: Jason Cook <1637905+original-el8@users.noreply.github.com> * naming: recognise the RTX Spark N1X PCI device id platform_from_pci only knew 0x2e12 (DGX Spark) as a GB10 device, so NVML naming refused the export on an RTX Spark N1X with "NVML reports unsupported GPU PCI id 0x2e03". Both ids are the same SM121 platform, so GB10_DEVICES now carries both and the PCI test iterates the table. Validation: cargo test package::naming reports 6 passed on x86_64-pc-windows-msvc and on the native aarch64 host. A full-capacity export named and published its package on this device. Limitations: no other GB10 ids were available to test; the table is the only place device identity is decided. Design-Signed-Off-By: Hermes Agent (deepseek-v4.1-flash); design-review=1c01 Signed-off-by: R4yharris <harray86@me.com> Signed-off-by: Jason Cook <1637905+original-el8@users.noreply.github.com> * Bound Windows integrated-GPU cache sizing by available commit On an RTX Spark under WDDM, every CUDA allocation, including the dedicated carveout, is charged against the system commit limit: CPU-visible RAM plus the page files. Cache sizing read only CUDA's free memory, so the memory reserve did not protect commit. On an RTX Spark N1X with 30.4 GiB of RAM and a system-managed page file whose maximum is 92 GiB, serving qwen38-spark-tp1-mtp5 with `[memory] reserve = "8G"` committed 101.7 GiB and left 0.9 GiB of the 122.4 GiB maximum commit limit; other processes then failed to create threads. Integrated-GPU memory observations on Windows are now also bounded by the commit this process can obtain: GlobalMemoryStatusEx's available commit plus each page file's remaining growth to its maximum size, read through NtQuerySystemInformation(SystemPageFileInformationEx). The growth term is required because Windows grows a system-managed page file on demand; before loading, the current limit on the same host was 76.4 GiB, too small for the package's 75.9 GiB of fixed device storage plus other processes' commit. Cache budgets subtract the reserve, driver margin, and host headroom from the bounded value as before, so the reserve remains available to other processes as commit. docs/windows.md describes the limit. Compatibility: Linux and discrete GPUs are unchanged. On Windows integrated GPUs, KV capacity shrinks when RAM plus the maximum page-file size cannot hold the server's footprint, the reserve, and other processes' commit; a larger page-file maximum or a smaller reserve restores it. Package formats and execution contracts are unchanged. Validation on an RTX Spark N1X, Windows 11 ARM64, aarch64-pc-windows-msvc, serving qwen38-spark-tp1-mtp5 with an 8 GiB reserve, --embedding-table-resident-scales, and --embedding-table-cache-size 2G: - Without this commit (b21878b with the RTX Spark serving fixes): 0.9 GiB of commit available at the maximum limit, 101.7 GiB server commit, 16,576 KV pages of 64 tokens. - With this commit: 15.5 GiB available at the maximum limit, 91.2 GiB server commit, 4,160 KV pages (266,240 tokens), 11.3 GiB of the carveout free. A chat completion finished with stop, and Ctrl-C shut the server down cleanly. - helios runtime_package::memory tests 13 passed, including page-file entry parsing; runtime_package::protection 14 and package::naming 6 passed; eos tests 5 passed. Limitations: measured on one RTX Spark N1X with one system-managed page file. SystemPageFileInformationEx is an ntdll information class that the Windows SDK does not document. Discrete GPUs under WDDM were not measured. Ignition's Windows preparation budgets still read available physical RAM. Linux was not rebuilt; the change compiles only on Windows. Design-Signed-Off-By: Claude Code (Claude Opus 5.5); design-review=1c01 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jason Cook <1637905+original-el8@users.noreply.github.com> --------- Signed-off-by: R4yharris <harray86@me.com> Signed-off-by: Jason Cook <1637905+original-el8@users.noreply.github.com> Co-authored-by: R4yharris <harray86@me.com> Co-authored-by: Jason Cook <1637905+original-el8@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b69e307 commit 534537c

4 files changed

Lines changed: 131 additions & 8 deletions

File tree

‎docs/windows.md‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,20 @@ weight loading. Successful single-request generation does not cover these cases.
118118

119119
On RTX Spark, CUDA's free and total memory include the dedicated GPU carveout
120120
and shared system memory. Windows reports only CPU-visible RAM through its
121-
physical-memory API; NVML reports only the dedicated carveout. GPU planning and
122-
cache sizing use CUDA's combined budget. Compiler and tuning worker budgets are
123-
also bounded by available CPU-visible RAM. The configured reserve, driver margin,
124-
and integrated-GPU host headroom are subtracted before allocating caches.
125-
Page-file capacity is not GPU memory.
121+
physical-memory API; NVML reports only the dedicated carveout. GPU planning uses
122+
CUDA's combined budget. Compiler and tuning worker budgets are also bounded by
123+
available CPU-visible RAM.
124+
125+
WDDM charges every CUDA allocation, including the dedicated carveout, against the
126+
system commit limit: CPU-visible RAM plus the page files. Windows grows a
127+
system-managed page file on demand up to a maximum it chooses, about three times
128+
RAM. Serving sizes caches from the smaller of CUDA's free memory and the commit the
129+
process can obtain once every page file reaches its maximum size, then subtracts the
130+
configured reserve, driver margin, and integrated-GPU host headroom, so the reserve
131+
remains available to other processes as commit. Page-file capacity is not GPU
132+
memory, but it bounds GPU allocations: when RAM plus the maximum page-file size is
133+
smaller than the server's footprint plus other processes' commit, KV capacity
134+
shrinks to fit. A custom page-file maximum raises that limit without consuming RAM.
126135

127136
The runtime preserves the package's recorded virtual addresses. Linux registers
128137
host pages for mapped graph storage. Windows uses host-backed CUDA VMM with CPU

‎helios/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ test = false
135135
bench = false
136136

137137
[target.'cfg(windows)'.dependencies]
138-
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Memory", "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_System_Console", "Win32_System_LibraryLoader", "Win32_System_Com", "Win32_UI_Shell", "Win32_Security", "Win32_Security_Authorization"] }
138+
windows-sys = { version = "0.61", features = ["Wdk_System_SystemInformation", "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Memory", "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_System_Console", "Win32_System_LibraryLoader", "Win32_System_Com", "Win32_UI_Shell", "Win32_Security", "Win32_Security_Authorization"] }
139139

140140
[target.'cfg(target_os = "linux")'.dependencies]
141141
io-uring = "0.7"

‎helios/src/runtime_package/device_memory.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ impl NativeResources {
123123
"cuDeviceGetPCIBusId",
124124
(driver.device_pci_bus_id)(pci.as_mut_ptr(), pci.len() as c_int, device),
125125
)?;
126+
// Both remain bounded by the commit this process can obtain.
126127
status
127128
.ullAvailPhys
128129
.saturating_add(discrete_free(&pci)?)
129130
.min(total as u64)
131+
.min(super::memory::commit_available()?)
130132
}
131133
};
132134
Ok(MemorySnapshot {

‎helios/src/runtime_package/memory.rs‎

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,87 @@ pub(super) fn shared_available(meminfo: &str, total: usize) -> Result<usize> {
3232
Ok(flare_selene::offload::available_memory(meminfo, total)?)
3333
}
3434

35+
/// Memory this process can commit once every page file reaches its maximum size.
36+
///
37+
/// WDDM charges CUDA allocations on an integrated GPU, including the dedicated carveout,
38+
/// against the system commit limit: CPU-visible RAM plus the page files. Windows grows a
39+
/// system-managed page file on demand, so the current limit understates what serving can
40+
/// commit; each page file's growth to its maximum size is added to the available commit.
41+
#[cfg(windows)]
42+
pub(super) fn commit_available() -> Result<u64> {
43+
use windows_sys::{
44+
Wdk::System::SystemInformation::{NtQuerySystemInformation, SYSTEM_INFORMATION_CLASS},
45+
Win32::System::SystemInformation::{
46+
GetSystemInfo, GlobalMemoryStatusEx, MEMORYSTATUSEX, SYSTEM_INFO,
47+
},
48+
};
49+
const SYSTEM_PAGE_FILE_INFORMATION_EX: SYSTEM_INFORMATION_CLASS = 144;
50+
// SAFETY: each structure is zero-initialized with any required length before its call.
51+
unsafe {
52+
let mut status: MEMORYSTATUSEX = std::mem::zeroed();
53+
status.dwLength = std::mem::size_of::<MEMORYSTATUSEX>() as u32;
54+
if GlobalMemoryStatusEx(&mut status) == 0 {
55+
return Err(std::io::Error::last_os_error().to_string().into());
56+
}
57+
let mut system: SYSTEM_INFO = std::mem::zeroed();
58+
GetSystemInfo(&mut system);
59+
// Windows supports at most 16 page files; their entries and names fit in 16 KiB.
60+
let mut entries = vec![0u64; 2048];
61+
let mut returned = 0u32;
62+
let code = NtQuerySystemInformation(
63+
SYSTEM_PAGE_FILE_INFORMATION_EX,
64+
entries.as_mut_ptr().cast(),
65+
(entries.len() * size_of::<u64>()) as u32,
66+
&mut returned,
67+
);
68+
if code < 0 {
69+
return Err(format!(
70+
"NtQuerySystemInformation(SystemPageFileInformationEx) failed with NTSTATUS {:#010x}",
71+
code as u32
72+
)
73+
.into());
74+
}
75+
let returned = std::slice::from_raw_parts(
76+
entries.as_ptr().cast::<u8>(),
77+
(returned as usize).min(entries.len() * size_of::<u64>()),
78+
);
79+
Ok(status
80+
.ullAvailPageFile
81+
.saturating_add(page_file_growth(returned, u64::from(system.dwPageSize))))
82+
}
83+
}
84+
85+
/// ntdll's SYSTEM_PAGEFILE_INFORMATION_EX, which reports sizes in pages.
86+
#[cfg(windows)]
87+
#[repr(C)]
88+
struct PageFile {
89+
next_entry_offset: u32,
90+
total_size: u32,
91+
total_in_use: u32,
92+
peak_usage: u32,
93+
name: windows_sys::Win32::Foundation::UNICODE_STRING,
94+
minimum_size: u32,
95+
maximum_size: u32,
96+
}
97+
98+
/// Bytes the page files in `entries` can still grow before reaching their maximum sizes.
99+
#[cfg(windows)]
100+
fn page_file_growth(entries: &[u8], page_bytes: u64) -> u64 {
101+
let (mut growth, mut offset) = (0u64, 0usize);
102+
while offset.saturating_add(size_of::<PageFile>()) <= entries.len() {
103+
// SAFETY: the entry lies within `entries`; unaligned reads accept any offset.
104+
let entry = unsafe { entries.as_ptr().add(offset).cast::<PageFile>().read_unaligned() };
105+
growth = growth.saturating_add(
106+
u64::from(entry.maximum_size.saturating_sub(entry.total_size)) * page_bytes,
107+
);
108+
if entry.next_entry_offset == 0 {
109+
break;
110+
}
111+
offset = offset.saturating_add(entry.next_entry_offset as usize);
112+
}
113+
growth
114+
}
115+
35116
impl NativeResources {
36117
/// Memory the driver reports in total for the rank's device: on an integrated GPU, the
37118
/// system's memory.
@@ -67,8 +148,9 @@ impl NativeResources {
67148
} else {
68149
#[cfg(windows)]
69150
{
70-
// CUDA includes both the dedicated carveout and shared system memory.
71-
Ok(free.min(total))
151+
// CUDA includes both the dedicated carveout and shared system memory, and
152+
// WDDM charges allocations from either against the system commit limit.
153+
Ok(free.min(total).min(commit_available()? as usize))
72154
}
73155
#[cfg(unix)]
74156
{
@@ -997,6 +1079,36 @@ mod tests {
9971079
}
9981080
}
9991081

1082+
#[cfg(windows)]
1083+
#[test]
1084+
fn windows_commit_adds_each_page_file_growth() {
1085+
let entry = |next, total, maximum| PageFile {
1086+
next_entry_offset: next,
1087+
total_size: total,
1088+
total_in_use: 0,
1089+
peak_usage: 0,
1090+
name: unsafe { std::mem::zeroed() },
1091+
minimum_size: 0,
1092+
maximum_size: maximum,
1093+
};
1094+
// Names follow each entry, so the second entry starts beyond the first one's size.
1095+
let mut entries = vec![0u8; 64 + size_of::<PageFile>()];
1096+
unsafe {
1097+
entries.as_mut_ptr().cast::<PageFile>().write_unaligned(entry(64, 100, 300));
1098+
entries.as_mut_ptr().add(64).cast::<PageFile>().write_unaligned(entry(0, 50, 80));
1099+
}
1100+
assert_eq!(page_file_growth(&entries, 4096), (200 + 30) * 4096);
1101+
// A page file larger than its maximum contributes no growth, and the walk stops
1102+
// at the returned length.
1103+
unsafe {
1104+
entries.as_mut_ptr().add(64).cast::<PageFile>().write_unaligned(entry(0, 90, 80));
1105+
}
1106+
assert_eq!(page_file_growth(&entries, 4096), 200 * 4096);
1107+
assert_eq!(page_file_growth(&entries[..64], 4096), 200 * 4096);
1108+
assert_eq!(page_file_growth(&[], 4096), 0);
1109+
assert!(commit_available().unwrap() > 0);
1110+
}
1111+
10001112
#[test]
10011113
fn serving_headroom_preserves_the_user_reserve() {
10021114
assert_eq!(headroom(&serde_json::json!({})).unwrap(), 64 << 20);

0 commit comments

Comments
 (0)