From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Miller Subject: Re: [net-next 1/1] tipc: avoid unnecessary copying of bundled messages Date: Wed, 14 Feb 2018 15:27:21 -0500 (EST) Message-ID: <20180214.152721.140431586969521284.davem@davemloft.net> References: <1518612631-21171-1-git-send-email-jon.maloy@ericsson.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 To: jon.maloy@ericsson.com Return-path: Received: from shards.monkeyblade.net ([184.105.139.130]:58518 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934803AbeBNU1X (ORCPT ); Wed, 14 Feb 2018 15:27:23 -0500 In-Reply-To: <1518612631-21171-1-git-send-email-jon.maloy@ericsson.com> Sender: netdev-owner@vger.kernel.org List-ID: From: Jon Maloy 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.