From 8d9d5343b2fb05437ce4c985d5e76e3db2ac59ec Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Fri, 23 Aug 2024 10:22:38 -0400 Subject: [PATCH] Update to latest dependencies: std LazyLock; Clap * Replace lazy_static with LazyLock * Replace argh with clap --- Cargo.lock | 376 +++++++++++++++++++++++++++++----------- Cargo.toml | 24 ++- Makefile | 13 +- src/anyos_hugepages.rs | 7 +- src/bin/faultlatency.rs | 45 +++-- src/linux_hugepages.rs | 3 +- src/main.rs | 51 +++--- src/mmaputils.rs | 28 +-- 8 files changed, 367 insertions(+), 180 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ac9de8..f5bbc6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,52 +4,73 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] -name = "argh" -version = "0.1.10" +name = "anstream" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab257697eb9496bf75526f0217b5ed64636a9cfafa78b8365c71bd283fcef93e" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ - "argh_derive", - "argh_shared", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", ] [[package]] -name = "argh_derive" -version = "0.1.10" +name = "anstyle" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b382dbd3288e053331f03399e1db106c9fb0d8562ad62cb04859ae926f324fa6" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ - "argh_shared", - "proc-macro2", - "quote", - "syn", + "utf8parse", ] [[package]] -name = "argh_shared" -version = "0.1.10" +name = "anstyle-query" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64cb94155d965e3d37ffbbe7cc5b82c3dd79dd33bd48e536f73d2cfb8d85506f" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys", +] [[package]] -name = "autocfg" -version = "1.1.0" +name = "anstyle-wincon" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys", +] [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cfg-if" @@ -57,11 +78,72 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "clap" +version = "4.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -76,22 +158,20 @@ checksum = "558b88954871f5e5b2af0e62e2e176c8bde7a6c2c4ed41b13d138d96da2e2cbd" [[package]] name = "heck" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hugepagedemo" version = "0.1.0" dependencies = [ - "argh", + "clap", "go-parse-duration", "humanunits", - "lazy_static", "memory-stats", "nix", "rand", - "rand_xoshiro", "regex", "strum", "time", @@ -103,82 +183,80 @@ version = "0.1.0" source = "git+https://github.com/evanj/humanunits#c2257ffcc2ab9e7a6820d722a1d6f6d8e3ff2b7b" [[package]] -name = "lazy_static" -version = "1.4.0" +name = "is_terminal_polyfill" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "memoffset" -version = "0.7.1" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memory-stats" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34f79cf9964c5c9545493acda1263f1912f8d2c56c8a2ffee2606cb960acaacc" +checksum = "c73f5c649995a115e1a0220b35e4df0a1294500477f97a91d0660fb5abeb574a" dependencies = [ "libc", - "winapi", + "windows-sys", ] [[package]] name = "nix" -version = "0.26.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a58d1d356c6597d08cde02c2f09d785b09e28711837b1ed667dc652c08a694" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ "bitflags", "cfg-if", + "cfg_aliases", "libc", - "memoffset", - "pin-utils", - "static_assertions", ] [[package]] -name = "pin-utils" +name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -214,19 +292,22 @@ dependencies = [ ] [[package]] -name = "rand_xoshiro" -version = "0.6.0" +name = "regex" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ - "rand_core", + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", ] [[package]] -name = "regex" -version = "1.7.1" +name = "regex-automata" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -235,42 +316,56 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rustversion" -version = "1.0.11" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "serde" -version = "1.0.152" +version = "1.0.208" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "static_assertions" -version = "1.1.0" +name = "strsim" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" -version = "0.24.1" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.24.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ "heck", "proc-macro2", @@ -281,9 +376,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.107" +version = "2.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" dependencies = [ "proc-macro2", "quote", @@ -292,25 +387,34 @@ dependencies = [ [[package]] name = "time" -version = "0.3.17" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ + "deranged", + "num-conv", + "powerfmt", "serde", "time-core", ] [[package]] name = "time-core" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "wasi" @@ -319,23 +423,95 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows_i686_gnu" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index ae74539..46e639c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,20 @@ license = "MIT" repository = "https://github.com/evanj/hugepagedemo" keywords = ["page", "hugepage", "madvise", "thp", "tlb"] categories = ["command-line-utilities"] +publish = false + +[lints.clippy] +cargo = "deny" +nursery = "deny" +pedantic = "deny" +style = "deny" +cast_possible_truncation = { level = "allow", priority = 1 } +cast_precision_loss = { level = "allow", priority = 1 } +cast_sign_loss = { level = "allow", priority = 1 } +missing_errors_doc = { level = "allow", priority = 1 } +missing_panics_doc = { level = "allow", priority = 1 } +multiple-crate-versions = { level = "allow", priority = 1 } +too_many_lines = { level = "allow", priority = 1 } [profile.release-nativecpu] inherits = "release" @@ -18,14 +32,12 @@ debug = true #rustflags = ["-C", "target-cpu=native"] [dependencies] -argh = "0.1.9" +clap = { version="4", features = ["derive"] } go-parse-duration = "0" -humanunits = {git="https://github.com/evanj/humanunits"} -lazy_static = "1" +humanunits = { git="https://github.com/evanj/humanunits" } memory-stats = "1" -nix = {version="0", features=["mman"]} -rand = "0" -rand_xoshiro = "0" +nix = { version="0", features=["mman", "feature"] } +rand = { version="0", features = ["small_rng"] } regex = "1" strum = { version = "0", features = ["derive"] } time = { version="0", features=["std"]} diff --git a/Makefile b/Makefile index fca9f83..9a233f6 100644 --- a/Makefile +++ b/Makefile @@ -4,16 +4,9 @@ all: aligned_alloc_demo cargo fmt cargo test cargo check - # https://zhauniarovich.com/post/2021/2021-09-pedantic-clippy/#paranoid-clippy - # -D clippy::restriction is way too "safe"/careful - # -D clippy::pedantic too paranoid - # -A clippy::option-if-let-else: I stylistically disagree with this - cargo clippy --all-targets --all-features -- \ - -D warnings \ - -D clippy::nursery \ - -A clippy::option-if-let-else \ - -D clippy::cargo - + cargo clippy --all-targets --all-features -- -D warnings + cargo verify-project + cargo audit clang-format -i '-style={BasedOnStyle: Google, ColumnLimit: 100}' *.c run_native: diff --git a/src/anyos_hugepages.rs b/src/anyos_hugepages.rs index aff151c..3592417 100644 --- a/src/anyos_hugepages.rs +++ b/src/anyos_hugepages.rs @@ -1,4 +1,6 @@ use nix::unistd::SysconfVar; +#[cfg(any(test, target_os = "linux"))] +use std::sync::LazyLock; #[cfg(any(test, target_os = "linux"))] #[derive(PartialEq, Eq, Debug)] @@ -37,9 +39,8 @@ impl std::fmt::Display for HugepageSetting { #[cfg(any(test, target_os = "linux"))] pub fn parse_hugepage_enabled(input: &[u8]) -> Result { - lazy_static! { - static ref RE: regex::bytes::Regex = regex::bytes::Regex::new(r#"\[([^\]]+)\]"#).unwrap(); - } + static RE: LazyLock = + LazyLock::new(|| regex::bytes::Regex::new(r"\[([^\]]+)\]").unwrap()); let string_matches = RE.captures(input); if string_matches.is_none() { diff --git a/src/bin/faultlatency.rs b/src/bin/faultlatency.rs index a7c4baf..77fdf64 100644 --- a/src/bin/faultlatency.rs +++ b/src/bin/faultlatency.rs @@ -1,3 +1,4 @@ +use clap::Parser; use hugepagedemo::MmapRegion; use std::{ error::Error, @@ -5,30 +6,23 @@ use std::{ }; use time::OffsetDateTime; -#[derive(argh::FromArgs)] /// Control the options for fault latency testing. +#[derive(Debug, Parser)] +#[command(version, about, long_about = None)] struct FaultLatencyOptions { /// probe the page latency at this interval. - #[argh( - option, - default = "Duration::from_secs(1)", - from_str_fn(argh_parse_go_duration) - )] + #[arg(long, default_value = "1s", value_parser(clap_parse_go_duration))] test_interval: Duration, /// sleep duration between probing the different page sizes. // allow(dead_code) for Mac OS X where the option is unused - #[allow(dead_code)] - #[argh( - option, - default = "Duration::from_millis(100)", - from_str_fn(argh_parse_go_duration) - )] + //#[allow(dead_code)] + #[arg(long, default_value = "100ms", value_parser(clap_parse_go_duration))] sleep_between_page_sizes: Duration, } -/// Parses a duration using Go's formats, with the signature required by argh. -fn argh_parse_go_duration(s: &str) -> Result { +/// Parses a duration using Go's formats, with the signature required by clap. +fn clap_parse_go_duration(s: &str) -> Result { let result = go_parse_duration::parse_duration(s); match result { Err(err) => Err(format!("{err:?}")), @@ -80,8 +74,9 @@ fn fault_4kib() -> Result { )) } +#[allow(clippy::similar_names)] fn main() -> Result<(), Box> { - let config: FaultLatencyOptions = argh::from_env(); + let config = FaultLatencyOptions::parse(); let mut next = Instant::now() + config.test_interval; loop { @@ -119,6 +114,7 @@ fn main() -> Result<(), Box> { mod linux { use hugepagedemo::MmapRegion; use nix::sys::mman::MmapAdvise; + use std::ptr::NonNull; use std::{ffi::c_void, time::Instant}; use crate::FaultLatency; @@ -128,7 +124,7 @@ mod linux { /// Unfortunately, the Linux kernel seems to prefer returning struct MmapMadviseNoUnmap { _region: MmapRegion, - aligned_pointer: *mut c_void, + aligned_pointer: NonNull, } impl MmapMadviseNoUnmap { @@ -146,12 +142,13 @@ mod linux { // This allows consecutive calls to mmap to be contiguous, which MIGHT // allow the kernel to coalesce them into huge pages? Not sure. let allocation_end = region.get_mut() as usize + align_rounded_size; - let aligned_pointer = - align_pointer_value_down(ALIGNMENT_2MIB, allocation_end - size) as *mut c_void; + let aligned_pointer_usize = + align_pointer_value_down(ALIGNMENT_2MIB, allocation_end - size); - assert!(region.get_mut() <= aligned_pointer); - assert!(aligned_pointer as usize + size <= allocation_end); + assert!(region.ptr_as_usize() <= aligned_pointer_usize); + assert!(aligned_pointer_usize + size <= allocation_end); + let aligned_pointer = NonNull::new(aligned_pointer_usize as *mut c_void).unwrap(); unsafe { nix::sys::mman::madvise(aligned_pointer, size, MmapAdvise::MADV_HUGEPAGE) .expect("BUG: madvise must succeed"); @@ -163,8 +160,8 @@ mod linux { }) } - pub(crate) fn get_mut(&mut self) -> *mut c_void { - self.aligned_pointer + const fn as_ptr(&self) -> *mut c_void { + self.aligned_pointer.as_ptr() } } @@ -181,9 +178,9 @@ mod linux { const PAGE_2MIB: usize = 2 << 20; let start = Instant::now(); - let mut region = MmapMadviseNoUnmap::new(PAGE_2MIB)?; + let region = MmapMadviseNoUnmap::new(PAGE_2MIB)?; let mmap_end = Instant::now(); - let u64_pointer = region.get_mut().cast::(); + let u64_pointer = region.as_ptr().cast::(); unsafe { *u64_pointer = 0x42; } diff --git a/src/linux_hugepages.rs b/src/linux_hugepages.rs index 359678a..35cf950 100644 --- a/src/linux_hugepages.rs +++ b/src/linux_hugepages.rs @@ -6,6 +6,7 @@ use std::fs::File; use std::io::Read; use std::io::Seek; use std::io::SeekFrom; +use std::ptr::NonNull; // See: https://www.kernel.org/doc/Documentation/vm/transhuge.txt const HUGEPAGE_ENABLED_PATH: &str = "/sys/kernel/mm/transparent_hugepage/enabled"; @@ -24,7 +25,7 @@ pub fn print_hugepage_setting_on_linux() -> Result<(), Box> { pub fn madvise_hugepages_on_linux(slice: &mut [u64]) { const HUGEPAGE_FLAGS: MmapAdvise = MmapAdvise::MADV_HUGEPAGE; - let slice_pointer = slice.as_mut_ptr().cast::(); + let slice_pointer = NonNull::new(slice.as_mut_ptr().cast::()).unwrap(); let slice_byte_len = slice.len() * 8; unsafe { nix::sys::mman::madvise(slice_pointer, slice_byte_len, HUGEPAGE_FLAGS) diff --git a/src/main.rs b/src/main.rs index 0571268..fe3426c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use clap::Parser; use hugepagedemo::MmapOwner; use memory_stats::memory_stats; use nix::sys::mman::{MapFlags, ProtFlags}; @@ -6,14 +7,11 @@ use rand::{distributions::Uniform, RngCore, SeedableRng}; use std::error::Error; use std::num::NonZeroUsize; use std::os::raw::c_void; +use std::ptr::NonNull; use std::slice; use std::thread::sleep; use std::time::{Duration, Instant}; -#[cfg(any(test, target_os = "linux"))] -#[macro_use] -extern crate lazy_static; - mod anyos_hugepages; mod mmaputils; #[cfg(target_os = "linux")] @@ -39,19 +37,20 @@ use notlinux_hugepages::read_page_size; const FILLED: u64 = 0x42; -#[derive(argh::FromArgs)] +#[derive(Debug, Parser)] +#[command(version, about, long_about = None)] /// Control the options for the huge page demo. struct HugePageDemoOptions { /// disable using mmap with madvise. - #[argh(option, default = "RunMode::All")] + #[arg(long, default_value_t = RunMode::All)] run_mode: RunMode, /// sleep for 60 seconds before dropping the mmap, to allow examining the process state. - #[argh(switch)] + #[arg(long)] sleep_before_drop: bool, } -#[derive(strum::EnumString, Eq, PartialEq)] +#[derive(strum::Display, strum::EnumString, Eq, PartialEq, Debug, Clone)] enum RunMode { All, VecOnly, @@ -64,11 +63,11 @@ fn main() -> Result<(), Box> { const TEST_SIZE_BYTES: usize = TEST_SIZE_GIB * 1024 * 1024 * 1024; const TEST_SIZE_U64: usize = TEST_SIZE_BYTES / 8; - let options: HugePageDemoOptions = argh::from_env(); + let options = HugePageDemoOptions::parse(); - // the rand book suggests Xoshiro256Plus is fast and pretty good: + // the rand book suggests SmallRng is fast and pretty good: // https://rust-random.github.io/book/guide-rngs.html - let mut rng = rand_xoshiro::Xoshiro256Plus::from_entropy(); + let mut rng = rand::rngs::SmallRng::from_entropy(); let mem_before = memory_stats().unwrap(); if options.run_mode == RunMode::All || options.run_mode == RunMode::VecOnly { @@ -228,15 +227,13 @@ impl MmapHugeMadviseAligned { let align_rounded_size = NonZeroUsize::new(size + alignment).expect("BUG: alignment and size must be > 0"); - let mmap_pointer: *mut c_void; + let mmap_pointer: NonNull; unsafe { - mmap_pointer = nix::sys::mman::mmap( + mmap_pointer = nix::sys::mman::mmap_anonymous( None, align_rounded_size, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, MapFlags::MAP_ANONYMOUS | MapFlags::MAP_PRIVATE | flags, - 0, - 0, )?; } @@ -244,18 +241,18 @@ impl MmapHugeMadviseAligned { // since the kernel seems to allocate consecutive allocations downward. // This allows consecutive calls to mmap to be contiguous, which MIGHT // allow the kernel to coalesce them into huge pages? Not sure. - let allocation_end = mmap_pointer as usize + align_rounded_size.get(); - let aligned_pointer = - align_pointer_value_down(alignment, allocation_end - size) as *mut c_void; + let mmap_pointer_usize = mmap_pointer.as_ptr() as usize; + let allocation_end = mmap_pointer_usize + align_rounded_size.get(); + let aligned_pointer_usize = align_pointer_value_down(alignment, allocation_end - size); // alternative of taking the lowest aligned address // let aligned_pointer = // align_pointer_value_up(alignment, mmap_pointer as usize) as *mut c_void; - assert!(mmap_pointer <= aligned_pointer); - assert!(aligned_pointer as usize + size <= allocation_end); + assert!(mmap_pointer_usize <= aligned_pointer_usize); + assert!(aligned_pointer_usize + size <= allocation_end); - let unaligned_below_size = aligned_pointer as usize - mmap_pointer as usize; - let aligned_end = aligned_pointer as usize + size; + let unaligned_below_size = aligned_pointer_usize - mmap_pointer_usize; + let aligned_end = aligned_pointer_usize + size; let unaligned_above_size = allocation_end - aligned_end; // println!( // "mmap_pointer:0x{:x} - unaligned_below_end:0x{:x}; aligned_pointer:0x{:x} - aligned_end:0x{:x}; unaligned_above_end:0x{:x}", @@ -267,8 +264,8 @@ impl MmapHugeMadviseAligned { // ); // if there is an unused section BELOW the allocation: unmap it - if aligned_pointer != mmap_pointer { - let unaligned_size = aligned_pointer as usize - mmap_pointer as usize; + if aligned_pointer_usize != mmap_pointer_usize { + let unaligned_size = aligned_pointer_usize - mmap_pointer_usize; unsafe { nix::sys::mman::munmap(mmap_pointer, unaligned_size) .expect("BUG: munmap must succeed"); @@ -277,8 +274,9 @@ impl MmapHugeMadviseAligned { // if there is an unused section ABOVE the allocation: unmap it if unaligned_above_size != 0 { + let aligned_end_pointer = NonNull::new(aligned_end as *mut c_void).unwrap(); unsafe { - nix::sys::mman::munmap(aligned_end as *mut c_void, unaligned_above_size) + nix::sys::mman::munmap(aligned_end_pointer, unaligned_above_size) .expect("BUG: munmap must succeed"); } } @@ -288,6 +286,7 @@ impl MmapHugeMadviseAligned { align_rounded_size.get() ); + let aligned_pointer = NonNull::new(aligned_pointer_usize as *mut c_void).unwrap(); Ok(Self { region: MmapOwner::new(aligned_pointer, size), }) @@ -454,5 +453,7 @@ mod test { v.push(aligned_alloc); } + // explicitly drop v: makes clippy happy because v is now used + drop(v); } } diff --git a/src/mmaputils.rs b/src/mmaputils.rs index 6eeeef3..806f236 100644 --- a/src/mmaputils.rs +++ b/src/mmaputils.rs @@ -1,20 +1,21 @@ -use std::{ffi::c_void, num::NonZeroUsize}; - use nix::sys::mman::{MapFlags, ProtFlags}; +use std::{ffi::c_void, num::NonZeroUsize, ptr::NonNull}; /// Owns a memory region with mmap and calls munmap on drop. pub struct MmapOwner { - mmap_pointer: *mut c_void, + mmap_pointer: NonNull, size: usize, } impl MmapOwner { - pub const fn new(mmap_pointer: *mut c_void, size: usize) -> Self { + #[must_use] + pub const fn new(mmap_pointer: NonNull, size: usize) -> Self { Self { mmap_pointer, size } } + #[must_use] pub const fn get_mut(&self) -> *mut c_void { - self.mmap_pointer + self.mmap_pointer.as_ptr() } } @@ -28,7 +29,7 @@ impl Drop for MmapOwner { // ); unsafe { - nix::sys::mman::munmap(self.mmap_pointer.cast::(), self.size) + nix::sys::mman::munmap(self.mmap_pointer, self.size) .expect("BUG: munmap should not fail"); } } @@ -40,23 +41,21 @@ pub struct MmapRegion { } impl MmapRegion { - // this is actually used by faultlatency; clippy doesn't find it? + // this is used by faultlatency; clippy doesn't find it? #[allow(dead_code)] pub fn new(size: usize) -> Result { Self::new_flags(size, MapFlags::empty()) } pub fn new_flags(size: usize, flags: MapFlags) -> Result { - let mmap_pointer: *mut c_void; + let mmap_pointer: NonNull; let non_zero_size = NonZeroUsize::new(size).expect("BUG: size must be > 0"); unsafe { - mmap_pointer = nix::sys::mman::mmap( + mmap_pointer = nix::sys::mman::mmap_anonymous( None, non_zero_size, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, MapFlags::MAP_ANONYMOUS | MapFlags::MAP_PRIVATE | flags, - 0, - 0, )?; } @@ -71,4 +70,11 @@ impl MmapRegion { pub const fn get_mut(&self) -> *mut c_void { self.region.get_mut() } + + // this is actually used by faultlatency; clippy doesn't find it? + #[allow(dead_code)] + #[must_use] + pub fn ptr_as_usize(&self) -> usize { + self.region.get_mut() as usize + } }