summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-15 19:43:12 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-15 19:43:12 +0200
commite9c0f4567dae2ca6c3a9cc377d8f65b25ced74e9 (patch)
tree717bb1e9e91f4fe8ff9451eb545d87486cebb019 /Kernel
parent13041f894fbfcb89b78cd1dfb18f3ca5072eb62a (diff)
downloadserenity-e9c0f4567dae2ca6c3a9cc377d8f65b25ced74e9.zip
Kernel+ProcessManager: Expose the number of kmalloc/kfree calls.
This will be very helpful in tracking down unwanted kmalloc traffic. :^)
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FileSystem/ProcFS.cpp7
-rw-r--r--Kernel/kmalloc.cpp5
-rw-r--r--Kernel/kmalloc.h2
3 files changed, 12 insertions, 2 deletions
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp
index d9c28162bd..1aaf655101 100644
--- a/Kernel/FileSystem/ProcFS.cpp
+++ b/Kernel/FileSystem/ProcFS.cpp
@@ -8,6 +8,7 @@
#include "Console.h"
#include "Scheduler.h"
#include <Kernel/PCI.h>
+#include <Kernel/kmalloc.h>
#include <AK/StringBuilder.h>
#include <LibC/errno_numbers.h>
@@ -558,14 +559,16 @@ ByteBuffer procfs$memstat(InodeIdentifier)
{
InterruptDisabler disabler;
StringBuilder builder;
- builder.appendf("%u,%u,%u,%u,%u,%u,%u\n",
+ builder.appendf("%u,%u,%u,%u,%u,%u,%u,%u,%u\n",
kmalloc_sum_eternal,
sum_alloc,
sum_free,
MM.user_physical_pages_in_existence() - MM.m_free_physical_pages.size(),
MM.m_free_physical_pages.size(),
MM.super_physical_pages_in_existence() - MM.m_free_supervisor_physical_pages.size(),
- MM.m_free_supervisor_physical_pages.size()
+ MM.m_free_supervisor_physical_pages.size(),
+ g_kmalloc_call_count,
+ g_kfree_call_count
);
return builder.to_byte_buffer();
}
diff --git a/Kernel/kmalloc.cpp b/Kernel/kmalloc.cpp
index e52d80c607..9c952bf5cc 100644
--- a/Kernel/kmalloc.cpp
+++ b/Kernel/kmalloc.cpp
@@ -33,6 +33,9 @@ volatile size_t sum_alloc = 0;
volatile size_t sum_free = POOL_SIZE;
volatile size_t kmalloc_sum_eternal = 0;
+dword g_kmalloc_call_count;
+dword g_kfree_call_count;
+
static byte* s_next_eternal_ptr;
static byte* s_end_of_eternal_range;
@@ -90,6 +93,7 @@ void* kmalloc_page_aligned(size_t size)
void* kmalloc_impl(size_t size)
{
InterruptDisabler disabler;
+ ++g_kmalloc_call_count;
// We need space for the allocation_t structure at the head of the block.
size_t real_size = size + sizeof(allocation_t);
@@ -153,6 +157,7 @@ void* kmalloc_impl(size_t size)
void kfree(void *ptr)
{
+ ++g_kfree_call_count;
if (!ptr)
return;
diff --git a/Kernel/kmalloc.h b/Kernel/kmalloc.h
index 19e9fb9644..001d22da5a 100644
--- a/Kernel/kmalloc.h
+++ b/Kernel/kmalloc.h
@@ -18,6 +18,8 @@ extern volatile size_t sum_alloc;
extern volatile size_t sum_free;
extern volatile size_t kmalloc_sum_eternal;
extern volatile size_t kmalloc_sum_page_aligned;
+extern dword g_kmalloc_call_count;
+extern dword g_kfree_call_count;
inline void* operator new(size_t, void* p) { return p; }
inline void* operator new[](size_t, void* p) { return p; }