diff options
author | Ian Moffett <ian@osmora.org> | 2024-05-23 03:21:16 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-05-23 03:21:16 -0400 |
commit | 103f3e8ca854c5ee83e2d5525d574d10964b583a (patch) | |
tree | 475f79ce2d671ce8536c5ab6fb182384661a2c8c /sys | |
parent | a6b64a1d8c6cdadece333edfcb0589d0711b5a58 (diff) |
kernel: vm: Add alloc and avl stats
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r-- | sys/include/vm/physseg.h | 2 | ||||
-rw-r--r-- | sys/vm/vm_physseg.c | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/sys/include/vm/physseg.h b/sys/include/vm/physseg.h index af8cae8..956f82f 100644 --- a/sys/include/vm/physseg.h +++ b/sys/include/vm/physseg.h @@ -35,6 +35,8 @@ struct physmem_stat { size_t reserved_kib; /* Reserved memory */ size_t total_kib; /* Total memory */ + size_t avl_kib; /* Available memory */ + size_t alloc_kib; /* Allocated physical memory */ }; void vm_physseg_init(void); diff --git a/sys/vm/vm_physseg.c b/sys/vm/vm_physseg.c index 6b803c2..88560e5 100644 --- a/sys/vm/vm_physseg.c +++ b/sys/vm/vm_physseg.c @@ -70,6 +70,7 @@ static bitmap_t bitmap = NULL; static size_t pages_total = 0; static size_t pages_reserved = 0; static size_t last_used_idx = 0; +static size_t pages_allocated = 0; static size_t bitmap_size = 0; static size_t highest_frame_idx; static size_t bitmap_free_start; /* Beginning bit of free region */ @@ -220,6 +221,7 @@ vm_alloc_pageframe(size_t count) for (size_t i = tmp; i < last_used_idx; ++i) bitmap_set_bit(bitmap, i); + pages_allocated += count; return tmp * vm_get_page_size(); } else { pages = 0; @@ -243,6 +245,8 @@ vm_free_pageframe(uintptr_t base, size_t count) for (uintptr_t p = base; p < base + (count*PAGE_SIZE); p += PAGE_SIZE) { bitmap_unset_bit(bitmap, p/0x1000); } + + pages_allocated -= count; } void @@ -262,5 +266,7 @@ vm_phys_memstat(void) vm_physseg_getstat(); stat.total_kib = (pages_total * pagesize) / 1024; stat.reserved_kib = (pages_reserved * pagesize) / 1024; + stat.alloc_kib = (pages_allocated * pagesize) / 1024; + stat.avl_kib = stat.total_kib - stat.alloc_kib; return stat; } |