Skip to content

Commit faaf232

Browse files
Auto merge of #142319 - the8472:ci-disable-write-flush, r=<try>
[experiment] Try speeding up windows CI a bit This should be equivalent to ticking the "turn off windows write cache buffer flushing" box This might squeeze out a few percent, but let's see if this even gets above the noise threshold. The last two `auto - x86_64-msvc-1` builds took 2h 29m, so that seems pretty stable. r? ghost try-job: x86_64-msvc-1
2 parents 8ce2287 + f8640e4 commit faaf232

File tree

5 files changed

+201
-0
lines changed

5 files changed

+201
-0
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ jobs:
122122
with:
123123
fetch-depth: 2
124124

125+
- name: disable write cache
126+
if: runner.os == 'Windows'
127+
run: |
128+
cd src/ci/winfs-yolo
129+
CARGO_INCREMENTAL=0 cargo run
130+
131+
125132
# Free up disk space on Linux by removing preinstalled components that
126133
# we do not need. We do this to enable some of the less resource
127134
# intensive jobs to run on free runners, which however also have

src/ci/winfs-yolo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

src/ci/winfs-yolo/Cargo.lock

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 4
4+
5+
[[package]]
6+
name = "windows-sys"
7+
version = "0.48.0"
8+
source = "registry+https://github.com/rust-lang/crates.io-index"
9+
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
10+
dependencies = [
11+
"windows-targets",
12+
]
13+
14+
[[package]]
15+
name = "windows-targets"
16+
version = "0.48.5"
17+
source = "registry+https://github.com/rust-lang/crates.io-index"
18+
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
19+
dependencies = [
20+
"windows_aarch64_gnullvm",
21+
"windows_aarch64_msvc",
22+
"windows_i686_gnu",
23+
"windows_i686_msvc",
24+
"windows_x86_64_gnu",
25+
"windows_x86_64_gnullvm",
26+
"windows_x86_64_msvc",
27+
]
28+
29+
[[package]]
30+
name = "windows_aarch64_gnullvm"
31+
version = "0.48.5"
32+
source = "registry+https://github.com/rust-lang/crates.io-index"
33+
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
34+
35+
[[package]]
36+
name = "windows_aarch64_msvc"
37+
version = "0.48.5"
38+
source = "registry+https://github.com/rust-lang/crates.io-index"
39+
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
40+
41+
[[package]]
42+
name = "windows_i686_gnu"
43+
version = "0.48.5"
44+
source = "registry+https://github.com/rust-lang/crates.io-index"
45+
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
46+
47+
[[package]]
48+
name = "windows_i686_msvc"
49+
version = "0.48.5"
50+
source = "registry+https://github.com/rust-lang/crates.io-index"
51+
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
52+
53+
[[package]]
54+
name = "windows_x86_64_gnu"
55+
version = "0.48.5"
56+
source = "registry+https://github.com/rust-lang/crates.io-index"
57+
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
58+
59+
[[package]]
60+
name = "windows_x86_64_gnullvm"
61+
version = "0.48.5"
62+
source = "registry+https://github.com/rust-lang/crates.io-index"
63+
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
64+
65+
[[package]]
66+
name = "windows_x86_64_msvc"
67+
version = "0.48.5"
68+
source = "registry+https://github.com/rust-lang/crates.io-index"
69+
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
70+
71+
[[package]]
72+
name = "winfs-yolo"
73+
version = "0.1.0"
74+
dependencies = [
75+
"windows-sys",
76+
]

src/ci/winfs-yolo/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "winfs-yolo"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
windows-sys = { version = "0.48.0", features = ["Win32_System_IO", "Win32_Storage_FileSystem", "Win32_Security", "Win32_Foundation"]}
8+
9+
[workspace]

src/ci/winfs-yolo/src/main.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//! Disable write cache flushing (i.e. write-durability guarantees) on Windows.
2+
//! Only run this on ephemeral machines, otherwise it may cause data loss.
3+
use std::ffi::CString;
4+
use std::ptr::{null, null_mut};
5+
use std::{mem, ptr};
6+
7+
use windows_sys::Win32::Foundation::{GENERIC_READ, GENERIC_WRITE, INVALID_HANDLE_VALUE};
8+
use windows_sys::Win32::Storage::FileSystem::{
9+
CreateFileA, FILE_SHARE_READ, FILE_SHARE_WRITE, OPEN_EXISTING,
10+
};
11+
use windows_sys::Win32::System::IO::DeviceIoControl;
12+
13+
const IOCTL_DISK_GET_CACHE_SETTINGS: u32 = 0x740e0;
14+
const IOCTL_DISK_SET_CACHE_SETTINGS: u32 = 0x7c0e4;
15+
16+
#[repr(C)]
17+
struct DiskCacheSettings {
18+
pub version: u32,
19+
pub state: u32,
20+
pub is_power_protected: u8,
21+
}
22+
23+
fn main() {
24+
// 3 drives ought to be enough for everyone
25+
for i in 0..=2 {
26+
unsafe {
27+
let disk = format!(r#"\\.\PHYSICALDRIVE{}"#, i);
28+
let hd1 = CString::new(disk.clone()).unwrap();
29+
let handle = CreateFileA(
30+
hd1.as_ptr().cast(),
31+
GENERIC_READ | GENERIC_WRITE,
32+
FILE_SHARE_READ | FILE_SHARE_WRITE,
33+
null(),
34+
OPEN_EXISTING,
35+
0,
36+
0,
37+
);
38+
39+
if handle == INVALID_HANDLE_VALUE {
40+
let error_code = windows_sys::Win32::Foundation::GetLastError();
41+
eprintln!("Failed to open device {disk}, {:x}", error_code);
42+
continue;
43+
}
44+
45+
let mut settings: DiskCacheSettings = mem::zeroed();
46+
let mut lpbytesreturned: u32 = 0;
47+
48+
let r = DeviceIoControl(
49+
handle,
50+
IOCTL_DISK_GET_CACHE_SETTINGS,
51+
null(),
52+
0,
53+
ptr::from_mut(&mut settings).cast(),
54+
size_of::<DiskCacheSettings>() as u32,
55+
&mut lpbytesreturned,
56+
null_mut(),
57+
);
58+
if r == 0 {
59+
eprintln!("Failed to get cache settings");
60+
continue;
61+
}
62+
63+
// Enable YOLO mode
64+
settings.is_power_protected = 1;
65+
66+
let r = DeviceIoControl(
67+
handle,
68+
IOCTL_DISK_SET_CACHE_SETTINGS,
69+
ptr::from_ref(&settings).cast(),
70+
size_of::<DiskCacheSettings>() as u32,
71+
null_mut(),
72+
0,
73+
&mut lpbytesreturned,
74+
null_mut(),
75+
);
76+
if r == 0 {
77+
eprintln!("Failed to set cache settings");
78+
continue;
79+
}
80+
81+
// verify that it sticks
82+
83+
let r = DeviceIoControl(
84+
handle,
85+
IOCTL_DISK_GET_CACHE_SETTINGS,
86+
null(),
87+
0,
88+
ptr::from_mut(&mut settings).cast(),
89+
size_of::<DiskCacheSettings>() as u32,
90+
&mut lpbytesreturned,
91+
null_mut(),
92+
);
93+
94+
if r == 0 {
95+
eprintln!("Failed to get cache settings the second time");
96+
continue;
97+
}
98+
99+
if settings.is_power_protected != 1 {
100+
eprintln!(
101+
"Failed to enable YOLO mode for drive {i}, is_power_protected was not retained"
102+
);
103+
} else {
104+
eprintln!("YOLO mode enabled successfully for drive {i}!");
105+
}
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)