Re: > 15,000 Simultaneous Connections

Robert de Vries (rhdv@rhdv.cistron.nl)
Thu, 9 Sep 1999 21:35:57 +0200 (CEST)


On Tue, 7 Sep 1999, Mike Jagdis wrote:

> On Mon, 6 Sep 1999, Jason Nordwick wrote:
>
> > Can you elaborate as to why it is not possible to remember interesting
> > descriptors in the blocking case?
>
> The kernel side can't remember fd sets because there is no way
> for it to figure out if the sets have changed between calls
> other than by scanning through them.

What if the kernel would *maintain* three select-like bitmaps for all
fds, not just the ones in the fdset of the current select call? At the
moment data arrives in a socket the kernel just flips a bit in the
appropriate bitmap, and unflips it when it is empty again. Same for the
write and exception bitmaps.
When a select is done, the kernel just ANDs the bitmap from userspace and
the maintained bitmap and if bits are set returns immediately, if not
blocks until timeout. If select becomes unblocked, the ANDing is done once
again (no check needed) and returns.
ANDing large bitmaps is not very expensive, although still O(n).
Maintaining the bitmaps is a small overhead at a time when often lots of
other much more expensive things are going on. This should be relatively
painless.

The essence of this idea is to spend a tiny amount of CPU for each fd,
in order to decrease significantly the big pain in select.

Robert

-- 
Robert de Vries
rhdv@rhdv.cistron.nl

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/