refactored and documented showmem into expe000

This commit is contained in:
Guillaume Raffy 2024-08-13 17:24:19 +02:00
parent 6d7d5b9586
commit b6af10d3a4
4 changed files with 52 additions and 20 deletions

View File

@ -0,0 +1,15 @@
This experimentation explores how meminfo's MemAvailable is computed, via an attempt to replicate code used in linux ([file://../../reference/show_mem.c])
```sh
20240813-16:48:45 graffy@graffy-ws2:~/work/linuxram.git$ ./src/memavail.py
{'MemTotal': 201214205952, 'MemFree': 803061760, 'MemAvailable': 131466833920, 'Buffers': 31981568, 'Cached': 130939863040, 'SwapCached': 1088724992, 'Active': 103304773632, 'Inactive': 94177337344, 'Active(anon)': 39671312384, 'Inactive(anon)': 26918952960, 'Active(file)': 63633461248, 'Inactive(file)': 67258384384, 'Unevictable': 23019520, 'Mlocked': 19873792, 'SwapTotal': 32765898752, 'SwapFree': 0, 'Zswap': 0, 'Zswapped': 0, 'Dirty': 8546779136, 'Writeback': 5550080, 'AnonPages': 65442127872, 'Mapped': 120565760, 'Shmem': 69955584, 'KReclaimable': 1252827136, 'Slab': 1991671808, 'SReclaimable': 1252827136, 'SUnreclaim': 738844672, 'KernelStack': 17088512, 'PageTables': 218902528, 'SecPageTables': 0, 'NFS_Unstable': 0, 'Bounce': 0, 'WritebackTmp': 0, 'CommitLimit': 133373001728, 'Committed_AS': 141631254528, 'VmallocTotal': 35184372087808, 'VmallocUsed': 302333952, 'VmallocChunk': 0, 'Percpu': 215089152, 'HardwareCorrupted': 53248, 'AnonHugePages': 49218060288, 'ShmemHugePages': 0, 'ShmemPmdMapped': 0, 'FileHugePages': 0, 'FilePmdMapped': 0, 'Hugepagesize': 2097152, 'Hugetlb': 0, 'DirectMap4k': 554131456, 'DirectMap2M': 6434062336, 'DirectMap1G': 199715979264}
0: {'DMA': 4, 'DMA32': 529, 'Normal': 34991, 'Movable': 0, 'Device': 0}1: {'DMA': 0, 'DMA32': 0, 'Normal': 36110, 'Movable': 0, 'Device': 0}2: {}
free memory : 784240.0 KiB
cache memory : 127537532.0 KiB
reclaimable memory : 2160392.0 KiB
meminfo's MemAvailable : 128385580.0 KiB
computed available memory : 128691460.0 KiB
computed - meminfo = 305880.0 KiB (76470.0 pages)
last command status : [0]
```

View File

@ -5,4 +5,4 @@ from .linuxmem import read_meminfo_stdout # noqa
from .linuxmem import meminfo_diff # noqa
from .linuxmem import find_diff # noqa
from .linuxmem import get_stabilized_meminfo # noqa
from .linuxmem import compute_mem_avail # noqa

View File

@ -4,7 +4,6 @@ import re
from pathlib import Path
import subprocess
import time
# code to userstand how meminfo's MemAvailable is computed
MeminfoVarId = str
MemUnit = int # in bytes
@ -224,7 +223,8 @@ def estimate_mem_available(meminfo_data: Dict[MeminfoVarId, MemUnit], zoneinfo_d
return num_available_pages * page_size
def show_memory_state(meminfo_stdout_file_path: Path, grepped_zoneinfo_file_path: Path):
def compute_mem_avail(meminfo_stdout_file_path: Path, grepped_zoneinfo_file_path: Path):
# code to userstand how meminfo's MemAvailable is computed
meminfo_data = read_meminfo_stdout(meminfo_stdout_file_path)
print(meminfo_data)
@ -235,20 +235,3 @@ def show_memory_state(meminfo_stdout_file_path: Path, grepped_zoneinfo_file_path
assert meminfo_data['Active'] == (meminfo_data['Active(file)'] + meminfo_data['Active(anon)'])
assert meminfo_data['Inactive'] == (meminfo_data['Inactive(file)'] + meminfo_data['Inactive(anon)'])
def main():
set_id = 'stressed_alambix97'
# set_id = 'validation_alambix98'
if set_id == 'stressed_alambix97':
meminfo_stdout_file_path = Path('/home/graffy/work/tickets/bug3897/alambix97/20240805-191606-meminfo.stdout')
grepped_zoneinfo_file_path = Path('/home/graffy/work/tickets/bug3897/alambix98/20240806-202043-grepped-zoneinfo.stdout') # I didn't have a chance to get zone infor before it crashed so I used another measure, hoping that zoneinfo is minimal
elif set_id == 'validation_alambix98':
meminfo_stdout_file_path = Path('/home/graffy/work/tickets/bug3897/alambix98/20240806-223916-meminfo.stdout')
grepped_zoneinfo_file_path = Path('/home/graffy/work/tickets/bug3897/alambix98/20240806-223916-grepped-zoneinfo.stdout')
show_memory_state(meminfo_stdout_file_path, grepped_zoneinfo_file_path)
main()

34
src/memavail.py Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""
code to userstand how meminfo's MemAvailable is computed
how to use:
```sh
20240813-16:43:33 graffy@graffy-ws2:~/work/linuxram.git$ export LINUXRAM_ROOT=$(pwd)
20240813-16:48:20 graffy@graffy-ws2:~/work/linuxram.git$ ./src/test_tmpfs.py
```
"""
from pathlib import Path
import os
from linuxmem import compute_mem_avail
def main():
set_id = 'stressed_alambix97'
# set_id = 'validation_alambix98'
linuxram_root_dir = Path(os.getenv('LINUXRAM_ROOT'))
if set_id == 'stressed_alambix97':
meminfo_stdout_file_path = linuxram_root_dir / 'measurements/bug3897/alambix97/20240805-191606-meminfo.stdout'
grepped_zoneinfo_file_path = linuxram_root_dir / 'measurements/bug3897/alambix98/20240806-202043-grepped-zoneinfo.stdout' # I didn't have a chance to get zone info before it crashed so I used another measure, hoping that zoneinfo is minimal
elif set_id == 'validation_alambix98':
meminfo_stdout_file_path = linuxram_root_dir / 'measurements/alambix98/20240806-223916-meminfo.stdout'
grepped_zoneinfo_file_path = linuxram_root_dir / 'measurements/bug3897/alambix98/20240806-223916-grepped-zoneinfo.stdout'
compute_mem_avail(meminfo_stdout_file_path, grepped_zoneinfo_file_path)
main()