Skip to content

Commit 6348636

Browse files
Avoid reading procfs to detect the Linux OS type (#20987)
Interpreter cache-key construction reads `/proc/sys/kernel/ostype` for every Python lookup, which becomes unexpectedly expensive when procfs is backed by FUSE. On an affected devbox, each read takes approximately 27 ms, compared with approximately 3 µs for `uname`; commands that discover interpreters twice avoid roughly 54 ms of overhead. Use `uname` to obtain the same Linux OS type directly while preserving existing interpreter-cache keys. Co-authored-by: Zanie Blue <[email protected]>
1 parent fbb0a82 commit 6348636

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎crates/uv-platform/src/host.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::str::FromStr;
77
/// The operating system type.
88
#[derive(Debug, Clone, PartialEq, Eq)]
99
pub enum OsType {
10-
/// Linux, with the kernel type from `/proc/sys/kernel/ostype` (typically `"Linux"`).
10+
/// Linux, with the kernel type from `uname` (typically `"Linux"`).
1111
Linux(String),
1212
/// macOS / Darwin.
1313
Darwin,
@@ -22,9 +22,9 @@ impl OsType {
2222
pub fn from_env() -> Option<Self> {
2323
cfg_select! {
2424
target_os = "linux" => {
25-
fs_err::read_to_string("/proc/sys/kernel/ostype")
26-
.ok()
27-
.map(|s| Self::Linux(s.trim().to_string()))
25+
let uname = rustix::system::uname();
26+
let os_type = uname.sysname().to_str().ok()?;
27+
Some(Self::Linux(os_type.to_string()))
2828
},
2929
target_os = "macos" => Some(Self::Darwin),
3030
target_os = "windows" => Some(Self::Windows),

0 commit comments

Comments
 (0)