From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ig0-f177.google.com (mail-ig0-f177.google.com [209.85.213.177]) by dpdk.org (Postfix) with ESMTP id 434DEC34A for ; Thu, 28 May 2015 18:07:00 +0200 (CEST) Received: by igbsb11 with SMTP id sb11so43119373igb.0 for ; Thu, 28 May 2015 09:06:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=vKGEMbeg+O8NYzqZMySuYOA1jFctD0urphqz1oM+4Ww=; b=k38oGUVZutYV4n3WkZzqW24eWUS+NTBUetSNWehOhciZZOICh6rbPeMJNcNzT3jBYZ 3xlzz/Ns6F7WzjW9R/aQ55Z7VZW1UsHuyoPvRQqeu8B+0BlBUmtetx8R75XOPOp/S7FL LhMcMgMTr/0V3TfwSgaNdFhwGsCWZ26rJV6wG7pHHoFH2Pt2QTx6Tlqoe0Zi6vl3zlwz 7zPQnU/6pm68xjajF4DFcE2T0a9PIyQLE4oezopCbjSUvvzTsdksAsibIA2/aVx+p6wn hJ4aos7sQ/8q4h54u+1G52wl2/Bcok7urt3TM4Tc94i330h4FZWpIdt6aQxnyZmVGuIs KcaQ== X-Gm-Message-State: ALoCoQmoBZmwGCiYD/UfJ019CcqwQwxiF07pI5xNIMVrO5JLgvJlfXghIdjsps//bN13lhFJBNxx MIME-Version: 1.0 X-Received: by 10.50.33.19 with SMTP id n19mr20883508igi.8.1432829219586; Thu, 28 May 2015 09:06:59 -0700 (PDT) Received: by 10.36.159.68 with HTTP; Thu, 28 May 2015 09:06:59 -0700 (PDT) In-Reply-To: References: <57F6A61F-5629-4D11-A78C-397DBB4E8381@inventum.net> <20150528075244.469b8557@urahara> Date: Thu, 28 May 2015 11:06:59 -0500 Message-ID: From: Matt Laswell To: Kyle Larose Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] Packet Cloning X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 May 2015 16:07:00 -0000 Hey Kyle, That's one way you can handle it, though I suspect you'll end up with some complexity elsewhere in your code to deal with remembering whether you should look at the original data or the copied and modified data. Another way is just to make a copy of the original mbuf, but have your copy API stop after it reaches some particular point. Perhaps just the L2-L4 headers, perhaps a few hundred bytes into payload, or perhaps something else entirely. This all gets very application dependent, of course. How much is "enough" is going to depend heavily on what you're trying to accomplish. -- Matt Laswell infinite io, inc. laswell@infiniteio.com On Thu, May 28, 2015 at 10:38 AM, Kyle Larose wrote: > I'm fairly new to dpdk, so I may be completely out to lunch on this, but > here's an idea to possibly improve performance compared to a straight copy > of the entire packet. If this idea makes sense, perhaps it could be added > to the mbuf library as an extension of the clone functionality? > > If you are only modifying the headers (say the Ethernet header), is it > possible to make a copy of only the first N bytes (say 32 bytes)? > > For example, you make two new "main" mbufs, which contain duplicate > metadata, and a copy of the first 32 bytes of the packet. Call them A and > B. Have both A and B chain to the original mbuf (call it O), which is > reference counted as with the normal clone functionality. Then, you adjust > the O such that its start data is 32 bytes into the packet. > > When you transmit A, it will send its own copy of the 32 bytes, plus the > unaltered remaining data contained in O. A will be freed, and the refcount > of O decremented. When you transmit B, it will work the same as with the > previous one, except that when the refcount on O is decremented, it reaches > zero and it is freed as well. > > I'm not sure if this makes sense in all cases (for example, maybe it's > just faster to allocate separate mbufs for 64-byte packets). Perhaps that > could also be handled transparently underneath the hood. > > Thoughts? > > Thanks, > > Kyle > > On Thu, May 28, 2015 at 11:10 AM, Matt Laswell > wrote: > >> Since Padam is going to be altering payload, he likely cannot use that >> API. >> The rte_pktmbuf_clone() API doesn't make a copy of the payload. Instead, >> it gives you a second mbuf whose payload pointer points back to the >> contents of the first (and also increments the reference counter on the >> first so that it isn't actually freed until all clones are accounted for). >> This is very fast, which is good. However, since there's only really one >> buffer full of payload, changes in the original also affect the clone and >> vice versa. This can have surprising and unpleasant side effects that may >> not show up until you are under load, which is awesome*. >> >> For what it's worth, if you need to be able to modify the copy while >> leaving the original alone, I don't believe that there's a good solution >> within DPDK. However, writing your own API to copy rather than clone a >> packet mbuf isn't difficult. >> >> -- >> Matt Laswell >> infinite io, inc. >> laswell@infiniteio.com >> >> * Don't ask me how I know how much awesome fun this can be, though I >> suspect you can guess. >> >> On Thu, May 28, 2015 at 9:52 AM, Stephen Hemminger < >> stephen@networkplumber.org> wrote: >> >> > On Thu, 28 May 2015 17:15:42 +0530 >> > Padam Jeet Singh wrote: >> > >> > > Hello, >> > > >> > > Is there a function in DPDK to completely clone a pkt_mbuf including >> the >> > segments? >> > > >> > > I am trying to build a packet mirroring application which sends packet >> > out through two separate interfaces, but the packet payload needs to be >> > altered before send. >> > > >> > > Thanks, >> > > Padam >> > > >> > > >> > >> > Isn't this what you want? >> > >> > /** >> > * Creates a "clone" of the given packet mbuf. >> > * >> > * Walks through all segments of the given packet mbuf, and for each of >> > them: >> > * - Creates a new packet mbuf from the given pool. >> > * - Attaches newly created mbuf to the segment. >> > * Then updates pkt_len and nb_segs of the "clone" packet mbuf to match >> > values >> > * from the original packet mbuf. >> > * >> > * @param md >> > * The packet mbuf to be cloned. >> > * @param mp >> > * The mempool from which the "clone" mbufs are allocated. >> > * @return >> > * - The pointer to the new "clone" mbuf on success. >> > * - NULL if allocation fails. >> > */ >> > static inline struct rte_mbuf *rte_pktmbuf_clone(struct rte_mbuf *md, >> > struct rte_mempool *mp) >> > >> > >