summaryrefslogtreecommitdiff
path: root/sys/vm/vm_physmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/vm/vm_physmem.c')
-rw-r--r--sys/vm/vm_physmem.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/sys/vm/vm_physmem.c b/sys/vm/vm_physmem.c
index 89f9ee6..b6e7347 100644
--- a/sys/vm/vm_physmem.c
+++ b/sys/vm/vm_physmem.c
@@ -36,6 +36,11 @@
#include <vm/vm.h>
#include <string.h>
+#define BYTES_PER_MIB 8388608
+
+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;
@@ -60,9 +65,11 @@ 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 */
+ pages_used += ent->length / DEFAULT_PAGESIZE;
continue;
}
@@ -73,6 +80,8 @@ physmem_populate_bitmap(void)
for (size_t j = 0; j < ent->length; j += DEFAULT_PAGESIZE) {
clrbit(bitmap, (ent->base + j) / DEFAULT_PAGESIZE);
}
+
+ pages_free += ent->length / DEFAULT_PAGESIZE;
}
}
@@ -203,6 +212,36 @@ vm_free_frame(uintptr_t base, size_t count)
spinlock_release(&lock);
}
+/*
+ * Return the amount of memory in MiB that is
+ * currently allocated.
+ */
+uint32_t
+vm_mem_used(void)
+{
+ return (pages_used * DEFAULT_PAGESIZE) / BYTES_PER_MIB;
+}
+
+/*
+ * Return the amount of memory in MiB that is
+ * currently free.
+ */
+uint32_t
+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)
{