Commit 6846eb7
authored
Rollup merge of rust-lang#65094 - oxalica:linux-statx, r=alexcrichton
Prefer statx on linux if available
This PR make `metadata`-related functions try to invoke `statx` first on Linux if available,
making `std::fs::Metadata::created` work on Linux with `statx` supported.
It follows the discussion in rust-lang#61386 , and will fix rust-lang#59743
The implementation of this PR is simply converting `struct statx` into `struct stat64` with
extra fields for `btime` if `statx` succeeds, since other fields are not currently used.
---
I also did a separated benchmark for `fs::metadata`, `stat64`, `statx`, and `statx` with conversion to `stat64`.
It shows that `statx` with conversion is even more faster than pure `statx`.
I think it's due to `sizeof stat64 == 114` but `sizeof statx == 256`.
Anyway, the bare implementation of `statx` with conversion is only about 0.2% slower than the original impl (`stat64`-family).
With heap-allocation counted (~8.5% of total cost), the difference between `stat` and `statx` (with or without conversion) is just nothing.
Therefore, I think it is not urgent to use bare `struct statx` as underlying representation now.
There is no need to break `std::os::linux::fs::MetadataExt::as_raw_stat` (rust-lang#61386 (comment))
[Separated bare benchmarks](https://gist.github.com/oxalica/c4073ecb202c599fe41b7f15f86dc79c):
```
metadata_ok time: [529.41 ns 529.77 ns 530.19 ns]
metadata_err time: [538.71 ns 539.39 ns 540.35 ns]
stat64_ok time: [484.32 ns 484.53 ns 484.75 ns]
stat64_err time: [481.77 ns 482.00 ns 482.24 ns]
statx_ok time: [488.07 ns 488.35 ns 488.62 ns]
statx_err time: [487.74 ns 488.00 ns 488.27 ns]
statx_cvt_ok time: [485.05 ns 485.28 ns 485.53 ns]
statx_cvt_err time: [485.23 ns 485.45 ns 485.67 ns]
```
r? @alexcrichton2 files changed
+180
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1090 | 1090 | | |
1091 | 1091 | | |
1092 | 1092 | | |
1093 | | - | |
| 1093 | + | |
| 1094 | + | |
1094 | 1095 | | |
1095 | 1096 | | |
1096 | 1097 | | |
1097 | 1098 | | |
1098 | 1099 | | |
1099 | | - | |
| 1100 | + | |
1100 | 1101 | | |
1101 | 1102 | | |
1102 | 1103 | | |
| |||
1109 | 1110 | | |
1110 | 1111 | | |
1111 | 1112 | | |
1112 | | - | |
| 1113 | + | |
1113 | 1114 | | |
1114 | 1115 | | |
1115 | 1116 | | |
| |||
3443 | 3444 | | |
3444 | 3445 | | |
3445 | 3446 | | |
| 3447 | + | |
| 3448 | + | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
3446 | 3460 | | |
3447 | 3461 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
47 | 124 | | |
48 | 125 | | |
49 | 126 | | |
| |||
98 | 175 | | |
99 | 176 | | |
100 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
101 | 186 | | |
102 | 187 | | |
103 | 188 | | |
| |||
164 | 249 | | |
165 | 250 | | |
166 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
167 | 269 | | |
168 | 270 | | |
169 | 271 | | |
| |||
306 | 408 | | |
307 | 409 | | |
308 | 410 | | |
309 | | - | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
310 | 426 | | |
311 | 427 | | |
312 | | - | |
| 428 | + | |
313 | 429 | | |
314 | | - | |
| 430 | + | |
315 | 431 | | |
316 | 432 | | |
317 | 433 | | |
| |||
517 | 633 | | |
518 | 634 | | |
519 | 635 | | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
520 | 650 | | |
521 | 651 | | |
522 | | - | |
| 652 | + | |
523 | 653 | | |
524 | | - | |
| 654 | + | |
525 | 655 | | |
526 | 656 | | |
527 | 657 | | |
| |||
798 | 928 | | |
799 | 929 | | |
800 | 930 | | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
801 | 944 | | |
802 | 945 | | |
803 | 946 | | |
804 | 947 | | |
805 | | - | |
| 948 | + | |
806 | 949 | | |
807 | 950 | | |
808 | 951 | | |
809 | 952 | | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
810 | 966 | | |
811 | 967 | | |
812 | 968 | | |
813 | 969 | | |
814 | | - | |
| 970 | + | |
815 | 971 | | |
816 | 972 | | |
817 | 973 | | |
| |||
0 commit comments