#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub enum MemoryInformationName
{
TotalPhysicalRam,
FreePhysicalRam,
AvailablePhysicalRam,
UsedAsFileBuffersPhysicalRam,
UsedAsCachePhysicalRam,
TotalSwap,
FreeSwap,
LazyFree,
UsedAsCacheSwap,
ActiveFileBufferAndCacheInUse,
InactiveFileBufferAndCacheAvailable,
AnonymousActive,
AnonymousInactive,
FileActive,
FileInactive,
Unevictable,
WaitingToBeWrittenBackToDisks,
CurrentlyBeingWrittenBackToDisks,
UsedForBlockDeviceBounceBuffers,
NetworkFileSystemUnstablePagesSentToServerButNotYetCommittedToStableStorage,
MemoryUsedByFuseForTemporaryWritebackBuffers,
AnonymousMemoryMappedUsingMmap,
FilesMappedUsingMmap,
Shmem,
LockedByMlock,
Slab,
SlabReclaimable,
SlabUnreclaimable,
KReclaimable,
KernelStack,
MemoryDedicatedToLowestPageTableLevel,
CommitLimit,
WorstCaseScenarioMemoryRequiredToCompleteWorkloadIncludingSwapMemory,
TotalVirtualAddressSpace,
UsedVirtualAddressSpace,
LargestContiguousChunkInVirtualAddressSpace,
TotalNumberOfHugePages,
FreeNumberOfHugePages,
ReservedNumberOfHugePages,
SurplusNumberOfHugePages,
SizeOfDefaultHugePage,
TransparentHugePagesMemoryUsage,
ShmemHugePageUsage,
ShmemMemoryMappedIntoUserSpaceUsingHugePages,
DirectMap4k,
DirectMap2M,
DirectMap1G,
HardwareCorrupted,
FileHugePageUsage,
TotalHighNotDirectlyMappedIntoKernelSpace,
FreeHighNotDirectlyMappedIntoKernelSpace,
TotalLowDirectlyMappedIntoKernelSpace,
FreeLowDirectlyMappedIntoKernelSpace,
MMapCopy,
Quicklists,
ContiguousMemoryAllocatorTotal,
ContiguousMemoryAllocatorFree,
Unknown(Box<[u8]>),
}
impl MemoryInformationName
{
#[inline(always)]
pub(crate) fn parse(value: &[u8], memory_information_name_prefix: &[u8]) -> MemoryInformationName
{
use self::MemoryInformationName::*;
if !value.starts_with(memory_information_name_prefix)
{
return Unknown(value.to_vec().into_boxed_slice())
}
match &value[memory_information_name_prefix.len() .. ]
{
b"MemTotal" => TotalPhysicalRam,
b"MemFree" => FreePhysicalRam,
b"MemAvailable" => AvailablePhysicalRam,
b"Buffers" => UsedAsFileBuffersPhysicalRam,
b"Cached" => UsedAsCachePhysicalRam,
b"SwapTotal" => TotalSwap,
b"SwapFree" => FreeSwap,
b"SwapCached" => UsedAsCacheSwap,
b"LazyFree" => LazyFree,
b"Active" => ActiveFileBufferAndCacheInUse,
b"Inactive" => InactiveFileBufferAndCacheAvailable,
b"Active(anon)" => AnonymousActive,
b"Inactive(anon)" => AnonymousInactive,
b"Active(file)" => FileActive,
b"Inactive(file)" => FileInactive,
b"Unevictable" => Unevictable,
b"Dirty" => WaitingToBeWrittenBackToDisks,
b"Writeback" => CurrentlyBeingWrittenBackToDisks,
b"Bounce" => UsedForBlockDeviceBounceBuffers,
b"NFS_Unstable" => NetworkFileSystemUnstablePagesSentToServerButNotYetCommittedToStableStorage,
b"WritebackTmp" => MemoryUsedByFuseForTemporaryWritebackBuffers,
b"AnonPages" => AnonymousMemoryMappedUsingMmap,
b"Mapped" => FilesMappedUsingMmap,
b"Shmem" => Shmem,
b"Mlocked" => LockedByMlock,
b"Slab" => Slab,
b"SReclaimable" => SlabReclaimable,
b"SUnreclaim" => SlabUnreclaimable,
b"KernelStack" => KernelStack,
b"PageTables" => MemoryDedicatedToLowestPageTableLevel,
b"CommitLimit" => CommitLimit,
b"Committed_AS" => WorstCaseScenarioMemoryRequiredToCompleteWorkloadIncludingSwapMemory,
b"VmallocTotal" => TotalVirtualAddressSpace,
b"VmallocUsed" => UsedVirtualAddressSpace,
b"VmallocChunk" => LargestContiguousChunkInVirtualAddressSpace,
b"HugePages_Total" => TotalNumberOfHugePages,
b"HugePages_Free" => FreeNumberOfHugePages,
b"HugePages_Rsvd" => ReservedNumberOfHugePages,
b"HugePages_Surp" => SurplusNumberOfHugePages,
b"Hugepagesize" => SizeOfDefaultHugePage,
b"AnonHugePages" => TransparentHugePagesMemoryUsage,
b"ShmemHugePages" => ShmemHugePageUsage,
b"FileHugePages" => FileHugePageUsage,
b"ShmemPmdMapped" => ShmemMemoryMappedIntoUserSpaceUsingHugePages,
b"DirectMap4k" => DirectMap4k,
b"DirectMap2M" => DirectMap2M,
b"DirectMap1G" => DirectMap1G,
b"HardwareCorrupted" => HardwareCorrupted,
b"HighTotal" => TotalHighNotDirectlyMappedIntoKernelSpace,
b"HighFree" => FreeHighNotDirectlyMappedIntoKernelSpace,
b"LowTotal" => TotalLowDirectlyMappedIntoKernelSpace,
b"LowFree" => FreeLowDirectlyMappedIntoKernelSpace,
b"MmapCopy" => MMapCopy,
b"Quicklists" => Quicklists,
b"CmaTotal" => ContiguousMemoryAllocatorTotal,
b"CmaFree" => ContiguousMemoryAllocatorFree,
name @ _ => Unknown(name.to_vec().into_boxed_slice()),
}
}
#[inline(always)]
pub fn unit(&self) -> MemoryInformationUnit
{
use self::MemoryInformationName::*;
use self::MemoryInformationUnit::*;
match *self
{
TotalNumberOfHugePages => Count,
FreeNumberOfHugePages => Count,
ReservedNumberOfHugePages => Count,
SurplusNumberOfHugePages => Count,
ContiguousMemoryAllocatorTotal => Count,
ContiguousMemoryAllocatorFree => Count,
_ => Kilobyte,
}
}
#[inline(always)]
pub(crate) fn validate_unit<'a>(&self, bytes: &'a [u8], zero_based_line_number: usize) -> Result<&'a [u8], MemoryInformationParseError>
{
let ends_with = self.unit().ends_with();
if likely!(bytes.ends_with(ends_with))
{
Ok(&bytes[0 .. bytes.len() - ends_with.len()])
}
else
{
Err(MemoryInformationParseError::InvalidUnit { zero_based_line_number })
}
}
}