From c8e6cfe6972a7ae6b89d9ed036b48356f72f18cb Mon Sep 17 00:00:00 2001 From: Chloe M Date: Fri, 10 Jul 2026 19:17:13 -0400 Subject: [PATCH] ptos: pm: Print usable memory in pretty units Signed-off-by: Chloe M --- service/ptos/mm/pm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/service/ptos/mm/pm.c b/service/ptos/mm/pm.c index 0712f74..ce5c609 100644 --- a/service/ptos/mm/pm.c +++ b/service/ptos/mm/pm.c @@ -11,6 +11,7 @@ #include #include #include +#include #define DTRACE(Fmt, ...) \ TRACE("[ PM ]: " Fmt, ##__VA_ARGS__) @@ -66,6 +67,30 @@ typedef struct { /* Standard usable memory list */ static MM_PFD_LIST AvlList; +/* Memory statistics */ +static USIZE UsableMemory; + +/* + * Used to convert bytes into human readable units + */ +static inline VOID +PmZoneSize(const CHAR *TypeName, USIZE Length) +{ + if (TypeName == NULL) { + return; + } + + if (Length >= UNIT_GIB) { + DTRACE("%s : %d GiB\n", TypeName, Length / UNIT_GIB); + } else if (Length >= UNIT_MIB) { + DTRACE("%s : %d MiB\n", TypeName, Length / UNIT_MIB); + } else if (Length >= UNIT_KIB) { + DTRACE("%s : %d KiB\n", TypeName, Length / UNIT_KIB); + } else { + DTRACE("%s : %d bytes\n", TypeName, Length); + } +} + /* * Appends a page frame descriptor to a page frame descriptor * list. @@ -179,9 +204,12 @@ PmProbe(VOID) } ++ZoneCount; + UsableMemory += Entry.Length; } + /* Log some statistics */ DTRACE("%d pfds, %d zones\n", PfdCount, ZoneCount); + PmZoneSize("usable", UsableMemory); } MM_PFN