Subject: Re: Fwd: Packet mmap: TX RING and zero copy

From: Evgeniy Polyakov <[email-masked]>
Date: Mon, 8 Sep 2008 15:26:29 +0400

Hi Johann.

On Mon, Sep 08, 2008 at 12:21:16PM +0200, Johann Baudy ([email-masked]) wrote:
> I've made a test with below patch (with and without UDP fragmentation):
> 
> without UDP fragmentation, packet size are almost always equal to
> PAGE_SIZE due to my mtu limit (2*PACKET_SIZE > mtu).
> with UDP fragmentation, kernel is sending multiple fragmented packets
> of 61448Kbytes.
> 
> Unfortunately, in both case, bitrate is still 15-20 MB/s :(
> According to wireshark, kernel sends 60KB over 9 packets, nothing
> during ~5ms, 60KB and so on. strange ... kernel seems to spend its
> time during push(). Is there a blocking call somewhere ?

Are you sure that it is udp_push_pending_frames() and not some splice
waiting?

> Thanks in advance,
> Johann
> 
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> 
> @@ -743,7 +743,28 @@ int udp_sendpage(struct sock *sk, struct page
> *page, int offset,
>                  size_t size, int flags)
>  {
>         struct udp_sock *up = udp_sk(sk);
> +       struct inet_sock *inet = inet_sk(sk);
>         int ret;
> +       int mtu = inet->cork.fragsize;
> +       int fragheaderlen;
> +       struct ip_options *opt = NULL;
> +
> +       if (inet->cork.flags & IPCORK_OPT)
> +               opt = inet->cork.opt;

This has to be checked under socket lock.

> +       fragheaderlen = sizeof(struct iphdr) + (opt ? opt->optlen : 0);
> +
> +       // With UDP fragmentation
> +       if (inet->cork.length + size >= 0xFFFF - fragheaderlen) {
> +       // Without UDP fragmentation
> +       //  if( (inet->cork.length + size) > mtu) {

This also should be protected. Two threads can simultaneously check
inet->cork.length and both suceed.

> +               lock_sock(sk);
> +               ret = udp_push_pending_frames(sk);
> +               release_sock(sk);
> +               if (ret) {
> +                       return 0;
> +               }
> +       }

-- 
	Evgeniy Polyakov