Kernel: Provide consistent memory stats in ProcFS
We should take the MM lock when gathering all the statistics that we need so that the values are consistent.
This commit is contained in:
parent
de6a4d49b8
commit
d3e6cdf21f
Notes:
sideshowbarker
2024-07-19 00:06:08 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/d3e6cdf21fa Pull-request: https://github.com/SerenityOS/serenity/pull/4807
2 changed files with 18 additions and 4 deletions
Kernel
|
@ -790,14 +790,26 @@ static bool procfs$memstat(InodeIdentifier, KBufferBuilder& builder)
|
|||
kmalloc_stats stats;
|
||||
get_kmalloc_stats(stats);
|
||||
|
||||
ScopedSpinLock mm_lock(s_mm_lock);
|
||||
auto user_physical_pages_total = MM.user_physical_pages();
|
||||
auto user_physical_pages_used = MM.user_physical_pages_used();
|
||||
auto user_physical_pages_committed = MM.user_physical_pages_committed();
|
||||
auto user_physical_pages_uncommitted = MM.user_physical_pages_uncommitted();
|
||||
|
||||
auto super_physical_total = MM.super_physical_pages();
|
||||
auto super_physical_used = MM.super_physical_pages_used();
|
||||
mm_lock.unlock();
|
||||
|
||||
JsonObjectSerializer<KBufferBuilder> json { builder };
|
||||
json.add("kmalloc_allocated", stats.bytes_allocated);
|
||||
json.add("kmalloc_available", stats.bytes_free);
|
||||
json.add("kmalloc_eternal_allocated", stats.bytes_eternal);
|
||||
json.add("user_physical_allocated", MM.user_physical_pages_used());
|
||||
json.add("user_physical_available", MM.user_physical_pages() - MM.user_physical_pages_used());
|
||||
json.add("super_physical_allocated", MM.super_physical_pages_used());
|
||||
json.add("super_physical_available", MM.super_physical_pages() - MM.super_physical_pages_used());
|
||||
json.add("user_physical_allocated", user_physical_pages_used);
|
||||
json.add("user_physical_available", user_physical_pages_total - user_physical_pages_used);
|
||||
json.add("user_physical_committed", user_physical_pages_committed);
|
||||
json.add("user_physical_uncommitted", user_physical_pages_uncommitted);
|
||||
json.add("super_physical_allocated", super_physical_used);
|
||||
json.add("super_physical_available", super_physical_total - super_physical_used);
|
||||
json.add("kmalloc_call_count", stats.kmalloc_call_count);
|
||||
json.add("kfree_call_count", stats.kfree_call_count);
|
||||
slab_alloc_stats([&json](size_t slab_size, size_t num_allocated, size_t num_free) {
|
||||
|
|
|
@ -131,6 +131,8 @@ public:
|
|||
|
||||
unsigned user_physical_pages() const { return m_user_physical_pages; }
|
||||
unsigned user_physical_pages_used() const { return m_user_physical_pages_used; }
|
||||
unsigned user_physical_pages_committed() const { return m_user_physical_pages_committed; }
|
||||
unsigned user_physical_pages_uncommitted() const { return m_user_physical_pages_uncommitted; }
|
||||
unsigned super_physical_pages() const { return m_super_physical_pages; }
|
||||
unsigned super_physical_pages_used() const { return m_super_physical_pages_used; }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue