diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/include/sys/vmstat.h | 2 | ||||
-rw-r--r-- | sys/include/vm/physmem.h | 1 | ||||
-rw-r--r-- | sys/vm/vm_physmem.c | 12 | ||||
-rw-r--r-- | sys/vm/vm_stat.c | 1 |
4 files changed, 16 insertions, 0 deletions
diff --git a/sys/include/sys/vmstat.h b/sys/include/sys/vmstat.h index 127bc96..b7faeb2 100644 --- a/sys/include/sys/vmstat.h +++ b/sys/include/sys/vmstat.h @@ -37,10 +37,12 @@ * * @mem_avail: Available memory in MiB * @mem_used: Allocated memory in MiB + * @mem_total: Total system memory in MiB */ struct vm_stat { uint32_t mem_avail; uint32_t mem_used; + size_t mem_total; }; #endif /* !_VM_STAT_H_ */ diff --git a/sys/include/vm/physmem.h b/sys/include/vm/physmem.h index e16bcf9..3f1da61 100644 --- a/sys/include/vm/physmem.h +++ b/sys/include/vm/physmem.h @@ -34,6 +34,7 @@ uint32_t vm_mem_used(void); uint32_t vm_mem_free(void); +size_t vm_mem_total(void); void vm_physmem_init(void); uintptr_t vm_alloc_frame(size_t count); 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; } |