From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 9503E1FF138 for ; Wed, 18 Mar 2026 15:07:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0CC4B253A; Wed, 18 Mar 2026 15:08:13 +0100 (CET) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 18 Mar 2026 15:08:07 +0100 Message-Id: Subject: Re: [PATCH proxmox 11/26] procfs: add helpers for querying pressure stall information From: "Lukas Wagner" To: "Arthur Bied-Charreton" , "Lukas Wagner" X-Mailer: aerc 0.21.0-0-g5549850facc2-dirty References: <20260312135229.420729-1-l.wagner@proxmox.com> <20260312135229.420729-12-l.wagner@proxmox.com> In-Reply-To: X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1773842845253 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.017 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.408 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.819 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.903 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: TBKIUEVAR74LLB6HWOMRZIU3COHF4IWL X-Message-ID-Hash: TBKIUEVAR74LLB6HWOMRZIU3COHF4IWL X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pdm-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hey Arthur, thanks for the review! On Mon Mar 16, 2026 at 2:25 PM CET, Arthur Bied-Charreton wrote: > On Thu, Mar 12, 2026 at 02:52:12PM +0100, Lukas Wagner wrote: >> This is put into a new crate, proxmox-procfs, since proxmox-sys is >> already quite large and should be split in the future. The general idea >> is that the contents of proxmox_sys::linux::procfs should be moved into >> this new crate (potentially after some API cleanup) at some point. >>=20 >> Signed-off-by: Lukas Wagner > I really like how you designed this, it reads very nicely!=20 > > 2 comments inline=20 >> --- >> Cargo.toml | 2 + >> proxmox-procfs/Cargo.toml | 18 ++ >> proxmox-procfs/debian/changelog | 5 + >> proxmox-procfs/debian/control | 50 +++++ >> proxmox-procfs/debian/copyright | 18 ++ >> proxmox-procfs/debian/debcargo.toml | 7 + >> proxmox-procfs/src/lib.rs | 1 + >> proxmox-procfs/src/pressure.rs | 334 ++++++++++++++++++++++++++++ >> 8 files changed, 435 insertions(+) >> create mode 100644 proxmox-procfs/Cargo.toml >> create mode 100644 proxmox-procfs/debian/changelog >> create mode 100644 proxmox-procfs/debian/control >> create mode 100644 proxmox-procfs/debian/copyright >> create mode 100644 proxmox-procfs/debian/debcargo.toml >> create mode 100644 proxmox-procfs/src/lib.rs >> create mode 100644 proxmox-procfs/src/pressure.rs >> + > [...] >> + fn read_pressure_line( >> + reader: &mut R, >> + buf: &mut Vec, >> + ) -> Result<(PressureRecordKind, PressureRecord), Error> { >> + // The buffer should be empty. It is only passed by the caller = as a performance >> + // optimization >> + debug_assert!(buf.is_empty()); >> + >> + reader.read_until(b'\n', buf)?; >> + // SAFETY: In production, `reader` is expected to read from >> + // procfs/sysfs pressure files, which only ever should return A= SCII strings. >> + let line =3D unsafe { std::str::from_utf8_unchecked(buf) }; > Major nit, but I wonder if using unsafe here is justified, given that thi= s=20 > assumption is not enforced at the type level (BufRead could return anythi= ng), > and this is not really a hot code path I saw the same unsafe block elsewhere in `proxmox-sys` which inspired me to do the same - but it's probably worth to benchmark this and check if it actually gives us a real-world performance benefit that is worth the hassle. As you said, will never be a particularly hot code path, in PDM (and soon PBS context) this will be called once every 10 seconds. >> + >> + Self::read_record(line) >> + } >> + >> + > [...] >> +#[cfg(test)] >> +mod test { >> + use super::*; >> + >> + #[test] >> + fn test_read_psi() { >> + let s =3D "some avg10=3D1.42 avg60=3D2.09 avg300=3D1.42 total= =3D40979658 >> +full avg10=3D0.08 avg60=3D0.18 avg300=3D0.13 total=3D22865313 >> +"; >> + >> + let mut reader =3D std::io::Cursor::new(s); >> + let stats =3D PressureData::read(&mut reader).unwrap(); >> + >> + assert_eq!(stats.some.total, 40979658); >> + assert!((stats.some.average_10 - 1.82).abs() < f64::EPSILON); > This test is failing, looks like this was supposed to be 1.42 Argh, this was a last-minute clippy fix before I sent the series (I forgot the .abs() initially), apparently I failed to run the tests again after that. Thanks! I will of course fix this for v2. >> + assert!((stats.some.average_60 - 2.09).abs() < f64::EPSILON); >> + assert!((stats.some.average_300 - 1.42).abs() < f64::EPSILON); >> + > [...]