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

Net: Try to reuse incoming packet buffers to avoid allocation churn

The majority of the time in NetworkTask was being spent in allocating
and deallocating KBuffers for each incoming packet.

We'll now keep up to 100 buffers around and reuse them for new packets
if the next incoming packet fits in an old buffer. This is pretty
naively implemented but definitely cuts down on time spent here.
This commit is contained in:
Andreas Kling 2019-12-14 11:07:37 +01:00
parent 39246fb621
commit ac215ca601
4 changed files with 53 additions and 24 deletions

View file

@ -37,7 +37,7 @@ public:
void send(const MACAddress&, const ARPPacket&);
void send_ipv4(const MACAddress&, const IPv4Address&, IPv4Protocol, const u8* payload, size_t payload_size, u8 ttl);
Optional<KBuffer> dequeue_packet();
size_t dequeue_packet(u8* buffer, size_t buffer_size);
bool has_queued_packets() const { return !m_packet_queue.is_empty(); }
@ -64,6 +64,8 @@ private:
IPv4Address m_ipv4_netmask;
IPv4Address m_ipv4_gateway;
SinglyLinkedList<KBuffer> m_packet_queue;
SinglyLinkedList<KBuffer> m_unused_packet_buffers;
size_t m_unused_packet_buffers_count { 0 };
String m_name;
u32 m_packets_in { 0 };
u32 m_bytes_in { 0 };