1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-19 17:22:06 +00:00

Kernel: Allocate profiling memory upfront

We need to allocate all pages for the profiler right away so that
we don't trigger page faults in the timer interrupt handler to
allocate them.

Fixes #4734
This commit is contained in:
Tom 2021-01-01 20:15:06 -07:00 committed by Andreas Kling
parent 06da50afc7
commit 60f5f48dd1
2 changed files with 14 additions and 11 deletions

View file

@ -106,25 +106,25 @@ private:
class KBuffer { class KBuffer {
public: public:
static OwnPtr<KBuffer> try_create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer") static OwnPtr<KBuffer> try_create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
{ {
auto impl = KBufferImpl::try_create_with_size(size, access, name); auto impl = KBufferImpl::try_create_with_size(size, access, name, strategy);
if (!impl) if (!impl)
return nullptr; return nullptr;
return adopt_own(*new KBuffer(impl.release_nonnull())); return adopt_own(*new KBuffer(impl.release_nonnull()));
} }
static OwnPtr<KBuffer> try_create_with_bytes(ReadonlyBytes bytes, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer") static OwnPtr<KBuffer> try_create_with_bytes(ReadonlyBytes bytes, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
{ {
auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name); auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name, strategy);
if (!impl) if (!impl)
return nullptr; return nullptr;
return adopt_own(*new KBuffer(impl.release_nonnull())); return adopt_own(*new KBuffer(impl.release_nonnull()));
} }
static KBuffer create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer") static KBuffer create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
{ {
return KBuffer(KBufferImpl::create_with_size(size, access, name)); return KBuffer(KBufferImpl::create_with_size(size, access, name, strategy));
} }
static KBuffer copy(const void* data, size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer") static KBuffer copy(const void* data, size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer")

View file

@ -25,6 +25,7 @@
*/ */
#include <AK/Demangle.h> #include <AK/Demangle.h>
#include <AK/Singleton.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/Custody.h>
#include <Kernel/KBuffer.h> #include <Kernel/KBuffer.h>
@ -36,8 +37,13 @@ namespace Kernel {
namespace Profiling { namespace Profiling {
static KBufferImpl* s_profiling_buffer;
static size_t s_slot_count; static size_t s_slot_count;
static AK::Singleton<KBuffer, []() -> KBuffer* {
auto buffer = KBuffer::try_create_with_size(8 * MiB, Region::Access::Read | Region::Access::Write, "Profiling Buffer", AllocationStrategy::AllocateNow);
s_slot_count = buffer->size() / sizeof(Sample);
return buffer.leak_ptr();
}>
s_profiling_buffer;
static size_t s_next_slot_index; static size_t s_next_slot_index;
static ProcessID s_pid { -1 }; static ProcessID s_pid { -1 };
@ -62,10 +68,7 @@ void start(Process& process)
executable_path() = {}; executable_path() = {};
s_pid = process.pid(); s_pid = process.pid();
if (!s_profiling_buffer) { s_profiling_buffer.ensure_instance();
s_profiling_buffer = RefPtr<KBufferImpl>(KBuffer::create_with_size(8 * MiB).impl()).leak_ref();
s_slot_count = s_profiling_buffer->size() / sizeof(Sample);
}
s_next_slot_index = 0; s_next_slot_index = 0;
} }