From 3f050c19720e1976bbbe2fd9061a52d2c3cd221c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 28 Oct 2018 10:36:59 +0100 Subject: [PATCH] Add zone dump to /proc/mm. Sweet, now we can look at all the zones (physical memory) currently in play. Building the procfs files with ksprintf and rickety buffer presizing feels pretty shoddy but I'll fix it up eventually. --- Kernel/MemoryManager.h | 1 + Kernel/ProcFileSystem.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h index 4ed3ff66f7..0e749cbb53 100644 --- a/Kernel/MemoryManager.h +++ b/Kernel/MemoryManager.h @@ -16,6 +16,7 @@ enum class PageFaultResponse { }; struct Zone : public Retainable { + friend ByteBuffer procfs$mm(); public: ~Zone(); size_t size() const { return m_pages.size() * PAGE_SIZE; } diff --git a/Kernel/ProcFileSystem.cpp b/Kernel/ProcFileSystem.cpp index f7b7f3f5cb..225f55278f 100644 --- a/Kernel/ProcFileSystem.cpp +++ b/Kernel/ProcFileSystem.cpp @@ -121,10 +121,19 @@ void ProcFileSystem::removeProcess(Task& task) ByteBuffer procfs$mm() { InterruptDisabler disabler; - auto buffer = ByteBuffer::createUninitialized(1024); + size_t zonePageCount = 0; + for (auto* zone : MM.m_zones) + zonePageCount += zone->m_pages.size(); + auto buffer = ByteBuffer::createUninitialized(1024 + 80 * MM.m_zones.size() + zonePageCount * 10); char* ptr = (char*)buffer.pointer(); ptr += ksprintf(ptr, "Zone count: %u\n", MM.m_zones.size()); ptr += ksprintf(ptr, "Free physical pages: %u\n", MM.m_freePages.size()); + for (auto* zone : MM.m_zones) { + ptr += ksprintf(ptr, "Zone %p size: %u\n ", zone, zone->size()); + for (auto page : zone->m_pages) + ptr += ksprintf(ptr, "%x ", page); + ptr += ksprintf(ptr, "\n"); + } buffer.trim(ptr - (char*)buffer.pointer()); return buffer; }