aboutsummaryrefslogtreecommitdiff
path: root/kernel/mm/page.py
diff options
context:
space:
mode:
authornthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
committernthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
commitc63f340d90800895f007de64b7d2d14624263331 (patch)
tree2c0849fa597dd6da831c8707b6f2603403778d7b /kernel/mm/page.py
Created student weenix repository
Diffstat (limited to 'kernel/mm/page.py')
-rw-r--r--kernel/mm/page.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/kernel/mm/page.py b/kernel/mm/page.py
new file mode 100644
index 0000000..9dfedf0
--- /dev/null
+++ b/kernel/mm/page.py
@@ -0,0 +1,47 @@
+import gdb
+
+import weenix
+import weenix.kmem
+
+
+class PageCommand(weenix.Command):
+ def __init__(self):
+ weenix.Command.__init__(self, "page", gdb.COMMAND_DATA, gdb.COMPLETE_NONE)
+
+ def invoke(self, args, tty):
+ total = 0
+ print("pagesize: {0}".format(weenix.kmem.pagesize()))
+
+ names = list()
+ blobs = list()
+ pages = list()
+ bytes = list()
+
+ for order, count in weenix.kmem.freepages().items():
+ pcount = count * (1 << order)
+ bcount = pcount * weenix.kmem.pagesize()
+ names.append("freepages[{0}]:".format(order))
+ blobs.append("{0} blob{1}".format(count, " " if (count == 1) else "s"))
+ pages.append("{0} page{1}".format(pcount, " " if (pcount == 1) else "s"))
+ bytes.append("{0} byte{1}".format(bcount, " " if (bcount == 1) else "s"))
+ total += count * (1 << order)
+
+ names.append("total:")
+ blobs.append("")
+ pages.append("{0} page{1}".format(total, " " if (total == 1) else "s"))
+ bytes.append("{0} bytes".format(total * weenix.kmem.pagesize()))
+
+ namewidth = max(list(map(lambda x: len(x), names)))
+ blobwidth = max(list(map(lambda x: len(x), blobs)))
+ pagewidth = max(list(map(lambda x: len(x), pages)))
+ bytewidth = max(list(map(lambda x: len(x), bytes)))
+
+ for name, blob, page, byte in zip(names, blobs, pages, bytes):
+ print(
+ "{1:<{0}} {3:>{2}} {5:>{4}} {7:>{6}}".format(
+ namewidth, name, blobwidth, blob, pagewidth, page, bytewidth, byte
+ )
+ )
+
+
+PageCommand()