Function cache_size

Source
pub fn cache_size(level: u8, cache_type: CacheType) -> Option<usize>
Expand description

Returns the total size in bytes of level cache with type cache_type.

The only possibilities for this returning None are if the system does not support cache parameters, in which case get_cache_parameters() will fail, or if the selected cache level and/or type does not exist.

On an AMD Zen architecture this is computed using tlb info. The values come back in kilobytes, so they are multiplied by 1024 to give the size in bytes to match the behaviour of other architectures.

On other architectures this is computed as associativity * line_size * sets, and if there are multiple caches available, it returns the size of the smallest cache.