Skip to content

Commit

Permalink
feat: pmm usage stats
Browse files Browse the repository at this point in the history
  • Loading branch information
portasynthinca3 committed Aug 5, 2024
1 parent d3ecca2 commit 997c70c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Run this project in QEMU with:
```shell
$ git clone https://github.com/portasynthinca3/boss
$ cd boss
$ make qemu
$ just qemu
```

Currently, the OS does not display anything on the screen. Instead, refer to
Expand Down
15 changes: 15 additions & 0 deletions src/mem_manager/phys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,18 @@ pub fn relocate() {

(*guard).relocate();
}

/// Returns a tuple containing used and available physical memory.
pub fn stats() -> (ByteSize, ByteSize) {
let mut used = ByteSize(0);
let mut available = ByteSize(0);

for range in (*ALL_RANGES.read()).as_ref().unwrap().iter() {
available += ByteSize(range.pages * PAGE_SIZE);
for b in range.bitmap.as_ref() {
used += ByteSize(b.count_ones() as usize * PAGE_SIZE);
}
}

(used, available)
}

0 comments on commit 997c70c

Please sign in to comment.