From 9a652bf4cfc943a5a59d23ea19c1efb202af5286 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 12 Aug 2025 21:49:20 -0400 Subject: kernel: vm: Add total system memory in vmstat This commit introduces reporting of total system memory supported through the vmstat subsystem Signed-off-by: Ian Moffett --- sys/vm/vm_physmem.c | 12 ++++++++++++ sys/vm/vm_stat.c | 1 + 2 files changed, 13 insertions(+) (limited to 'sys/vm') diff --git a/sys/vm/vm_physmem.c b/sys/vm/vm_physmem.c index debec1f..b6e7347 100644 --- a/sys/vm/vm_physmem.c +++ b/sys/vm/vm_physmem.c @@ -40,6 +40,7 @@ static size_t pages_free = 0; static size_t pages_used = 0; +static size_t pages_total = 0; static size_t highest_frame_idx = 0; static size_t bitmap_size = 0; static size_t bitmap_free_start = 0; @@ -64,6 +65,7 @@ physmem_populate_bitmap(void) for (size_t i = 0; i < resp->entry_count; ++i) { ent = resp->entries[i]; + pages_total += ent->length / DEFAULT_PAGESIZE; if (ent->type != LIMINE_MEMMAP_USABLE) { /* This memory is not usable */ @@ -230,6 +232,16 @@ vm_mem_free(void) return (pages_free * DEFAULT_PAGESIZE) / BYTES_PER_MIB; } +/* + * Return the total amount of memory supported + * by the machine. + */ +size_t +vm_mem_total(void) +{ + return (pages_total * DEFAULT_PAGESIZE) / BYTES_PER_MIB; +} + void vm_physmem_init(void) { diff --git a/sys/vm/vm_stat.c b/sys/vm/vm_stat.c index 8cf2fe4..3e39047 100644 --- a/sys/vm/vm_stat.c +++ b/sys/vm/vm_stat.c @@ -71,6 +71,7 @@ vm_stat_get(struct vm_stat *vmstat) vmstat->mem_avail = vm_mem_free(); vmstat->mem_used = vm_mem_used(); + vmstat->mem_total = vm_mem_total(); return 0; } -- cgit v1.2.3