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
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum MemoryStatisticName
{
TotalPhyiscalRam,
FreePhysicalRam,
AvailablePhysicalRam,
UsedAsFileBuffersPhysicalRam,
UsedAsCachePhysicalRam,
TotalSwap,
FreeSwap,
UsedAsCacheSwap,
ActiveFileBufferAndCacheInUse,
InactiveFileBufferAndCacheAvailable,
AnonymousActive,
AnonymousInactive,
FileActive,
FileInactive,
Unevictable,
WaitingToBeWrittenBackToDisks,
CurrentlyBeingWrittenBackToDisks,
UsedForBlockDeviceBounceBuffers,
NetworkFileSystemUnstablePagesSentToServerButNotYetCommitedToStableStorage,
MemoryUsedByFuseForTemporaryWritebackBuffers,
AnononymousMemoryMappedUsingMmap,
FilesMappedUsingMmap,
Shmem,
LockedByMlock,
Slab,
SlabReclaimable,
SlabUnreclaimable,
KernelStack,
MemoryDedicatedToLowestPageTableLevel,
CommitLimit,
WorstCaseScenarioMemoryRequiredToCompleteWorkloadIncludingSwapMemory,
TotalVirtualAddressSpaceEgByMalloc,
UsedVirtualAddressSpaceEgByMalloc,
LarestContiguousChunkInVirtualAddressSpaceEgByMalloc,
TotalNumberOfHugePages,
FreeNumberOfHugePages,
ReservedNumberOfHugePages,
SurplusNumberOfHugesPages,
SizeOfAHugePage,
TransparentHugePagesMemoryUsage,
DirectMap4k,
DirectMap2M,
HardwareCorrupted,
TotalHighNotDirectlyMappedIntoKernelSpace,
FreeHighNotDirectlyMappedIntoKernelSpace,
TotalLowDirectlyMappedIntoKernelSpace,
FreeLowDirectlyMappedIntoKernelSpace,
ShmemHugePageUsage,
ShmemMemoryMappedIntoUserSpaceUsingHugePages,
Unknown(String),
}
impl MemoryStatisticName
{
#[inline(always)]
pub fn parse(value: &str, memoryStatisticNamePrefix: &str) -> MemoryStatisticName
{
if !value.starts_with(memoryStatisticNamePrefix)
{
return MemoryStatisticName::Unknown(value.to_owned());
}
match &value[memoryStatisticNamePrefix.len()..]
{
"MemTotal" => MemoryStatisticName::TotalPhyiscalRam,
"MemFree" => MemoryStatisticName::FreePhysicalRam,
"MemAvailable" => MemoryStatisticName::AvailablePhysicalRam,
"Buffers" => MemoryStatisticName::UsedAsFileBuffersPhysicalRam,
"Cached" => MemoryStatisticName::UsedAsCachePhysicalRam,
"SwapTotal" => MemoryStatisticName::TotalSwap,
"SwapFree" => MemoryStatisticName::FreeSwap,
"SwapCached" => MemoryStatisticName::UsedAsCacheSwap,
"Active" => MemoryStatisticName::ActiveFileBufferAndCacheInUse,
"Inactive" => MemoryStatisticName::InactiveFileBufferAndCacheAvailable,
"Active(anon" => MemoryStatisticName::AnonymousActive,
"Inactive(anon" => MemoryStatisticName::AnonymousInactive,
"Active(file" => MemoryStatisticName::FileActive,
"Inactive(file" => MemoryStatisticName::FileInactive,
"Unevictable" => MemoryStatisticName::Unevictable,
"Dirty" => MemoryStatisticName::WaitingToBeWrittenBackToDisks,
"Writeback" => MemoryStatisticName::CurrentlyBeingWrittenBackToDisks,
"Bounce" => MemoryStatisticName::UsedForBlockDeviceBounceBuffers,
"NFS_Unstable" => MemoryStatisticName::NetworkFileSystemUnstablePagesSentToServerButNotYetCommitedToStableStorage,
"WritebackTmp" => MemoryStatisticName::MemoryUsedByFuseForTemporaryWritebackBuffers,
"AnonPages" => MemoryStatisticName::AnononymousMemoryMappedUsingMmap,
"Mapped" => MemoryStatisticName::FilesMappedUsingMmap,
"Shmem" => MemoryStatisticName::Shmem,
"Mlocked" => MemoryStatisticName::LockedByMlock,
"Slab" => MemoryStatisticName::Slab,
"SReclaimable" => MemoryStatisticName::SlabReclaimable,
"SUnreclaim" => MemoryStatisticName::SlabUnreclaimable,
"KernelStack" => MemoryStatisticName::KernelStack,
"PageTables" => MemoryStatisticName::MemoryDedicatedToLowestPageTableLevel,
"CommitLimit" => MemoryStatisticName::CommitLimit,
"Committed_AS" => MemoryStatisticName::WorstCaseScenarioMemoryRequiredToCompleteWorkloadIncludingSwapMemory,
"VmallocTotal" => MemoryStatisticName::TotalVirtualAddressSpaceEgByMalloc,
"VmallocUsed" => MemoryStatisticName::UsedVirtualAddressSpaceEgByMalloc,
"VmallocChunk" => MemoryStatisticName::LarestContiguousChunkInVirtualAddressSpaceEgByMalloc,
"HugePages_Total" => MemoryStatisticName::TotalNumberOfHugePages,
"HugePages_Free" => MemoryStatisticName::FreeNumberOfHugePages,
"HugePages_Rsvd" => MemoryStatisticName::ReservedNumberOfHugePages,
"HugePages_Surp" => MemoryStatisticName::SurplusNumberOfHugesPages,
"Hugepagesize" => MemoryStatisticName::SizeOfAHugePage,
"AnonHugePages" => MemoryStatisticName::TransparentHugePagesMemoryUsage,
"DirectMap4k" => MemoryStatisticName::DirectMap4k,
"DirectMap2M" => MemoryStatisticName::DirectMap2M,
"HardwareCorrupted" => MemoryStatisticName::HardwareCorrupted,
"HighTotal" => MemoryStatisticName::TotalHighNotDirectlyMappedIntoKernelSpace,
"HighFree" => MemoryStatisticName::FreeHighNotDirectlyMappedIntoKernelSpace,
"LowTotal" => MemoryStatisticName::TotalLowDirectlyMappedIntoKernelSpace,
"LowFree" => MemoryStatisticName::FreeLowDirectlyMappedIntoKernelSpace,
"ShmemHugePages" => MemoryStatisticName::ShmemHugePageUsage,
"ShmemPmdMapped" => MemoryStatisticName::ShmemMemoryMappedIntoUserSpaceUsingHugePages,
name @ _ => MemoryStatisticName::Unknown(name.to_owned()),
}
}
#[inline(always)]
pub fn isDeprecatedOrNotUnderstood(&self) -> bool
{
match *self
{
MemoryStatisticName::HardwareCorrupted => true,
MemoryStatisticName::TotalHighNotDirectlyMappedIntoKernelSpace => true,
MemoryStatisticName::FreeHighNotDirectlyMappedIntoKernelSpace => true,
MemoryStatisticName::TotalLowDirectlyMappedIntoKernelSpace => true,
MemoryStatisticName::FreeLowDirectlyMappedIntoKernelSpace => true,
MemoryStatisticName::ShmemHugePageUsage => true,
MemoryStatisticName::ShmemMemoryMappedIntoUserSpaceUsingHugePages => true,
_ => false,
}
}
#[inline(always)]
pub fn unit(&self) -> MemoryStatisticUnit
{
match *self
{
MemoryStatisticName::TotalNumberOfHugePages => MemoryStatisticUnit::Count,
MemoryStatisticName::FreeNumberOfHugePages => MemoryStatisticUnit::Count,
MemoryStatisticName::ReservedNumberOfHugePages => MemoryStatisticUnit::Count,
MemoryStatisticName::SurplusNumberOfHugesPages => MemoryStatisticUnit::Count,
_ => MemoryStatisticUnit::KiloByte,
}
}
}