1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 17:27:34 +00:00

Kernel: Use KBuffers for ProcFS and SynthFS

Instead of generating ByteBuffers and keeping those lying around, have
these filesystems generate KBuffers instead. These are way less spooky
to leave around for a while.

Since FileDescription will keep a generated file buffer around until
userspace has read the whole thing, this prevents trivially exhausting
the kmalloc heap by opening many files in /proc for example.

The code responsible for generating each /proc file is not perfectly
efficient and many of them still use ByteBuffers internally but they
at least go away when we return now. :^)
This commit is contained in:
Andreas Kling 2019-08-05 11:35:49 +02:00
parent 6b6b86fbf3
commit 79e22acb22
7 changed files with 58 additions and 43 deletions

View file

@ -65,11 +65,16 @@ public:
const KBufferImpl& impl() const { return m_impl; }
KBuffer(NonnullRefPtr<KBufferImpl>&& impl)
: m_impl(move(impl))
KBuffer(const ByteBuffer& buffer)
: m_impl(KBufferImpl::copy(buffer.data(), buffer.size()))
{
}
private:
explicit KBuffer(NonnullRefPtr<KBufferImpl>&& impl)
: m_impl(move(impl))
{
}
NonnullRefPtr<KBufferImpl> m_impl;
};