| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 1 | // Copyright 2019 The Prometheus Authors |
| 2 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | // you may not use this file except in compliance with the License. |
| 4 | // You may obtain a copy of the License at |
| 5 | // |
| 6 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | // |
| 8 | // Unless required by applicable law or agreed to in writing, software |
| 9 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | // See the License for the specific language governing permissions and |
| 12 | // limitations under the License. |
| 13 | |
| 14 | package procfs |
| 15 | |
| 16 | import ( |
| 17 | "bufio" |
| 18 | "bytes" |
| 19 | "fmt" |
| 20 | "io" |
| 21 | "strconv" |
| 22 | "strings" |
| 23 | |
| 24 | "github.com/prometheus/procfs/internal/util" |
| 25 | ) |
| 26 | |
| 27 | // Meminfo represents memory statistics. |
| 28 | type Meminfo struct { |
| 29 | // Total usable ram (i.e. physical ram minus a few reserved |
| 30 | // bits and the kernel binary code) |
| 31 | MemTotal *uint64 |
| 32 | // The sum of LowFree+HighFree |
| 33 | MemFree *uint64 |
| 34 | // An estimate of how much memory is available for starting |
| 35 | // new applications, without swapping. Calculated from |
| 36 | // MemFree, SReclaimable, the size of the file LRU lists, and |
| 37 | // the low watermarks in each zone. The estimate takes into |
| 38 | // account that the system needs some page cache to function |
| 39 | // well, and that not all reclaimable slab will be |
| 40 | // reclaimable, due to items being in use. The impact of those |
| 41 | // factors will vary from system to system. |
| 42 | MemAvailable *uint64 |
| 43 | // Relatively temporary storage for raw disk blocks shouldn't |
| 44 | // get tremendously large (20MB or so) |
| 45 | Buffers *uint64 |
| 46 | Cached *uint64 |
| 47 | // Memory that once was swapped out, is swapped back in but |
| 48 | // still also is in the swapfile (if memory is needed it |
| 49 | // doesn't need to be swapped out AGAIN because it is already |
| 50 | // in the swapfile. This saves I/O) |
| 51 | SwapCached *uint64 |
| 52 | // Memory that has been used more recently and usually not |
| 53 | // reclaimed unless absolutely necessary. |
| 54 | Active *uint64 |
| 55 | // Memory which has been less recently used. It is more |
| 56 | // eligible to be reclaimed for other purposes |
| 57 | Inactive *uint64 |
| 58 | ActiveAnon *uint64 |
| 59 | InactiveAnon *uint64 |
| 60 | ActiveFile *uint64 |
| 61 | InactiveFile *uint64 |
| 62 | Unevictable *uint64 |
| 63 | Mlocked *uint64 |
| 64 | // total amount of swap space available |
| 65 | SwapTotal *uint64 |
| 66 | // Memory which has been evicted from RAM, and is temporarily |
| 67 | // on the disk |
| 68 | SwapFree *uint64 |
| 69 | // Memory which is waiting to get written back to the disk |
| 70 | Dirty *uint64 |
| 71 | // Memory which is actively being written back to the disk |
| 72 | Writeback *uint64 |
| 73 | // Non-file backed pages mapped into userspace page tables |
| 74 | AnonPages *uint64 |
| 75 | // files which have been mapped, such as libraries |
| 76 | Mapped *uint64 |
| 77 | Shmem *uint64 |
| 78 | // in-kernel data structures cache |
| 79 | Slab *uint64 |
| 80 | // Part of Slab, that might be reclaimed, such as caches |
| 81 | SReclaimable *uint64 |
| 82 | // Part of Slab, that cannot be reclaimed on memory pressure |
| 83 | SUnreclaim *uint64 |
| 84 | KernelStack *uint64 |
| 85 | // amount of memory dedicated to the lowest level of page |
| 86 | // tables. |
| 87 | PageTables *uint64 |
| 88 | // NFS pages sent to the server, but not yet committed to |
| 89 | // stable storage |
| 90 | NFSUnstable *uint64 |
| 91 | // Memory used for block device "bounce buffers" |
| 92 | Bounce *uint64 |
| 93 | // Memory used by FUSE for temporary writeback buffers |
| 94 | WritebackTmp *uint64 |
| 95 | // Based on the overcommit ratio ('vm.overcommit_ratio'), |
| 96 | // this is the total amount of memory currently available to |
| 97 | // be allocated on the system. This limit is only adhered to |
| 98 | // if strict overcommit accounting is enabled (mode 2 in |
| 99 | // 'vm.overcommit_memory'). |
| 100 | // The CommitLimit is calculated with the following formula: |
| 101 | // CommitLimit = ([total RAM pages] - [total huge TLB pages]) * |
| 102 | // overcommit_ratio / 100 + [total swap pages] |
| 103 | // For example, on a system with 1G of physical RAM and 7G |
| 104 | // of swap with a `vm.overcommit_ratio` of 30 it would |
| 105 | // yield a CommitLimit of 7.3G. |
| 106 | // For more details, see the memory overcommit documentation |
| 107 | // in vm/overcommit-accounting. |
| 108 | CommitLimit *uint64 |
| 109 | // The amount of memory presently allocated on the system. |
| 110 | // The committed memory is a sum of all of the memory which |
| 111 | // has been allocated by processes, even if it has not been |
| 112 | // "used" by them as of yet. A process which malloc()'s 1G |
| 113 | // of memory, but only touches 300M of it will show up as |
| 114 | // using 1G. This 1G is memory which has been "committed" to |
| 115 | // by the VM and can be used at any time by the allocating |
| 116 | // application. With strict overcommit enabled on the system |
| 117 | // (mode 2 in 'vm.overcommit_memory'),allocations which would |
| 118 | // exceed the CommitLimit (detailed above) will not be permitted. |
| 119 | // This is useful if one needs to guarantee that processes will |
| 120 | // not fail due to lack of memory once that memory has been |
| 121 | // successfully allocated. |
| 122 | CommittedAS *uint64 |
| 123 | // total size of vmalloc memory area |
| 124 | VmallocTotal *uint64 |
| 125 | // amount of vmalloc area which is used |
| 126 | VmallocUsed *uint64 |
| 127 | // largest contiguous block of vmalloc area which is free |
| 128 | VmallocChunk *uint64 |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 129 | Percpu *uint64 |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 130 | HardwareCorrupted *uint64 |
| 131 | AnonHugePages *uint64 |
| 132 | ShmemHugePages *uint64 |
| 133 | ShmemPmdMapped *uint64 |
| 134 | CmaTotal *uint64 |
| 135 | CmaFree *uint64 |
| 136 | HugePagesTotal *uint64 |
| 137 | HugePagesFree *uint64 |
| 138 | HugePagesRsvd *uint64 |
| 139 | HugePagesSurp *uint64 |
| 140 | Hugepagesize *uint64 |
| 141 | DirectMap4k *uint64 |
| 142 | DirectMap2M *uint64 |
| 143 | DirectMap1G *uint64 |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 144 | |
| 145 | // The struct fields below are the byte-normalized counterparts to the |
| 146 | // existing struct fields. Values are normalized using the optional |
| 147 | // unit field in the meminfo line. |
| 148 | MemTotalBytes *uint64 |
| 149 | MemFreeBytes *uint64 |
| 150 | MemAvailableBytes *uint64 |
| 151 | BuffersBytes *uint64 |
| 152 | CachedBytes *uint64 |
| 153 | SwapCachedBytes *uint64 |
| 154 | ActiveBytes *uint64 |
| 155 | InactiveBytes *uint64 |
| 156 | ActiveAnonBytes *uint64 |
| 157 | InactiveAnonBytes *uint64 |
| 158 | ActiveFileBytes *uint64 |
| 159 | InactiveFileBytes *uint64 |
| 160 | UnevictableBytes *uint64 |
| 161 | MlockedBytes *uint64 |
| 162 | SwapTotalBytes *uint64 |
| 163 | SwapFreeBytes *uint64 |
| 164 | DirtyBytes *uint64 |
| 165 | WritebackBytes *uint64 |
| 166 | AnonPagesBytes *uint64 |
| 167 | MappedBytes *uint64 |
| 168 | ShmemBytes *uint64 |
| 169 | SlabBytes *uint64 |
| 170 | SReclaimableBytes *uint64 |
| 171 | SUnreclaimBytes *uint64 |
| 172 | KernelStackBytes *uint64 |
| 173 | PageTablesBytes *uint64 |
| 174 | NFSUnstableBytes *uint64 |
| 175 | BounceBytes *uint64 |
| 176 | WritebackTmpBytes *uint64 |
| 177 | CommitLimitBytes *uint64 |
| 178 | CommittedASBytes *uint64 |
| 179 | VmallocTotalBytes *uint64 |
| 180 | VmallocUsedBytes *uint64 |
| 181 | VmallocChunkBytes *uint64 |
| 182 | PercpuBytes *uint64 |
| 183 | HardwareCorruptedBytes *uint64 |
| 184 | AnonHugePagesBytes *uint64 |
| 185 | ShmemHugePagesBytes *uint64 |
| 186 | ShmemPmdMappedBytes *uint64 |
| 187 | CmaTotalBytes *uint64 |
| 188 | CmaFreeBytes *uint64 |
| 189 | HugepagesizeBytes *uint64 |
| 190 | DirectMap4kBytes *uint64 |
| 191 | DirectMap2MBytes *uint64 |
| 192 | DirectMap1GBytes *uint64 |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // Meminfo returns an information about current kernel/system memory statistics. |
| 196 | // See https://www.kernel.org/doc/Documentation/filesystems/proc.txt |
| 197 | func (fs FS) Meminfo() (Meminfo, error) { |
| 198 | b, err := util.ReadFileNoStat(fs.proc.Path("meminfo")) |
| 199 | if err != nil { |
| 200 | return Meminfo{}, err |
| 201 | } |
| 202 | |
| 203 | m, err := parseMemInfo(bytes.NewReader(b)) |
| 204 | if err != nil { |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 205 | return Meminfo{}, fmt.Errorf("%w: %w", ErrFileParse, err) |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | return *m, nil |
| 209 | } |
| 210 | |
| 211 | func parseMemInfo(r io.Reader) (*Meminfo, error) { |
| 212 | var m Meminfo |
| 213 | s := bufio.NewScanner(r) |
| 214 | for s.Scan() { |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 215 | fields := strings.Fields(s.Text()) |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 216 | var val, valBytes uint64 |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 217 | |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 218 | val, err := strconv.ParseUint(fields[1], 0, 64) |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 219 | if err != nil { |
| 220 | return nil, err |
| 221 | } |
| 222 | |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 223 | switch len(fields) { |
| 224 | case 2: |
| 225 | // No unit present, use the parsed the value as bytes directly. |
| 226 | valBytes = val |
| 227 | case 3: |
| 228 | // Unit present in optional 3rd field, convert it to |
| 229 | // bytes. The only unit supported within the Linux |
| 230 | // kernel is `kB`. |
| 231 | if fields[2] != "kB" { |
| 232 | return nil, fmt.Errorf("%w: Unsupported unit in optional 3rd field %q", ErrFileParse, fields[2]) |
| 233 | } |
| 234 | |
| 235 | valBytes = 1024 * val |
| 236 | |
| 237 | default: |
| 238 | return nil, fmt.Errorf("%w: Malformed line %q", ErrFileParse, s.Text()) |
| 239 | } |
| 240 | |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 241 | switch fields[0] { |
| 242 | case "MemTotal:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 243 | m.MemTotal = &val |
| 244 | m.MemTotalBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 245 | case "MemFree:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 246 | m.MemFree = &val |
| 247 | m.MemFreeBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 248 | case "MemAvailable:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 249 | m.MemAvailable = &val |
| 250 | m.MemAvailableBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 251 | case "Buffers:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 252 | m.Buffers = &val |
| 253 | m.BuffersBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 254 | case "Cached:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 255 | m.Cached = &val |
| 256 | m.CachedBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 257 | case "SwapCached:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 258 | m.SwapCached = &val |
| 259 | m.SwapCachedBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 260 | case "Active:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 261 | m.Active = &val |
| 262 | m.ActiveBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 263 | case "Inactive:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 264 | m.Inactive = &val |
| 265 | m.InactiveBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 266 | case "Active(anon):": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 267 | m.ActiveAnon = &val |
| 268 | m.ActiveAnonBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 269 | case "Inactive(anon):": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 270 | m.InactiveAnon = &val |
| 271 | m.InactiveAnonBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 272 | case "Active(file):": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 273 | m.ActiveFile = &val |
| 274 | m.ActiveFileBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 275 | case "Inactive(file):": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 276 | m.InactiveFile = &val |
| 277 | m.InactiveFileBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 278 | case "Unevictable:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 279 | m.Unevictable = &val |
| 280 | m.UnevictableBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 281 | case "Mlocked:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 282 | m.Mlocked = &val |
| 283 | m.MlockedBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 284 | case "SwapTotal:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 285 | m.SwapTotal = &val |
| 286 | m.SwapTotalBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 287 | case "SwapFree:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 288 | m.SwapFree = &val |
| 289 | m.SwapFreeBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 290 | case "Dirty:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 291 | m.Dirty = &val |
| 292 | m.DirtyBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 293 | case "Writeback:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 294 | m.Writeback = &val |
| 295 | m.WritebackBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 296 | case "AnonPages:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 297 | m.AnonPages = &val |
| 298 | m.AnonPagesBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 299 | case "Mapped:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 300 | m.Mapped = &val |
| 301 | m.MappedBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 302 | case "Shmem:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 303 | m.Shmem = &val |
| 304 | m.ShmemBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 305 | case "Slab:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 306 | m.Slab = &val |
| 307 | m.SlabBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 308 | case "SReclaimable:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 309 | m.SReclaimable = &val |
| 310 | m.SReclaimableBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 311 | case "SUnreclaim:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 312 | m.SUnreclaim = &val |
| 313 | m.SUnreclaimBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 314 | case "KernelStack:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 315 | m.KernelStack = &val |
| 316 | m.KernelStackBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 317 | case "PageTables:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 318 | m.PageTables = &val |
| 319 | m.PageTablesBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 320 | case "NFS_Unstable:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 321 | m.NFSUnstable = &val |
| 322 | m.NFSUnstableBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 323 | case "Bounce:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 324 | m.Bounce = &val |
| 325 | m.BounceBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 326 | case "WritebackTmp:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 327 | m.WritebackTmp = &val |
| 328 | m.WritebackTmpBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 329 | case "CommitLimit:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 330 | m.CommitLimit = &val |
| 331 | m.CommitLimitBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 332 | case "Committed_AS:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 333 | m.CommittedAS = &val |
| 334 | m.CommittedASBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 335 | case "VmallocTotal:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 336 | m.VmallocTotal = &val |
| 337 | m.VmallocTotalBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 338 | case "VmallocUsed:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 339 | m.VmallocUsed = &val |
| 340 | m.VmallocUsedBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 341 | case "VmallocChunk:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 342 | m.VmallocChunk = &val |
| 343 | m.VmallocChunkBytes = &valBytes |
| 344 | case "Percpu:": |
| 345 | m.Percpu = &val |
| 346 | m.PercpuBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 347 | case "HardwareCorrupted:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 348 | m.HardwareCorrupted = &val |
| 349 | m.HardwareCorruptedBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 350 | case "AnonHugePages:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 351 | m.AnonHugePages = &val |
| 352 | m.AnonHugePagesBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 353 | case "ShmemHugePages:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 354 | m.ShmemHugePages = &val |
| 355 | m.ShmemHugePagesBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 356 | case "ShmemPmdMapped:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 357 | m.ShmemPmdMapped = &val |
| 358 | m.ShmemPmdMappedBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 359 | case "CmaTotal:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 360 | m.CmaTotal = &val |
| 361 | m.CmaTotalBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 362 | case "CmaFree:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 363 | m.CmaFree = &val |
| 364 | m.CmaFreeBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 365 | case "HugePages_Total:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 366 | m.HugePagesTotal = &val |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 367 | case "HugePages_Free:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 368 | m.HugePagesFree = &val |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 369 | case "HugePages_Rsvd:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 370 | m.HugePagesRsvd = &val |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 371 | case "HugePages_Surp:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 372 | m.HugePagesSurp = &val |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 373 | case "Hugepagesize:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 374 | m.Hugepagesize = &val |
| 375 | m.HugepagesizeBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 376 | case "DirectMap4k:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 377 | m.DirectMap4k = &val |
| 378 | m.DirectMap4kBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 379 | case "DirectMap2M:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 380 | m.DirectMap2M = &val |
| 381 | m.DirectMap2MBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 382 | case "DirectMap1G:": |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 383 | m.DirectMap1G = &val |
| 384 | m.DirectMap1GBytes = &valBytes |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | return &m, nil |
| 389 | } |