summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/FileSystem/ProcFS.cpp14
-rw-r--r--Kernel/Process.cpp87
-rw-r--r--Kernel/Process.h8
-rw-r--r--Kernel/VM/Space.cpp88
-rw-r--r--Kernel/VM/Space.h8
5 files changed, 103 insertions, 102 deletions
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp
index 8551c6fece..52bddb2901 100644
--- a/Kernel/FileSystem/ProcFS.cpp
+++ b/Kernel/FileSystem/ProcFS.cpp
@@ -806,13 +806,13 @@ static bool procfs$all(InodeIdentifier, KBufferBuilder& builder)
process_object.add("name", process.name());
process_object.add("executable", process.executable() ? process.executable()->absolute_path() : "");
process_object.add("tty", process.tty() ? process.tty()->tty_name() : "notty");
- process_object.add("amount_virtual", process.amount_virtual());
- process_object.add("amount_resident", process.amount_resident());
- process_object.add("amount_dirty_private", process.amount_dirty_private());
- process_object.add("amount_clean_inode", process.amount_clean_inode());
- process_object.add("amount_shared", process.amount_shared());
- process_object.add("amount_purgeable_volatile", process.amount_purgeable_volatile());
- process_object.add("amount_purgeable_nonvolatile", process.amount_purgeable_nonvolatile());
+ process_object.add("amount_virtual", process.space().amount_virtual());
+ process_object.add("amount_resident", process.space().amount_resident());
+ process_object.add("amount_dirty_private", process.space().amount_dirty_private());
+ process_object.add("amount_clean_inode", process.space().amount_clean_inode());
+ process_object.add("amount_shared", process.space().amount_shared());
+ process_object.add("amount_purgeable_volatile", process.space().amount_purgeable_volatile());
+ process_object.add("amount_purgeable_nonvolatile", process.space().amount_purgeable_nonvolatile());
process_object.add("dumpable", process.is_dumpable());
auto thread_array = process_object.add_array("threads");
process.for_each_thread([&](const Thread& thread) {
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 7a39711418..6ed5a8831c 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -554,93 +554,6 @@ void Process::die()
kill_all_threads();
}
-size_t Process::amount_dirty_private() const
-{
- // FIXME: This gets a bit more complicated for Regions sharing the same underlying VMObject.
- // The main issue I'm thinking of is when the VMObject has physical pages that none of the Regions are mapping.
- // That's probably a situation that needs to be looked at in general.
- size_t amount = 0;
- ScopedSpinLock lock(space().get_lock());
- for (auto& region : space().regions()) {
- if (!region.is_shared())
- amount += region.amount_dirty();
- }
- return amount;
-}
-
-size_t Process::amount_clean_inode() const
-{
- HashTable<const InodeVMObject*> vmobjects;
- {
- ScopedSpinLock lock(space().get_lock());
- for (auto& region : space().regions()) {
- if (region.vmobject().is_inode())
- vmobjects.set(&static_cast<const InodeVMObject&>(region.vmobject()));
- }
- }
- size_t amount = 0;
- for (auto& vmobject : vmobjects)
- amount += vmobject->amount_clean();
- return amount;
-}
-
-size_t Process::amount_virtual() const
-{
- size_t amount = 0;
- ScopedSpinLock lock(space().get_lock());
- for (auto& region : space().regions()) {
- amount += region.size();
- }
- return amount;
-}
-
-size_t Process::amount_resident() const
-{
- // FIXME: This will double count if multiple regions use the same physical page.
- size_t amount = 0;
- ScopedSpinLock lock(space().get_lock());
- for (auto& region : space().regions()) {
- amount += region.amount_resident();
- }
- return amount;
-}
-
-size_t Process::amount_shared() const
-{
- // FIXME: This will double count if multiple regions use the same physical page.
- // FIXME: It doesn't work at the moment, since it relies on PhysicalPage ref counts,
- // and each PhysicalPage is only reffed by its VMObject. This needs to be refactored
- // so that every Region contributes +1 ref to each of its PhysicalPages.
- size_t amount = 0;
- ScopedSpinLock lock(space().get_lock());
- for (auto& region : space().regions()) {
- amount += region.amount_shared();
- }
- return amount;
-}
-
-size_t Process::amount_purgeable_volatile() const
-{
- size_t amount = 0;
- ScopedSpinLock lock(space().get_lock());
- for (auto& region : space().regions()) {
- if (region.vmobject().is_anonymous() && static_cast<const AnonymousVMObject&>(region.vmobject()).is_any_volatile())
- amount += region.amount_resident();
- }
- return amount;
-}
-
-size_t Process::amount_purgeable_nonvolatile() const
-{
- size_t amount = 0;
- ScopedSpinLock lock(space().get_lock());
- for (auto& region : space().regions()) {
- if (region.vmobject().is_anonymous() && !static_cast<const AnonymousVMObject&>(region.vmobject()).is_any_volatile())
- amount += region.amount_resident();
- }
- return amount;
-}
-
void Process::terminate_due_to_signal(u8 signal)
{
ASSERT_INTERRUPTS_DISABLED();
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 427dbb660d..39808bd614 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -388,14 +388,6 @@ public:
return m_max_open_file_descriptors;
}
- size_t amount_clean_inode() const;
- size_t amount_dirty_private() const;
- size_t amount_virtual() const;
- size_t amount_resident() const;
- size_t amount_shared() const;
- size_t amount_purgeable_volatile() const;
- size_t amount_purgeable_nonvolatile() const;
-
int exec(String path, Vector<String> arguments, Vector<String> environment, int recusion_depth = 0);
enum class ShouldAllocateTls {
diff --git a/Kernel/VM/Space.cpp b/Kernel/VM/Space.cpp
index bbee739db1..16ef065fba 100644
--- a/Kernel/VM/Space.cpp
+++ b/Kernel/VM/Space.cpp
@@ -28,6 +28,7 @@
#include <Kernel/Process.h>
#include <Kernel/SpinLock.h>
#include <Kernel/VM/AnonymousVMObject.h>
+#include <Kernel/VM/InodeVMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/Space.h>
@@ -219,4 +220,91 @@ void Space::remove_all_regions(Badge<Process>)
m_regions.clear();
}
+size_t Space::amount_dirty_private() const
+{
+ // FIXME: This gets a bit more complicated for Regions sharing the same underlying VMObject.
+ // The main issue I'm thinking of is when the VMObject has physical pages that none of the Regions are mapping.
+ // That's probably a situation that needs to be looked at in general.
+ size_t amount = 0;
+ ScopedSpinLock lock(m_lock);
+ for (auto& region : m_regions) {
+ if (!region.is_shared())
+ amount += region.amount_dirty();
+ }
+ return amount;
+}
+
+size_t Space::amount_clean_inode() const
+{
+ HashTable<const InodeVMObject*> vmobjects;
+ {
+ ScopedSpinLock lock(m_lock);
+ for (auto& region : m_regions) {
+ if (region.vmobject().is_inode())
+ vmobjects.set(&static_cast<const InodeVMObject&>(region.vmobject()));
+ }
+ }
+ size_t amount = 0;
+ for (auto& vmobject : vmobjects)
+ amount += vmobject->amount_clean();
+ return amount;
+}
+
+size_t Space::amount_virtual() const
+{
+ size_t amount = 0;
+ ScopedSpinLock lock(m_lock);
+ for (auto& region : m_regions) {
+ amount += region.size();
+ }
+ return amount;
+}
+
+size_t Space::amount_resident() const
+{
+ // FIXME: This will double count if multiple regions use the same physical page.
+ size_t amount = 0;
+ ScopedSpinLock lock(m_lock);
+ for (auto& region : m_regions) {
+ amount += region.amount_resident();
+ }
+ return amount;
+}
+
+size_t Space::amount_shared() const
+{
+ // FIXME: This will double count if multiple regions use the same physical page.
+ // FIXME: It doesn't work at the moment, since it relies on PhysicalPage ref counts,
+ // and each PhysicalPage is only reffed by its VMObject. This needs to be refactored
+ // so that every Region contributes +1 ref to each of its PhysicalPages.
+ size_t amount = 0;
+ ScopedSpinLock lock(m_lock);
+ for (auto& region : m_regions) {
+ amount += region.amount_shared();
+ }
+ return amount;
+}
+
+size_t Space::amount_purgeable_volatile() const
+{
+ size_t amount = 0;
+ ScopedSpinLock lock(m_lock);
+ for (auto& region : m_regions) {
+ if (region.vmobject().is_anonymous() && static_cast<const AnonymousVMObject&>(region.vmobject()).is_any_volatile())
+ amount += region.amount_resident();
+ }
+ return amount;
+}
+
+size_t Space::amount_purgeable_nonvolatile() const
+{
+ size_t amount = 0;
+ ScopedSpinLock lock(m_lock);
+ for (auto& region : m_regions) {
+ if (region.vmobject().is_anonymous() && !static_cast<const AnonymousVMObject&>(region.vmobject()).is_any_volatile())
+ amount += region.amount_resident();
+ }
+ return amount;
+}
+
}
diff --git a/Kernel/VM/Space.h b/Kernel/VM/Space.h
index 4e4a76dc13..5f376ec389 100644
--- a/Kernel/VM/Space.h
+++ b/Kernel/VM/Space.h
@@ -70,6 +70,14 @@ public:
SpinLock<u32>& get_lock() const { return m_lock; }
+ size_t amount_clean_inode() const;
+ size_t amount_dirty_private() const;
+ size_t amount_virtual() const;
+ size_t amount_resident() const;
+ size_t amount_shared() const;
+ size_t amount_purgeable_volatile() const;
+ size_t amount_purgeable_nonvolatile() const;
+
private:
Space(Process&, NonnullRefPtr<PageDirectory>);