1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 17:15:09 +00:00

Kernel: Make DoubleBuffer use a KBuffer instead of kmalloc()ing

Background: DoubleBuffer is a handy buffer class in the kernel that
allows you to keep writing to it from the "outside" while the "inside"
reads from it. It's used for things like LocalSocket and TTY's.
Internally, it has a read buffer and a write buffer, but the two will
swap places when the read buffer is exhausted (by reading from it.)

Before this patch, it was internally implemented as two Vector<u8>
that we would swap between when the reader side had exhausted the data
in the read buffer. Now instead we preallocate a large KBuffer (64KB*2)
on DoubleBuffer construction and use that throughout its lifetime.

This removes all the kmalloc heap traffic caused by DoubleBuffers :^)
This commit is contained in:
Andreas Kling 2020-01-20 16:08:49 +01:00
parent 0a282e0a02
commit f4f958f99f
6 changed files with 54 additions and 37 deletions

View file

@ -110,7 +110,7 @@ bool FIFO::can_read(const FileDescription&) const
bool FIFO::can_write(const FileDescription&) const
{
return m_buffer.bytes_in_write_buffer() < 4096 || !m_readers;
return m_buffer.space_for_writing() || !m_readers;
}
ssize_t FIFO::read(FileDescription&, u8* buffer, ssize_t size)