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
//! Prevents [false sharing](https://en.wikipedia.org/wiki/False_sharing) by adding padding
//! (unused bytes) between variables.
//!
//! As CPU memory is cached in line of some small power of two-word size (e.g., 128 aligned),
//! using padding prevents two processors to operate on independent data that might have been
//! stored on the same cache line. Such operations could result in the invalidation of the
//! whole cache line. Reducing cache invalidation on frequently accessed shared data structure
//! helps in improving the performance by reducing memory stalls and waste of system bandwidth.
//!
//! # Size and alignment
//!
//! Cache lines are assumed to be N bytes long, depending on the architecture:
//!
//! - On x86_64 and aarch64, N = 128.
//! - On all others, N = 64.
//!
//! The size of `CachePad<T>` is the smallest multiple of N bytes large enough to accommodate
//! a value of type `T`.
//!
//! # Notes
//!
//! CPU cache line:
//!
//! - MacBook Air (M1, 2020)
//!
//! ```bash
//! sysctl -a | grep cachelinesize
//! hw.cachelinesize: 128
//! ```
use fmt;
use Deref;
/// Pads and aligns data to the length of a cache line.
pub ;