1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
//! Tests for the `decommit_reclaims_and_zeroes()` capability API and diagnostic
//! counter (findings R4-3 and R4-4).
//!
//! Finding II-16 (tests for public constructors/accessors without coverage) applied:
//! every public API surface added in this wave must have a test that would fail if the
//! implementation were broken or deleted.
// Only `Reservation` is unconditionally available: `reserve_aligned_huge` is gated
// behind `huge-pages` and `reset_bench_internals_counters` behind `bench-internals`,
// so both are imported inside the gated tests that use them. A top-level unconditional
// `use` of either breaks the default-feature CI row
// (`cargo clippy -p aligned-vmem --all-targets -- -D warnings`) with E0432.
use Reservation;
// Serial guard for bench-internals tests that read/write global counters
// (mirrors the pattern from tests/smoke.rs — see the comment block there for rationale).
static SERIAL: Mutex = new;
const MIB: usize = 1024 * 1024;
/// Test that `decommit_reclaims_and_zeroes()` returns the correct compile-time
/// constant for the current platform (finding R4-3, II-16).
///
/// What breaks if this test is deleted: the cfg-based contract of
/// `decommit_reclaims_and_zeroes()` could drift from actual platform behavior
/// without any regression guard. A future maintainer adding a new target could
/// erroneously return `true` on a platform where decommit is advisory-only,
/// or `false` on a platform where it actually guarantees reclaim+zero-fill.
/// The mock arm (task #1066) is the counterfactual for the cfg fix: dropping
/// `aligned_vmem_mock` from the exclusion list would silently regress the
/// query to `true` under the mock with no red test.
/// Test that `can_decommit_reclaim_and_zero()` returns `false` for huge-page reservations
/// and equals the platform query for ordinary (fallback) reservations.
///
/// What breaks if this test is deleted:
/// - The instance-level query could incorrectly return `true` for huge-page reservations,
/// leading callers to believe decommit will work when it actually silently fails (R5-1, finding 3).
/// - The documented relationship (instance query = platform query && !is_huge) could be broken
/// for ordinary reservations, because this is the ONLY test that checks it on a real
/// reservation obtained via `reserve_aligned_huge` (which may fall back to ordinary pages).
///
/// Counterfactual for huge case: if the implementation returns `Self::decommit_reclaims_and_zeroes()`
/// (removing `&& !self.is_huge()`), this test fails on any host where `is_huge() == true`.
///
/// NOTE (updated task #1160/F4): The huge-page success path (the `if reservation.is_huge()`
/// branch) is NOT exercised on STANDARD CI runners — `ubuntu-latest` runners have no configured
/// hugetlb pool (`/proc/sys/vm/nr_hugepages` defaults to 0), and `windows-latest` runners lack
/// `SeLockMemoryPrivilege` — see item 59b in `docs/CORRECTNESS_OPEN_ITEMS.md` (the Windows half,
/// still fully open). The Linux half is narrower than it used to be: the dedicated
/// `aligned-vmem-hugetlb-real` CI job (`.github/workflows/ci.yml`) DOES configure a real
/// `nr_hugepages` pool and DOES run this test file (`--test decommit_capability`), so under
/// THAT job `reservation.is_huge()` is `true` here and the huge-page branch below executes for
/// real — see item 59a in `docs/CORRECTNESS_OPEN_ITEMS.md` for what that job proves and what it
/// still does not (the kernel-response question). On every OTHER runner (including the general
/// `test-workspace`/`aligned-vmem-gates` jobs, and Windows everywhere),
/// `reserve_aligned_huge` falls back to ordinary pages, so only the ordinary (fallback) case
/// below executes there. The test remains valuable as documentation of the contract and for the
/// rare host where huge pages are actually available.
///
/// Counterfactual for ordinary case: if the implementation returns `true` unconditionally
/// or writes `||` instead of `&&`, this test fails on Linux/Windows (where platform query returns `true`
/// but the instance query should return `false` for huge pages, and `true` for ordinary fallback).
/// Test that `can_decommit_reclaim_and_zero()` returns the platform capability
/// for ordinary (non-huge) reservations.
///
/// What breaks if this test is deleted: the instance-level query could diverge from
/// the platform-level query for ordinary reservations, breaking the documented
/// relationship (instance query = platform query && !is_huge). The mock arm
/// (task #1066) pins the instance query to the platform query's new `false`
/// answer under the `aligned_vmem_mock` cfg.
/// Test that `huge_decommit_attempts()` counter increments when decommit is called
/// on a huge-page reservation with a range that is NOT eligible for the
/// Linux/Android >= 5.18 real-backend path (finding R4-4, II-16; range
/// narrowed task #1140 — see the regression note below).
///
/// What breaks if this test is deleted: the counter increment could be removed
/// or moved to the wrong place (e.g., outside the `is_huge()` check) without any
/// regression guard. The counter is the only observability mechanism for the
/// "decommit silently fails on huge reservations" problem; without this test,
/// that observability could vanish unnoticed.
///
/// **Regression note (task #1140, discovered during this task's own
/// verification):** this test originally called `reservation.decommit(0,
/// size)` with `size == 2 MiB == LINUX_HUGE_PAGE_SIZE` inside the
/// `is_huge()` arm, then asserted the skip counter incremented. Since task
/// #1140, that exact call is now an ELIGIBLE range on a sufficiently recent
/// Linux/Android kernel (it takes the real `MADV_DONTNEED` backend path
/// instead of skipping), so the counter would correctly stay at `baseline`
/// instead of reaching `baseline + 1` — a false failure of correct behavior
/// on any real hugetlb-pool host running such a kernel. No CI runner in this
/// repo configures such a pool today, so this specific failure has never been
/// observed in CI (the `if` arm has never executed there), but it WAS
/// reproduced for real on a manually-provisioned WSL2/Linux kernel 6.18 host
/// with the huge flag genuinely synthesized via `from_raw_parts` (see
/// `simulated_huge_flag_drives_the_same_branch_dispatch_on_any_host` below)
/// during this task's own verification pass. The `decommit(0, ps)` probe
/// below (page-aligned, in-bounds, but never a 2-MiB multiple) stays on the
/// skip path unconditionally, closing the gap before a real hugetlb runner
/// ever exercises it. The eligible-range real-backend case has its own
/// dedicated coverage:
/// `huge_aligned_range_takes_the_real_backend_path_not_the_skip_path` below.
/// Test that `huge_decommit_attempts()` does NOT increment for ordinary reservations
/// (finding R4-4, II-16).
///
/// What breaks if this test is deleted: the counter increment could be moved outside
/// the `is_huge()` guard, causing it to increment for ALL decommits, not just
/// huge-page ones. This would break the counter's contract as an upper bound for
/// estimating the true huge-page incompatibility rate.
/// Task #1140: on Linux/Android kernel >= 5.18, a huge-page-aligned range on a
/// GENUINELY huge reservation must take the REAL backend path (`MADV_DONTNEED`
/// actually issued), not the silent-skip path — the reverse of what
/// `huge_decommit_attempts_increments_on_huge_reservation` above pins for the
/// pre-#1140 behavior. This test asserts exactly the opposite counter
/// direction from that test, on the same `is_huge()` branch, for a range that
/// is additionally 2-MiB-aligned at both endpoints.
///
/// **Counterfactual:** reverting the `reservation.rs` change from task #1140
/// (restoring the unconditional `if self.is_huge() { ...; return; }` skip)
/// makes this test fail: `huge_decommit_attempts()` would increment by 1 for
/// EVERY call in this test, including the 2-MiB-aligned one, so the first
/// assertion below (`baseline` unchanged after the aligned call) would read
/// `baseline + 1` instead and fail.
///
/// **Execution honesty (per this task's own brief; updated task #1160/F4):**
/// this assertion only actually exercises the new code path when
/// `reservation.is_huge()` is `true`, which requires a REAL hugetlb pool
/// (`/proc/sys/vm/nr_hugepages > 0`). At the time this test was authored, no
/// runner in this repo's CI configured one (see item 59 in
/// `docs/CORRECTNESS_OPEN_ITEMS.md`, and the same caveat on
/// `can_decommit_reclaim_and_zero_returns_false_for_huge_reservations`
/// above). **That has changed:** the `aligned-vmem-hugetlb-real` CI job
/// (`.github/workflows/ci.yml`) now configures a real `nr_hugepages` pool
/// and runs this exact test (this function is one of its six
/// hard-asserted `test <name> ... ok` sentinels — plus two literal
/// `[oracle] ARMED: ...` marker sentinels, eight `grep -F` checks in total
/// as of task #1166's recount), so under THAT job `reservation.is_huge()` is
/// `true` and this test genuinely exercises the real-backend branch —
/// proving the crate's dispatch reaches the real
/// `madvise(2)`/`MADV_DONTNEED` call, not that the kernel honoured it (see
/// `decommit`'s own rustdoc for that distinction). On every OTHER host this
/// crate's CI runs on (including the general `test-workspace` job, and the
/// Windows host this test was originally authored on), `reserve_aligned_huge`
/// still falls back to ordinary pages, `is_huge()` is `false`, and this test
/// exercises only the `else` arm (already covered by the ordinary-reservation
/// tests above) — it is NOT a false pass there either, it is an honest skip
/// of the new-behavior assertion, matching this file's own pre-existing
/// pattern for the same structural reason.
/// Task #1140, HOST-INDEPENDENT branch-dispatch proof: the two tests above
/// (`huge_aligned_range_takes_the_real_backend_path_not_the_skip_path` and its
/// sibling in `huge_decommit_attempts_increments_on_huge_reservation`) can only
/// exercise their real assertions on a host with a configured hugetlb pool —
/// on every other host, including this task's own Windows authoring host, they
/// silently no-op. This test proves the SAME `is_huge()`-plus-range-alignment
/// BRANCH DISPATCH logic in `Reservation::decommit`/`try_decommit` without
/// needing a real hugetlb pool, by fabricating `is_huge() == true` over an
/// ORDINARY (non-`MAP_HUGETLB`) mapping via the documented
/// `into_full_parts`/`from_raw_parts` round-trip.
///
/// **Why this is a sound (not unsound) use of `from_raw_parts`:** the
/// constructor's own "Correctness contract" section (task #1172/M3 split;
/// previously part of `# Safety` before that split) requires `granted_huge`
/// to accurately reflect the OS grant, and this test deliberately violates
/// that for `is_huge()`'s OBSERVABLE VALUE — but `granted_huge` has NO effect
/// on any unsafe operation `from_raw_parts`/`Drop`/`release_reservation`
/// performs (verified by reading every `granted_huge` use site in
/// `src/reservation.rs`/`src/os/unix.rs`/`src/os/windows.rs`: it is stored and
/// read back verbatim, never branched on by any pointer-unsafe code path —
/// `munmap`/`VirtualFree` care only about `reservation`/`reservation_len`/
/// `align`, never about `granted_huge`). Since task #1172, `from_raw_parts`
/// ALSO reads the raw `granted_huge` PARAMETER (before it becomes a field) in
/// two Correctness-contract `assert!`s (`huge-pages`-feature-required, and —
/// on Linux/Android — the 2-MiB-multiple requirement); this test's `size ==
/// 2 * MIB` base reservation and its `huge-pages` feature gate (see this
/// test's own `#[cfg]`) satisfy both, same reasoning as
/// `reservation_decommit_contract.rs`'s sibling test. Both `assert!`s are
/// safe Rust — not pointer-unsafe operations — so this does not weaken the
/// claim above. The ONLY consumers of `is_huge()` itself (the accessor, as
/// opposed to the raw parameter) are `Reservation::decommit`/`try_decommit`'s
/// branch dispatch (exactly what this test exercises) and the two
/// capability-query methods (not exercised here) — both operate purely on
/// already-validated, in-bounds byte ranges of
/// a live mapping, so fabricating this one bool cannot cause memory unsafety.
///
/// **What this test DOES prove:** the Rust-level decision of "does
/// `Reservation::decommit`'s huge branch call the real backend, or take the
/// silent-skip + counter-increment path" is driven by `is_huge()` AND
/// `linux_huge_range_is_madvise_eligible`'s range check — exactly the new
/// logic task #1140 added — regardless of whether the underlying mapping is
/// truly `MAP_HUGETLB`.
///
/// **What this test does NOT prove:** that a REAL `MAP_HUGETLB` mapping's
/// `madvise(MADV_DONTNEED)` call actually succeeds/zeroes on a real
/// Linux >= 5.18 kernel — an ordinary (non-hugetlb) anonymous mapping accepts
/// `MADV_DONTNEED` at ANY granularity on EVERY Linux kernel version (this is
/// not new to 5.18; only `MAP_HUGETLB` mappings had the granularity
/// restriction this task's fix is about), so this test's underlying syscall
/// always succeeds regardless of host kernel version — it is not evidence for
/// the kernel-version-gated HugeTLB claim itself, only for the branch-dispatch
/// logic around it. That claim remains REASONED-FROM-SPEC per `man 2 madvise`,
/// as stated throughout this task's doc changes and its own final report.
/// Task #1140: `Reservation::try_decommit`'s validate-before-huge-skip
/// ordering (task #1084/M3) must still hold when the huge-aligned real-call
/// path is reachable — an INVERTED range that happens to be huge-page-aligned
/// at both endpoints (`start = 2 * size, end = size` for a `size`-byte
/// reservation, both multiples of `LINUX_HUGE_PAGE_SIZE`) must be rejected as
/// `Err` by the bounds check before ever reaching the eligibility check, on
/// every platform and every `is_huge()` value — this test does not require a
/// real hugetlb pool because the bounds check (`end > self.len()`) rejects it
/// unconditionally, before `is_huge()` is even consulted.
///
/// **Counterfactual:** if the bounds/validation checks in `try_decommit` were
/// ever reordered to run AFTER the huge-eligibility check (the exact bug
/// class task #1084/M3 already fixed once for the huge-skip branch), this
/// range could reach `linux_huge_range_is_madvise_eligible(2*size, size)` —
/// which itself now rejects `start > end` (see that function's own doc) — but
/// a caller relying on the OUTER bounds check firing first would see a
/// different error path. This test pins the outer bounds check as the first
/// gate regardless of internal eligibility-check details.
/// Task #1152 (F1): path-activation oracle for the `aligned-vmem-hugetlb-real`
/// CI job (`.github/workflows/ci.yml`).
///
/// Every huge-decommit test above (`huge_decommit_attempts_increments_on_huge_reservation`,
/// `huge_aligned_range_takes_the_real_backend_path_not_the_skip_path`) is
/// deliberately host-adaptive: `if reservation.is_huge() { <real assertions> }
/// else { return; }`. That is the right shape for a test that must also pass
/// on a host with no hugetlb pool (every dev machine, `windows-latest`,
/// `ubuntu-latest` without the pool configured) — but it means NONE of them
/// can, by themselves, prove that a CI job which claims to grant a real
/// hugetlb pool actually did. A job that configures `nr_hugepages=64` but
/// whose `MAP_HUGETLB` mmap still silently fails (cgroup limit, NUMA
/// placement, a future runner-image change) would still show every one of
/// those tests as `ok`, because they all take the documented ordinary-page
/// fallback branch — the exact "green and dead" failure mode CLAUDE.md's
/// R30-8 rule (path-activation oracle) exists to close.
///
/// This test is the oracle: gated behind an env var
/// (`ALIGNED_VMEM_REQUIRE_REAL_HUGETLB=1`) that only the
/// `aligned-vmem-hugetlb-real` job sets, it refuses the fallback outcome
/// outright. Unset (every other environment, including a developer's own
/// machine and every other CI job), it no-ops immediately — it is not a
/// general-purpose "prove huge pages work" test, only a tripwire for the one
/// job that is supposed to guarantee a real pool.
///
/// **Counterfactual:** if the runner's hugetlb pool silently stops actually
/// backing `MAP_HUGETLB` allocations (while `/proc/sys/vm/nr_hugepages`
/// still reads back a nonzero value, so the job's own pool-configuration
/// step keeps passing), `reserve_aligned_huge` falls back to ordinary pages,
/// `is_huge()` is `false`, and this test's `assert!` fires — turning the job
/// red instead of green-and-silent. Validated by forcing the same assertion
/// against a real fallback outcome on a non-hugetlb host (this task's own
/// verification; see the task's final report for how, since this repository
/// has no way to grant a real hugetlb pool on Windows or in this sandbox).
///
/// **Task #1162 — arming itself was pinned by nothing.** Before this task,
/// the ARMED (`ALIGNED_VMEM_REQUIRE_REAL_HUGETLB=1` set, real grant
/// confirmed) and UNARMED (var unset or wrong, early `return`) outcomes both
/// printed the identical libtest line `test
/// ci_hugetlb_real_pool_oracle_refuses_ordinary_page_fallback ... ok` — so a
/// future edit that dropped the env var (e.g. a bad `env:` block indent, or
/// a merge that lost the prefix) would make this oracle silently no-op on
/// every run, and nothing in ci.yml, `scripts/verify-ci-sentinels.mjs`, or
/// this test itself would go red: every huge test would quietly take its
/// `if reservation.is_huge()` fallback branch, all five sentinels the
/// `aligned-vmem-hugetlb-real` job checks would still match, and the job
/// would report success while proving zero hugetlb coverage. Closed by
/// making ARMED observably different from UNARMED in the OUTPUT itself: a
/// `println!("[oracle] ARMED: ...")` after the assert above, which only
/// executes on the real-grant path, checked by its own additional `grep -F`
/// sentinel in ci.yml. **Task #1166 correction:** this marker is observed by
/// running THIS test alone (`--exact <name> -- --nocapture`), not by adding
/// `--nocapture` to the job's shared multi-test run — `--nocapture` does not
/// change libtest's `test <name> ... ok` line FORMAT, but under the default
/// parallel runner it does NOT print that line atomically either: the
/// aggregating main thread writes `"test {name} ... "`, the outcome word,
/// and the trailing newline as three separate writes, and an unsynchronized
/// worker-thread `println!` (this marker, or the sibling oracle's) can land
/// between them and split another test's sentinel line — confirmed by a
/// 400-run counterfactual (11/400 corrupted) documented in
/// `.github/workflows/ci.yml`'s `aligned-vmem-hugetlb-real` step. This
/// checks EXECUTION, not workflow text, so it cannot be defeated by moving
/// the env var to a different syntactic position in the YAML.
/// Task #1164 (item 59a's own next-trigger, task #1160/F5): the KERNEL-RESPONSE
/// half of item 59a — closes the one gap `ci_hugetlb_real_pool_oracle_refuses_
/// ordinary_page_fallback` above deliberately leaves open. That oracle proves
/// (a) a real `MAP_HUGETLB` grant was obtained and (b) the eligible-range
/// decommit dispatch reaches the real backend call — but `libc_madvise`
/// (`src/os/unix.rs`) discards the syscall's own return value by design (task
/// #719), so nothing observes whether the KERNEL actually accepted the call
/// (`madvise(2)` returning `0`) versus rejecting it (`-1`). This test is that
/// observation, for the one case where a rejection is a genuine defect rather
/// than a tolerated OS refusal: an eligible (huge-page-size-aligned) range,
/// decommitted eagerly, against a freshly-confirmed-real `MAP_HUGETLB` grant,
/// inside the `aligned-vmem-hugetlb-real` job specifically.
///
/// **Why a `madvise` failure HERE is treated as a red build, unlike the
/// crate's general contract (`decommit`'s own rustdoc) that OS refusal is
/// non-erroneous:** the crate's tolerance for refusal exists for conditions
/// this test's environment does not have — cgroup memory limits, memory
/// pressure, an unsupported kernel. `man 2 madvise` documents
/// `MADV_DONTNEED`-on-HugeTLB support from Linux 5.18 (see
/// `linux_huge_range_is_madvise_eligible`'s own doc comment in
/// `src/os/unix.rs`); `ubuntu-latest` (this job's `runs-on`) ships a kernel
/// far newer than that baseline. The job's own pool-configuration step
/// hard-fails (not skips) if `nr_hugepages` cannot be raised to at least 8
/// (`.github/workflows/ci.yml`), and the oracle immediately above this test
/// already hard-asserts the grant was real, not a fallback. Under those three
/// preconditions — modern kernel, a genuinely configured pool, a real grant —
/// there is no realistic legitimate-refusal path left for `MADV_DONTNEED` on
/// a huge-page-size-aligned range: a `-1` return here would mean the kernel
/// or the pool configuration silently regressed, which is exactly the class
/// of defect this job exists to surface as red rather than green-and-dead.
///
/// **Vacuous-pass analysis — every path this test could report `ok` without
/// having proven anything, and how each is closed:**
/// 1. **Env var unset (every host except this one CI job):** the same early
/// `return` as the oracle immediately above — a genuine, honest no-op, not
/// a claim of anything proven. Gated identically, for the identical
/// reason.
/// 2. **`#[cfg]` excluding this function entirely:** requires
/// `feature = "bench-internals"` (the counters this test reads do not
/// exist without it — see below), `feature = "huge-pages"` (the real
/// dispatch path does not exist without it), and
/// `target_os = "linux"`/`"android"` (the only platforms
/// `linux_huge_range_is_madvise_eligible` compiles for) — the same three
/// gates the oracle above already requires, so this test can never run
/// somewhere the oracle itself would not also run.
/// 3. **`bench-internals` off:** `unix_madvise_attempts`/`unix_madvise_successes`
/// are themselves `#[cfg(feature = "bench-internals")]`-gated re-exports
/// (`src/lib.rs`) — calling them without the feature is a compile error
/// (E0432 unresolved import), not a silent no-op. This function's own
/// `#[cfg]` includes the same feature, so the whole test (not just the
/// calls) is absent from the binary when the feature is off — it cannot
/// exist to vacuously pass. (Confirmed by this task's own
/// `--features huge-pages` clippy run below: this file compiles clean
/// with the test simply not present.)
/// 4. **The reservation falling back to ordinary pages:** hard-asserted via
/// `is_huge()` BEFORE the decommit call, with a panic message identical in
/// spirit to the oracle's own — this test does not assume the grant from
/// the oracle's run persists across test-binary process boundaries (it
/// does not; each `#[test]` fn in the same binary runs in the same
/// process but makes its OWN `reserve_aligned_huge` call), so it re-proves
/// the grant itself rather than relying on the earlier oracle having run
/// first (libtest does not guarantee ordering, and does not guarantee
/// both tests run in the same invocation at all).
/// 5. **The range being ineligible so the crate early-exits before any
/// syscall:** `size = 2 * MIB` and the full span `[0, size)` is exactly
/// one huge page — both endpoints are `LINUX_HUGE_PAGE_SIZE` multiples by
/// construction (mirrors `huge_aligned_range_takes_the_real_backend_path_
/// not_the_skip_path` above), so `linux_huge_range_is_madvise_eligible`
/// is `true` and the eager `decommit` call is guaranteed to reach
/// `libc_madvise`, not the skip-and-count path.
/// 6. **Another test perturbing the counters concurrently:** `SERIAL` (this
/// file's shared `Mutex<()>`, held for the same reason `tests/smoke.rs`'s
/// `macos_decommit_madvise_syscall_actually_succeeds` holds its own) is
/// locked for this test's entire body, and `reset_bench_internals_counters()`
/// is called AFTER acquiring the lock but BEFORE the decommit call, so the
/// baseline this test reads cannot be contaminated by a concurrently
/// running test in the same process (this file's other `#[test]` fns that
/// touch these counters all join the same `SERIAL` contract). That last
/// parenthesis was FALSE until task #1223: four `#[test]` fns in this
/// file reserved memory without taking `SERIAL` at all, three of them at
/// `size == align == 2 MiB` -- exactly `unix_reserve`'s exact-size
/// `MAP_HUGETLB` fast-path entry condition, which moves
/// `UNIX_EXACT_RESERVE_ATTEMPTS`/`_HITS`. Holding the lock never excluded
/// them, because a mutex only excludes the parties that take it; the
/// claim described an obligation nobody had written down rather than one
/// the code enforced. It cost a red `main`. The claim is true as written
/// NOW only because #1223 added the four missing `SERIAL.lock()` calls --
/// it is not self-maintaining, and a new reserving test added to this
/// file without the lock silently makes it false again.
///
/// **Counterfactual (built OUTSIDE this repo, since a real hugetlb pool is
/// not available in this sandbox on Windows):** substituted `libc_madvise`'s
/// `UNIX_MADVISE_SUCCESSES.fetch_add` call with a no-op (simulating the
/// kernel returning `-1` on every call) in a scratch copy of `src/os/unix.rs`
/// outside this worktree, then ran an equivalent ordinary (non-huge)
/// `reserve_aligned`/`decommit`/counter-assert sequence on this Windows
/// fallback host. The assertion below (`successes > baseline_successes`)
/// failed exactly as expected, with the message below, confirming the
/// assertion is not tautological. **What this substitution does NOT
/// establish:** it does not exercise the real `MAP_HUGETLB`-plus-eligible-
/// range dispatch this test targets (Windows has no such path at all), so it
/// only proves the ASSERTION LOGIC is sound, not that this specific test body
/// would fail the same way on a real Linux hugetlb host with a genuinely
/// broken kernel/pool — that confirmation can only come from a real
/// `aligned-vmem-hugetlb-real` CI run with the counter regressed, which this
/// task did not have the means to force.
/// Task #1174 (item 87's next-trigger via the linked jobs, R30-8-class gap):
/// closes the one thing neither `ci_hugetlb_real_pool_oracle_refuses_
/// ordinary_page_fallback` nor `ci_hugetlb_real_pool_kernel_actually_accepts_
/// eligible_madvise` above ever checks — **memory content**. Both siblings
/// prove the kernel *dispatched* the `madvise(2)` call and *accepted* it
/// (returned 0); neither reads a single byte back. A kernel that accepts
/// `MADV_DONTNEED` on a real `MAP_HUGETLB` mapping but does not actually
/// reclaim/zero the underlying pages on next access — a real, documented
/// possibility this crate's own rustdoc distinguishes from acceptance (see
/// `Reservation`'s own doc block, "Huge reservations, eager `decommit`" —
/// zero-fill is the SEPARATE guarantee stated for that one eligible case, not
/// implied by acceptance alone) — would leave both siblings green while the
/// crate's documented postcondition for this exact case silently did not
/// hold.
///
/// This test is the write -> decommit -> read postcondition check: write a
/// non-zero pattern across a huge-page-size-aligned, madvise-eligible range,
/// `decommit()` it, then read every byte back and assert zero. This mirrors
/// `reservation_decommit_in_bounds_matches_free_function` in `tests/smoke.rs`
/// (the identical write/decommit/read-zero shape for the ORDINARY-page eager
/// case), narrowed to the one huge-page case where the crate's own doc
/// promises the same guarantee.
///
/// **What this test does NOT check (deliberately, see CLAUDE.md's
/// two-properties rule): whether huge pages were actually returned to the
/// pool / whether `HugePages_Free` increased.** That is a physical-resource
/// accounting question, not a content question, and unlike this test's
/// read-zero assertion it is not deterministic from inside one `#[test]` fn
/// in this process: `/proc/sys/vm/nr_hugepages` and `/proc/meminfo`'s
/// `HugePages_Free` are process-EXTERNAL, kernel-global counters that this
/// job's OWN earlier steps and every other test binary/target this job runs
/// (`huge_pages.rs`, `reservation_decommit_contract.rs`, the other tests in
/// THIS binary) also allocate from and release into — a `#[test]` fn cannot
/// snapshot "before" without racing every other huge-page reservation
/// already made or still live in this job, and cargo test's default
/// multi-threaded runner does not serialize across `#[test]` FILES the way
/// this file's own `SERIAL` mutex only serializes within itself. Folding a
/// noisy, shared, external counter into the SAME hard assert as this test's
/// deterministic in-process read-zero check would make an otherwise-reliable
/// oracle flaky on scheduling alone — exactly the class of defect CLAUDE.md's
/// "Tests must not be flaky" rule and the two-properties split both warn
/// against. The pool-free-count observation is instead taken as a
/// **best-effort, printed-not-asserted** measurement by the CI job itself
/// (`.github/workflows/ci.yml`'s `aligned-vmem-hugetlb-real` step, immediately
/// after this test's own `cargo test` invocation), reading
/// `/proc/meminfo`'s `HugePages_Free` before and after that invocation and
/// logging the delta — informative, not a gate, and NOT proof that pages
/// were returned (a nonzero job-level delta could come from any of this
/// job's other huge-page tests releasing their own reservations in the same
/// window, not specifically from this test's `decommit()` call).
///
/// **Vacuous-pass analysis:**
/// 1. **Env var unset:** the same honest early `return` as both siblings
/// above — gated identically, for the identical reason.
/// 2. **`#[cfg]` excluding this fn:** requires `huge-pages` (the real
/// dispatch path) and `target_os = "linux"`/`"android"` (the only
/// platforms the huge-aligned real-call path compiles for). Stated
/// precisely, because the two siblings do NOT have the same gate:
/// this is BYTE-IDENTICAL to
/// `ci_hugetlb_real_pool_oracle_refuses_ordinary_page_fallback`'s gate,
/// and a strict subset of
/// `ci_hugetlb_real_pool_kernel_actually_accepts_eligible_madvise`'s,
/// which additionally requires `feature = "bench-internals"` for the
/// counters it reads and this test does not. So this test compiles in
/// every configuration either sibling does, and in strictly more than
/// the second one — never fewer than either.
/// 3. **The reservation falling back to ordinary pages:** hard-asserted via
/// `is_huge()` BEFORE the write/decommit/read sequence — the same
/// tripwire both siblings use, and required by construction: without it
/// this test would silently validate the ordinary-page zero-fill
/// guarantee (already covered by `reservation_decommit_in_bounds_
/// matches_free_function` in `tests/smoke.rs`) and prove nothing about
/// the huge-page path.
/// 4. **The range being ineligible so the crate early-exits before any
/// syscall:** `size = 2 * MIB` and the full span `[0, size)` is exactly
/// one huge page, huge-page-size-aligned at both endpoints by
/// construction — identical reasoning to both siblings above.
/// 5. **The write pattern happening to already be zero:** written as `0xAB`
/// (never zero), so a decommit that is a complete no-op (old contents
/// left in place) would leave every byte `0xAB`, not `0`, and the read
/// loop below would fail on the very first byte.
/// 6. **Reading before the kernel has actually reclaimed the pages:** unlike
/// Darwin's advisory-only `MADV_DONTNEED`, Linux's `MADV_DONTNEED` on an
/// eligible range zero-fills synchronously with respect to the NEXT
/// access from the calling process (task #1140's own doc citation, `man 2
/// madvise`) — there is no reclaim-is-still-pending race to account for
/// here, unlike the RSS/pool-accounting axis this test deliberately does
/// not touch (point above).
/// 7. **Another test perturbing this range concurrently:** `SERIAL` (this
/// file's shared `Mutex<()>`) is held for this test's entire body, same
/// contract as both siblings and every other bench-internals-adjacent
/// test in this file.
/// Task #1189 (coverage gap C2 from
/// `docs/reviews/2026-08-19-2148-aligned-vmem-publication-audit-Сол-кодекс.md`):
/// closes the report's own named gap for the real-HugeTLB job specifically
/// -- `UNIX_MUNMAP_FAILURES` existed but no test in this job ever checked it
/// (or any release counter) around a HugeTLB reservation's `Drop`. The
/// report's own words: "the crate's comment in `unix.rs` assumes leak would
/// show up as test failure/resource exhaustion... but pool contains many
/// pages (64) and concurrent mappings are few, so absence of release is not
/// guaranteed to redden the job" -- i.e. a deleted release call site would
/// stay invisible in this job forever without a direct oracle.
///
/// This is the deterministic, in-process half of that oracle (mirroring the
/// two-properties split `ci_hugetlb_real_pool_decommit_actually_zeroes_
/// memory_on_reaccess` above already uses for the write/decommit/read
/// property vs. the shared `HugePages_Free` pool-count property): reserve
/// one real HugeTLB mapping, snapshot `unix_munmap_attempts()`/
/// `unix_munmap_failures()`, `drop()` the reservation (the ONLY `munmap`
/// call in this window -- `SERIAL` excludes every other test in this
/// binary, and this test makes exactly one reservation), then hard-assert
/// the attempts delta is exactly 1 and the failures delta is 0. Unlike
/// `HugePages_Free` (a kernel-global counter shared across this job's other
/// huge-page targets, see the sibling test's own doc for why that one stays
/// printed-not-asserted), `UNIX_MUNMAP_ATTEMPTS`/`_FAILURES` are THIS
/// PROCESS's own counters -- this test's binary (`decommit_capability`) is
/// a separate OS process from the job's other two test binaries
/// (`huge_pages`, `reservation_decommit_contract`), so nothing outside this
/// one `#[test]` fn's own `SERIAL`-guarded window can touch them. Both
/// halves of that sentence -- "`SERIAL` excludes every other test in this
/// binary" above, and "nothing outside this window can touch them" here --
/// were FALSE until task #1223, and this test was the more exposed of the
/// two counter-reading tests, not the less: its assert is `munmap` delta
/// EXACTLY 1, and EVERY reservation in this file emits one `munmap` on
/// drop, so any of the four then-unlocked tests dropping a reservation
/// inside this window would have pushed the delta to 2 and failed it. It
/// never fired only because the four unlocked tests happened not to overlap
/// this one; the counter-reading sibling that DID fire (the align > 2 MiB
/// oracle below) needed the narrower coincidence of an increment landing
/// between two adjacent loads. Do not read this test's clean history as
/// evidence the reasoning was sound. A hard assert here is the CORRECT
/// strength, not a compromise -- see
/// `UNIX_MUNMAP_ATTEMPTS`'s own doc comment
/// (`src/bench_internals/unix.rs`) for the general reasoning this specific
/// test applies.
///
/// **What this test does NOT check (same boundary the sibling test already
/// draws):** whether the huge page was actually returned to the kernel pool
/// (`HugePages_Free`) -- that is the job-level printed observation in
/// `.github/workflows/ci.yml`, unchanged by this test. This test proves the
/// RELEASE CALL ITSELF ran and succeeded, not that the physical page came
/// back to the pool -- those are the same "acceptance vs. physical
/// resource" distinction the sibling test's own doc draws for decommit.
///
/// **Vacuous-pass analysis:**
/// 1. **Env var unset:** the same honest early `return` as every sibling
/// oracle in this file.
/// 2. **`#[cfg]` excluding this fn:** requires `huge-pages` (for
/// `reserve_aligned_huge`) AND `bench-internals` (for the counters) AND
/// `target_os = "linux"`/`"android"` (the only platforms
/// `UNIX_MUNMAP_ATTEMPTS` is compiled for -- see that static's own
/// `#[cfg]`, which additionally requires `unix` and excludes `miri`,
/// both satisfied whenever `target_os = "linux"`/`"android"` holds).
/// Narrower than `ci_hugetlb_real_pool_decommit_actually_zeroes_memory_
/// on_reaccess`'s gate (that one does not need `bench-internals`), same
/// shape as `ci_hugetlb_real_pool_kernel_actually_accepts_eligible_
/// madvise`'s gate.
/// 3. **The reservation falling back to ordinary pages:** hard-asserted via
/// `is_huge()`, identical tripwire to every sibling oracle in this file
/// -- without it this test would validate the ordinary-page release
/// path (already implicitly exercised by every other test in this
/// crate's suite that drops a `Reservation`) and prove nothing new
/// about the HugeTLB-specific `munmap` alignment contract task #714
/// documents (`src/os/unix.rs`'s `unix_reserve` doc comment: `munmap`'s
/// `addr`/`length` must both be huge-page-size multiples for a
/// `MAP_HUGETLB` mapping, or the kernel returns `EINVAL` and leaks the
/// whole mapping).
/// 4. **A concurrent reservation/release in the same process touching the
/// same counters:** `SERIAL` is held for this test's entire body
/// (acquired before the reservation, released only when the function
/// returns), so no other test in THIS binary can run concurrently; no
/// other binary shares this process's counters (see the module-level
/// reasoning above). "No other test in THIS binary can run
/// concurrently" is a claim about what the OTHER tests do, not about
/// what this one does -- it holds only while every reserving test in
/// this file also takes `SERIAL`, which four of them did not until task
/// #1223. See the corrected paragraph above for the full account.
/// 5. **The counter increment being deleted from `libc_munmap` (the actual
/// regression this test exists to catch):** would make `attempts_after
/// == attempts_before` (delta 0, not 1), failing the first assert below
/// -- confirmed by a local counterfactual on the WINDOWS sibling of this
/// same fix (`tests/smoke.rs`'s
/// `windows_virtualfree_release_is_attempted_exactly_once_and_does_not_fail`,
/// which this test mirrors): commenting out
/// `WINDOWS_VIRTUALFREE_RELEASE_ATTEMPTS.fetch_add` there reproducibly
/// turns that test red (`left: 0, right: 1`), then reverted. The Unix
/// counterfactual for THIS test could not be run locally (no HugeTLB
/// pool on this project's Windows dev host, and this fn's own env-var
/// guard makes it a no-op outside `ALIGNED_VMEM_REQUIRE_REAL_HUGETLB=1`)
/// -- the Windows counterfactual is the same code shape
/// (`#[cfg(feature = "bench-internals")] X.fetch_add(1, ...)` guarding a
/// release-path attempts counter) and is the closest available
/// verification; this test is first actually EXECUTED on the real-hugetlb
/// CI runner, not before.
/// Task #1188 (perf-index item 57's P1, `docs/reviews/2026-08-19-2148-aligned-vmem-publication-audit-Сол-кодекс.md`
/// §P1): the report's own worked example is `size == align == 4 MiB`, which
/// over-reserves `size + align = 8 MiB` against the hugetlb pool for 4 MiB of
/// USABLE span -- a 2x pool charge, because `align > LINUX_HUGE_PAGE_SIZE`
/// (2 MiB) never reaches the exact-size fast path in `unix_reserve`
/// (`src/os/unix.rs`; that block's own `if huge && align ==
/// LINUX_HUGE_PAGE_SIZE` guard is a strict equality, not `<=`), so every such
/// request falls straight through to the general over-reserve path. Task
/// #1182's correction to item 48/52 found that despite a real-hugetlb host
/// existing in CI since task #1152 (`aligned-vmem-hugetlb-real`), no test in
/// that job's three files ever exercised `align > size` in a loop -- every
/// call was a single non-looped `(size, size)` reservation. This test is that
/// missing reservation-heavy `align > 2 MiB` workload.
///
/// **What this test measures, and how, matching the report's three requested
/// axes:**
/// 1. **Fallback rate** -- ASSERTED. `UNIX_EXACT_RESERVE_ATTEMPTS`/`_HITS`
/// are THIS PROCESS's own counters (not kernel-global), incremented only
/// by the exact-size huge path that requires `align == LINUX_HUGE_PAGE_SIZE`
/// exactly. For every reservation in this test's loop, `align = 2 *
/// LINUX_HUGE_PAGE_SIZE` (4 MiB) -- strictly greater than 2 MiB -- so
/// that block's guard condition is false by construction and the counter
/// must stay at 0 for the whole loop. A hard `assert_eq!(0)` here is not
/// a weaker stand-in for a hit-rate measurement: 0-of-N IS the fallback
/// rate this shape produces (100% of requests bypass the exact-size fast
/// path and take the over-reserve path), and it is deterministic given
/// the fixed `align`, not host-dependent -- unlike whether the OS grants
/// the underlying `MAP_HUGETLB` mapping at all (that part -- `is_huge()`
/// -- is the separate oracle below, and IS host-dependent on pool
/// capacity).
/// 2. **Syscall cost** -- ASSERTED, via `UNIX_MUNMAP_ATTEMPTS`. The
/// over-reserve path's known-good case (documented in `unix_reserve`'s
/// own comment, "Keep the entire over-reserve mapping... exactly as the
/// Windows backend does") makes exactly ONE `mmap` and, on success, ZERO
/// `munmap` calls per reservation (no head/tail trim) -- so across N
/// reservations released together, `UNIX_MUNMAP_ATTEMPTS` must increase
/// by exactly N (one `munmap` per `Drop`, matching
/// `ci_hugetlb_real_pool_release_is_attempted_exactly_once_and_does_not_fail`'s
/// established single-release-call oracle immediately above, now
/// generalized to N releases). This is the "price of the amplified
/// over-reserve path" the report calls for at the syscall-count level:
/// the crate's own comment already states the closed-form cost (1 mmap,
/// 0 extra munmap trims per reservation for this shape); this assertion
/// is the executable proof that closed form still matches the real
/// dispatch, not a new syscall-latency benchmark.
/// 3. **Pool occupancy** -- OBSERVATION ONLY, PRINTED NOT ASSERTED. Same
/// "assert or observe" decision as
/// `ci_hugetlb_real_pool_decommit_actually_zeroes_memory_on_reaccess`'s
/// own doc comment above, and for the identical reason stated there:
/// `/proc/meminfo`'s `HugePages_Free` is a kernel-global counter shared
/// with every other huge-page reservation this job's OTHER test
/// files/targets also make in the same run, so no single `#[test]` fn
/// can snapshot a "before" that isn't racing sibling activity outside
/// this file's own `SERIAL` mutex (which serializes only within this
/// binary, not across `huge_pages`/`reservation_decommit_contract`, run
/// as separate processes in the same job). Per that precedent, this
/// axis is instead a best-effort delta logged by the CI JOB itself
/// (`.github/workflows/ci.yml`'s `aligned-vmem-hugetlb-real` step),
/// bracketing this test's own isolated `--exact` invocation exactly like
/// the existing `marker3` bracket already does for the decommit-content
/// test -- informative for a human reading the log, never a pass/fail
/// gate. **Not duplicating the pre-existing marker3 bracket**: this
/// test's own isolated invocation gets its own before/after
/// `HugePages_Free` log lines in the CI step, because this test reserves
/// `RESERVATION_COUNT` LIVE, SIMULTANEOUSLY-HELD 4-MiB-aligned mappings
/// (8 MiB pool charge each = up to `RESERVATION_COUNT * 8 MiB` held at
/// peak, TWICE `RESERVATION_COUNT * size` because of this exact
/// over-reserve behavior) before releasing any of them -- a materially
/// different pool-pressure shape from marker3's single 2-MiB exact-fit
/// reservation, worth its own log bracket even though neither is a gate.
///
/// **Honesty boundary (explicitly NOT overclaimed):** this test does NOT
/// measure, and this doc does not claim to measure, whether trimming
/// head/tail after the over-reserve would reduce STEADY-STATE occupancy --
/// the report's own §P1 text says a trim does not remove the ADMISSION cost
/// of the initial `mmap(size + align)`, which is exactly what this test's
/// syscall-count and fallback-rate assertions bound (the admission-time
/// mmap always requests the full `over` span, unconditionally, regardless of
/// what happens after). Nor does it measure whether a request at this
/// amplified size ever tips over into an OS-level refusal (a real "fallback
/// to ordinary pages" outcome, as opposed to the "never attempts the
/// exact-size fast path" fallback this test's `UNIX_EXACT_RESERVE_ATTEMPTS`
/// assertion covers) -- that would depend on the pool's remaining headroom
/// after `RESERVATION_COUNT` reservations, which is exactly the pool
/// occupancy axis this test deliberately leaves as a printed observation,
/// not a hard assert, for the reasons stated above.
///
/// **Vacuous-pass analysis:**
/// 1. **Env var unset:** the same honest early `return` as every sibling
/// oracle in this file.
/// 2. **`#[cfg]` excluding this fn:** requires `huge-pages` (for
/// `reserve_aligned_huge`) AND `bench-internals` (for the counters) AND
/// `target_os = "linux"`/`"android"` (the only platforms
/// `UNIX_EXACT_RESERVE_ATTEMPTS`/`UNIX_MUNMAP_ATTEMPTS` compile for) --
/// identical shape to
/// `ci_hugetlb_real_pool_release_is_attempted_exactly_once_and_does_not_fail`'s
/// gate immediately above.
/// 3. **Every reservation falling back to ordinary pages:** hard-asserted
/// per-reservation via `is_huge()` inside the loop -- the same tripwire
/// every sibling oracle in this file uses, applied N times instead of
/// once, so a partial-fallback run (some huge, some not) still fails
/// loudly on the first ordinary-page reservation rather than silently
/// passing on an average.
/// 4. **The exact-size fast path secretly firing for `align > 2 MiB` (the
/// actual regression this test's first assertion would catch):** would
/// move `UNIX_EXACT_RESERVE_ATTEMPTS` off 0, failing that assert
/// immediately -- this is the direct counterfactual for a future change
/// that widens the fast path's guard from `align == LINUX_HUGE_PAGE_SIZE`
/// to something like `align >= LINUX_HUGE_PAGE_SIZE` without updating
/// this test's fixed premise.
/// 5. **A `munmap` trim being added to the over-reserve path for this shape
/// (the actual regression this test's second assertion would catch):**
/// would move `UNIX_MUNMAP_ATTEMPTS`'s post-loop delta above exactly
/// `RESERVATION_COUNT`, failing that assert -- `unix_reserve`'s own doc
/// comment (`src/os/unix.rs`) explicitly reasons about NOT re-adding
/// trims for exactly this reason ("would partially reverse task #842's
/// deliberate one-munmap soundness design"), so this assertion pins that
/// design decision as an executable invariant, not just a comment.
/// 6. **A concurrent reservation/release in the same process touching the
/// same counters:** `SERIAL` is held for this test's entire body,
/// identical contract to every other counter-touching test in this file.
/// THIS BULLET WAS FALSE AND THIS TEST IS WHAT PROVED IT (task #1223).
/// Holding `SERIAL` excludes only the tests that also take it, and four
/// `#[test]` fns in this file reserved without it -- three of them at
/// `size == align == 2 MiB`, which is precisely `unix_reserve`'s
/// exact-size `MAP_HUGETLB` fast-path entry condition and therefore
/// moves the two counters this test measures. The failure mode was
/// narrow enough to survive three green runs of the
/// `aligned-vmem-hugetlb-real` job and then turn `main` red on the
/// fourth: the two post-loop reads below are SEPARATE atomic loads
/// (`exact_attempts_after`, then `exact_hits_after`), so an interloper's
/// attempts-then-hits increment pair landing between them leaves the
/// attempts delta reading 0 (assert passes) and the hits delta reading 1
/// (assert fails) -- which is exactly the `left: 1, right: 0` CI
/// recorded. #1223 added the four missing locks, making the bullet true
/// as written; it is not self-enforcing, so a new reserving test added
/// to this file without `SERIAL` silently re-breaks it. The reads are
/// deliberately left as two loads: a single fused read would narrow this
/// particular window without closing the underlying hole (an interloper
/// reserving anywhere inside the loop would still corrupt both deltas),
/// and narrowing a race until it stops reproducing is how it comes back.
/// Local alias so the test above can name the 2-MiB huge page size without
/// duplicating the private `LINUX_HUGE_PAGE_SIZE` constant `src/os/unix.rs`
/// keeps `pub(crate)`-scoped (not visible from `tests/`) -- matches this
/// file's own pre-existing `MIB`-based constants (`huge_pages.rs` does the
/// same with its own file-local `LINUX_HUGE_PAGE_SIZE` const for the same
/// reason).
const LINUX_HUGE_PAGE_SIZE_FOR_TEST: usize = 2 * MIB;