3 ms·
I worked on a router with multicast and we avoided packet copying with an interesting reference counting scheme: When a packet arrives, its handle gets 64K ref
by jhallenworld 11y ago
I worked on a router with multicast and we avoided packet copying with an interesting reference counting scheme:
When a packet arrives, its handle gets 64K references and its 16-bit reference counter has 0 references.
When we are done with the handle (packet transmitted), the references in the handle are added to the counter. If the result is 0, the packet can be freed.
When we duplicate a packet, always it's the case that there is a parent handle which gets split into children. So what do you do? You divide the references among the children: so now you have two handles with 32K references. First one is done, counter will have 32K. Second one is done, counter will have 0 and packet can be freed.
The advantage of this scheme is that there is only exactly one ADD to reference counter per duplicated packet.
For large packets this scheme will be faster than copying. For small packets, maybe not. Even the single ADD is probably a miss and involves moving a cache-line. (anyway, usually you want packet header to be in the handle, so small packets fit in the handle, large packets use buffers).