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.
This commit is contained in:
Andreas Kling 2018-10-28 10:36:59 +01:00
parent c76dc9a047
commit 3f050c1972
2 changed files with 11 additions and 1 deletions

View file

@ -16,6 +16,7 @@ enum class PageFaultResponse {
};
struct Zone : public Retainable<Zone> {
friend ByteBuffer procfs$mm();
public:
~Zone();
size_t size() const { return m_pages.size() * PAGE_SIZE; }

View file

@ -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;
}