netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>
Subject: Re: [PATCH net-next 3/3] udp: try to avoid 2 cache miss on dequeue
Date: Thu, 01 Jun 2017 12:46:27 +0200	[thread overview]
Message-ID: <1496313987.4872.16.camel@redhat.com> (raw)
In-Reply-To: <1496250276.27480.9.camel@edumazet-glaptop3.roam.corp.google.com>

On Wed, 2017-05-31 at 10:04 -0700, Eric Dumazet wrote:
> On Mon, 2017-05-29 at 17:27 +0200, Paolo Abeni wrote:
> > when udp_recvmsg() is executed, on x86_64 and other archs, most skb
> > fields are on cold cachelines.
> > If the skb are linear and the kernel don't need to compute the udp
> > csum, only a handful of skb fields are required by udp_recvmsg().
> > Since we already use skb->dev_scratch to cache hot data, and
> > there are 32 bits unused on 64 bit archs, use such field to cache
> > as much data as we can, and try to prefetch on dequeue the relevant
> > fields that are left out.
> > 
> > This can save up to 2 cache miss per packet.
> 
> okay ;)
> 
> > 
> > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > ---
> >  net/ipv4/udp.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++------
> >  1 file changed, 103 insertions(+), 11 deletions(-)
> > 
> > diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> > index 53fa48d..616132e 100644
> > --- a/net/ipv4/udp.c
> > +++ b/net/ipv4/udp.c
> > @@ -1163,6 +1163,83 @@ int udp_sendpage(struct sock *sk, struct page *page, int offset,
> >  	return ret;
> >  }
> >  
> > +/* Copy as much information as possible into skb->dev_scratch to avoid
> > + * possibly multiple cache miss on dequeue();
> > + */
> > +#if BITS_PER_LONG == 64
> > +
> > +/* we can store multiple info here: truesize, len and the bit needed to
> > + * compute skb_csum_unnecessary will be on cold cache lines at recvmsg
> > + * time.
> > + * skb->len can be stored on 16 bits since the udp header has been already
> > + * validated and pulled.
> > + */
> > +struct udp_dev_scratch {
> > +	__u32 truesize;
> > +	__u16 len;
> > +	__u16 is_linear:1;
> > +	__u16 csum_unnecessary:1;
> 
> What about 
> 	u32   truesize;
> 	u16   len;
> 	bool  is_linear;
> 	bool  csum_unnecessary;
> 
> I do not believe the __ prefix is necessary for a local structure (not
> uapi)
> 
> Also a plain bool or u8 is faster than a bit field (shorter
> instructions)

Thank you! I like the above! I'll go for 'bool' usage in v2,

Paolo

p.s. I used the bitfield because I initially had an additional, very
ugly, patch saving another cache miss and requiring one more bit there,
 but said patch hurted so much the sight that I had to drop it.

  reply	other threads:[~2017-06-01 10:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-29 15:27 [PATCH net-next 0/3] udp: reduce cache pressure Paolo Abeni
2017-05-29 15:27 ` [PATCH net-next 1/3] net: factor out a helper to decrement the skb refcount Paolo Abeni
2017-05-31 16:56   ` Eric Dumazet
2017-05-29 15:27 ` [PATCH net-next 2/3] udp: avoid a cache miss on dequeue Paolo Abeni
2017-05-31 17:00   ` Eric Dumazet
2017-06-01 10:39     ` Paolo Abeni
2017-06-01 15:58       ` Eric Dumazet
2017-06-01 16:21         ` Paolo Abeni
2017-06-01 16:40           ` Eric Dumazet
2017-06-01 20:35             ` Paolo Abeni
2017-06-01 20:50               ` Eric Dumazet
2017-05-29 15:27 ` [PATCH net-next 3/3] udp: try to avoid 2 " Paolo Abeni
2017-05-31 17:04   ` Eric Dumazet
2017-06-01 10:46     ` Paolo Abeni [this message]
2017-06-07  2:12   ` [lkp-robot] [udp] bc0d3d0639: apachebench.requests_per_second -21% regression kernel test robot
2017-05-31 16:47 ` [PATCH net-next 0/3] udp: reduce cache pressure David Miller
2017-05-31 16:52   ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1496313987.4872.16.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).