netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: jon.maloy@ericsson.com
Cc: netdev@vger.kernel.org,
	mohan.krishna.ghanta.krishnamurthy@ericsson.com,
	tung.q.nguyen@dektech.com.au, hoang.h.le@dektech.com.au,
	canh.d.luu@dektech.com.au, ying.xue@windriver.com,
	tipc-discussion@lists.sourceforge.net
Subject: Re: [net-next 1/1] tipc: avoid unnecessary copying of bundled messages
Date: Wed, 14 Feb 2018 15:27:21 -0500 (EST)	[thread overview]
Message-ID: <20180214.152721.140431586969521284.davem@davemloft.net> (raw)
In-Reply-To: <1518612631-21171-1-git-send-email-jon.maloy@ericsson.com>

From: Jon Maloy <jon.maloy@ericsson.com>
Date: Wed, 14 Feb 2018 13:50:31 +0100

> diff --git a/net/tipc/msg.c b/net/tipc/msg.c
> index 4e1c6f6..a368fa8 100644
> --- a/net/tipc/msg.c
> +++ b/net/tipc/msg.c
> @@ -434,6 +434,9 @@ bool tipc_msg_extract(struct sk_buff *skb, struct sk_buff **iskb, int *pos)
>  	skb_pull(*iskb, offset);
>  	imsz = msg_size(buf_msg(*iskb));
>  	skb_trim(*iskb, imsz);
> +
> +	/* Scale extracted buffer's truesize to avoid double accounting */
> +	(*iskb)->truesize = SKB_TRUESIZE(imsz);
>  	if (unlikely(!tipc_msg_validate(iskb)))
>  		goto none;
>  	*pos += align(imsz);

As Eric said, you have to be really careful here.

If you clone a 10K SKB 10 times, you really have to account for the full
truesize 10 times.

That is unless you explicitly trim off frags in the new clone, then adjust
the truesize by explicitly decreasing it by the amount of memory backing
the frags you trimmed off completely (not partially).

Finally, you can only do this on an SKB that has never entered a socket
SKB queue, otherwise you corrupt memory accounting.

  parent reply	other threads:[~2018-02-14 20:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-14 12:50 [net-next 1/1] tipc: avoid unnecessary copying of bundled messages Jon Maloy
2018-02-14 13:42 ` Eric Dumazet
2018-02-14 20:27 ` David Miller [this message]
2018-02-15  8:57   ` Jon Maloy
2018-02-16 20:25     ` David Miller

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=20180214.152721.140431586969521284.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=canh.d.luu@dektech.com.au \
    --cc=hoang.h.le@dektech.com.au \
    --cc=jon.maloy@ericsson.com \
    --cc=mohan.krishna.ghanta.krishnamurthy@ericsson.com \
    --cc=netdev@vger.kernel.org \
    --cc=tipc-discussion@lists.sourceforge.net \
    --cc=tung.q.nguyen@dektech.com.au \
    --cc=ying.xue@windriver.com \
    /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).