From: Alexander Lobakin <aleksander.lobakin@intel.com> To: Alexander H Duyck <alexander.duyck@gmail.com> Cc: "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Paul Menzel <pmenzel@molgen.mpg.de>, "Jesper Dangaard Brouer" <hawk@kernel.org>, Larysa Zaremba <larysa.zaremba@intel.com>, <netdev@vger.kernel.org>, Ilias Apalodimas <ilias.apalodimas@linaro.org>, <linux-kernel@vger.kernel.org>, Michal Kubiak <michal.kubiak@intel.com>, <intel-wired-lan@lists.osuosl.org>, Christoph Hellwig <hch@lst.de>, "Magnus Karlsson" <magnus.karlsson@intel.com> Subject: Re: [Intel-wired-lan] [PATCH net-next v2 03/12] iavf: optimize Rx buffer allocation a bunch Date: Wed, 31 May 2023 17:13:22 +0200 [thread overview] Message-ID: <cb7d3479-63a5-31b4-355d-b12a7e1b2878@intel.com> (raw) In-Reply-To: <8828262f1c238ab28be9ec87a7701acd791af926.camel@gmail.com> From: Alexander H Duyck <alexander.duyck@gmail.com> Date: Tue, 30 May 2023 09:18:40 -0700 > On Thu, 2023-05-25 at 14:57 +0200, Alexander Lobakin wrote: >> The Rx hotpath code of IAVF is not well-optimized TBH. Before doing any >> further buffer model changes, shake it up a bit. Notably: >> >> 1. Cache more variables on the stack. >> DMA device, Rx page size, NTC -- these are the most common things >> used all throughout the hotpath, often in loops on each iteration. >> Instead of fetching (or even calculating, as with the page size) them >> from the ring all the time, cache them on the stack at the beginning >> of the NAPI polling callback. NTC will be written back at the end, >> the rest are used read-only, so no sync needed. > > The advantage of this is going to vary based on the attribute. One of > the reasons why I left most of this on the ring is because the section > of the ring most of these variables were meant to be read-mostly and > shouldn't have resulted in any additional overhead versus accessing > them from the stack. But not all of these variables are read-only. E.g. NTC is often modified. Page size was calculated per descriptor, but could be once a poll cycle starts, and so on. > >> 2. Don't move the recycled buffers around the ring. >> The idea of passing the page of the right-now-recycled-buffer to a >> different buffer, in this case, the first one that needs to be >> allocated, moreover, on each new frame, is fundamentally wrong. It >> involves a few o' fetches, branches and then writes (and one Rx >> buffer struct is at least 32 bytes) where they're completely unneeded, >> but gives no good -- the result is the same as if we'd recycle it >> inplace, at the same position where it was used. So drop this and let >> the main refilling function take care of all the buffers, which were >> processed and now need to be recycled/refilled. > > The next_to_alloc logic was put in place to deal with systems that are > experiencing memory issues. Specifically what can end up happening is > that the ring can stall due to failing memory allocations and the > memory can get stuck on the ring. For that reason we were essentially > defragmenting the buffers when we started suffering memory pressure so > that they could be reusued and/or freed following immediate use. > > Basically what you are trading off is some exception handling for > performance by removing it. I'm not sure this helps a lot, but OTOH this really slows down things, esp. given that this code is run all the time, not only when a memory allocation fail happens. > >> 3. Don't allocate with %GPF_ATOMIC on ifup. >> This involved introducing the @gfp parameter to a couple functions. >> Doesn't change anything for Rx -> softirq. > > Any specific reason for this? Just wondering if this is meant to > address some sort of memory pressure issue since it basically just > means the allocation can go out and try to free other memory. Yes, I'm no MM expert, but I've seen plenty of times messages from the MM folks that ATOMIC shouldn't be used in non-atomic contexts. Atomic allocation is able to grab memory from some sort of critical reservs and all that, and the less we touch them, the better. Outside of atomic contexts they should not be touched. > >> 4. 1 budget unit == 1 descriptor, not skb. >> There could be underflow when receiving a lot of fragmented frames. >> If each of them would consist of 2 frags, it means that we'd process >> 64 descriptors at the point where we pass the 32th skb to the stack. >> But the driver would count that only as a half, which could make NAPI >> re-enable interrupts prematurely and create unnecessary CPU load. > > Not sure I agree with this. The problem is the overhead for an skb > going up the stack versus a fragment are pretty signficant. Keep in > mind that most of the overhead for a single buffer occurs w/ > napi_gro_receive and is not actually at the driver itself. The whole > point of the budget is to meter out units of work, not to keep you in > the busy loop. This starts looking like the old code where the Intel > drivers were returning either budget or 0 instead of supporting the > middle ground. No, certainly not this :D The point of budget is to limit the amount of time drivers can spend on cleaning their rings. Making skb the unit makes the unit very logical and flexible, but I'd say it should always be solid. Imagine you get a frame which got spanned across 5 buffers. You spend x5 time (roughly) to build an skb and pass it up the stack vs when you get a linear frame in one buffer, but according to your logics both of these cases count as 1 unit, while the amount of time spent differs significantly. I can't say that's fair enough. > >> 5. Shortcut !size case. >> It's super rare, but possible -- for example, if the last buffer of >> the fragmented frame contained only FCS, which was then stripped by >> the HW. Instead of checking for size several times when processing, >> quickly reuse the buffer and jump to the skb fields part. >> 6. Refill the ring after finishing the polling loop. >> Previously, the loop wasn't starting a new iteration after the 64th >> desc, meaning that we were always leaving 16 buffers non-refilled >> until the next NAPI poll. It's better to refill them while they're >> still hot, so do that right after exiting the loop as well. >> For a full cycle of 64 descs, there will be 4 refills of 16 descs >> from now on. >> >> Function: add/remove: 4/2 grow/shrink: 0/5 up/down: 473/-647 (-174) >> >> + up to 2% performance. >> > > What is the test you saw the 2% performance improvement in? Is it > something XDP related or a full stack test? Not XDP, it's not present in this driver at this point :D Stack test, but without usercopy overhead. Trafgen bombs the NIC, the driver builds skbs and passes it up the stack, the stack does GRO etc, and then the frames get dropped on IP input because there's no socket. > >> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com> > > Also one thing I am not a huge fan of is a patch that is really a > patchset onto itself. With all 6 items called out here I would have > preferred to see this as 6 patches as it would have been easier to > review. Agree BTW, I'm not a fan of this patch either. I wasn't sure what to do with it, as splitting it into 6 explodes the series into a monster, but proceeding without it increases diffstat and complicates things later on. I'll try the latter, but will see. 17 patches is not the End of Days after all. > >> --- >> drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +- >> drivers/net/ethernet/intel/iavf/iavf_txrx.c | 259 +++++++++----------- >> drivers/net/ethernet/intel/iavf/iavf_txrx.h | 3 +- >> 3 files changed, 114 insertions(+), 150 deletions(-) [...] >> @@ -943,23 +945,17 @@ bool iavf_alloc_rx_buffers(struct iavf_ring *rx_ring, u16 cleaned_count) >> >> /* clear the status bits for the next_to_use descriptor */ >> rx_desc->wb.qword1.status_error_len = 0; >> - >> - cleaned_count--; >> - } while (cleaned_count); >> + } while (--to_refill); > > Just a nit. You might want to break this up into two statements like I > had before. I know some people within Intel weren't a huge fan of when > I used to do that kind of thing all the time in loops where I would do > the decrement and test in one line.. :) Should I please them or do it as I want to? :D I realize from the compiler's PoV it's most likely the same, but dunno, why not. > >> >> if (rx_ring->next_to_use != ntu) >> iavf_release_rx_desc(rx_ring, ntu); >> >> - return false; [...] >> /* if we are the last buffer then there is nothing else to do */ >> #define IAVF_RXD_EOF BIT(IAVF_RX_DESC_STATUS_EOF_SHIFT) >> if (likely(iavf_test_staterr(rx_desc, IAVF_RXD_EOF))) > > You may want to see if you can get rid of this function entirely, > perhaps you do in a later patch. This function was added for ixgbe back > in the day to allow us to place the skb back in the ring for the RSC > based workloads where we had to deal with interleaved frames in the Rx > path. > > For example, one question here would be why are we passing skb? It > isn't used as far as I can tell. Yes, I'm optimizing all this out later in the series. I was surprised just as much as you when I saw skb getting passed to do nothing ._. [...] Thanks for the detailed reviews, stuff that Intel often lacks :s :D Olek
WARNING: multiple messages have this Message-ID (diff)
From: Alexander Lobakin <aleksander.lobakin@intel.com> To: Alexander H Duyck <alexander.duyck@gmail.com> Cc: Paul Menzel <pmenzel@molgen.mpg.de>, Jesper Dangaard Brouer <hawk@kernel.org>, Larysa Zaremba <larysa.zaremba@intel.com>, netdev@vger.kernel.org, Ilias Apalodimas <ilias.apalodimas@linaro.org>, linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>, Eric Dumazet <edumazet@google.com>, Michal Kubiak <michal.kubiak@intel.com>, intel-wired-lan@lists.osuosl.org, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, "David S. Miller" <davem@davemloft.net>, Magnus Karlsson <magnus.karlsson@intel.com> Subject: Re: [Intel-wired-lan] [PATCH net-next v2 03/12] iavf: optimize Rx buffer allocation a bunch Date: Wed, 31 May 2023 17:13:22 +0200 [thread overview] Message-ID: <cb7d3479-63a5-31b4-355d-b12a7e1b2878@intel.com> (raw) In-Reply-To: <8828262f1c238ab28be9ec87a7701acd791af926.camel@gmail.com> From: Alexander H Duyck <alexander.duyck@gmail.com> Date: Tue, 30 May 2023 09:18:40 -0700 > On Thu, 2023-05-25 at 14:57 +0200, Alexander Lobakin wrote: >> The Rx hotpath code of IAVF is not well-optimized TBH. Before doing any >> further buffer model changes, shake it up a bit. Notably: >> >> 1. Cache more variables on the stack. >> DMA device, Rx page size, NTC -- these are the most common things >> used all throughout the hotpath, often in loops on each iteration. >> Instead of fetching (or even calculating, as with the page size) them >> from the ring all the time, cache them on the stack at the beginning >> of the NAPI polling callback. NTC will be written back at the end, >> the rest are used read-only, so no sync needed. > > The advantage of this is going to vary based on the attribute. One of > the reasons why I left most of this on the ring is because the section > of the ring most of these variables were meant to be read-mostly and > shouldn't have resulted in any additional overhead versus accessing > them from the stack. But not all of these variables are read-only. E.g. NTC is often modified. Page size was calculated per descriptor, but could be once a poll cycle starts, and so on. > >> 2. Don't move the recycled buffers around the ring. >> The idea of passing the page of the right-now-recycled-buffer to a >> different buffer, in this case, the first one that needs to be >> allocated, moreover, on each new frame, is fundamentally wrong. It >> involves a few o' fetches, branches and then writes (and one Rx >> buffer struct is at least 32 bytes) where they're completely unneeded, >> but gives no good -- the result is the same as if we'd recycle it >> inplace, at the same position where it was used. So drop this and let >> the main refilling function take care of all the buffers, which were >> processed and now need to be recycled/refilled. > > The next_to_alloc logic was put in place to deal with systems that are > experiencing memory issues. Specifically what can end up happening is > that the ring can stall due to failing memory allocations and the > memory can get stuck on the ring. For that reason we were essentially > defragmenting the buffers when we started suffering memory pressure so > that they could be reusued and/or freed following immediate use. > > Basically what you are trading off is some exception handling for > performance by removing it. I'm not sure this helps a lot, but OTOH this really slows down things, esp. given that this code is run all the time, not only when a memory allocation fail happens. > >> 3. Don't allocate with %GPF_ATOMIC on ifup. >> This involved introducing the @gfp parameter to a couple functions. >> Doesn't change anything for Rx -> softirq. > > Any specific reason for this? Just wondering if this is meant to > address some sort of memory pressure issue since it basically just > means the allocation can go out and try to free other memory. Yes, I'm no MM expert, but I've seen plenty of times messages from the MM folks that ATOMIC shouldn't be used in non-atomic contexts. Atomic allocation is able to grab memory from some sort of critical reservs and all that, and the less we touch them, the better. Outside of atomic contexts they should not be touched. > >> 4. 1 budget unit == 1 descriptor, not skb. >> There could be underflow when receiving a lot of fragmented frames. >> If each of them would consist of 2 frags, it means that we'd process >> 64 descriptors at the point where we pass the 32th skb to the stack. >> But the driver would count that only as a half, which could make NAPI >> re-enable interrupts prematurely and create unnecessary CPU load. > > Not sure I agree with this. The problem is the overhead for an skb > going up the stack versus a fragment are pretty signficant. Keep in > mind that most of the overhead for a single buffer occurs w/ > napi_gro_receive and is not actually at the driver itself. The whole > point of the budget is to meter out units of work, not to keep you in > the busy loop. This starts looking like the old code where the Intel > drivers were returning either budget or 0 instead of supporting the > middle ground. No, certainly not this :D The point of budget is to limit the amount of time drivers can spend on cleaning their rings. Making skb the unit makes the unit very logical and flexible, but I'd say it should always be solid. Imagine you get a frame which got spanned across 5 buffers. You spend x5 time (roughly) to build an skb and pass it up the stack vs when you get a linear frame in one buffer, but according to your logics both of these cases count as 1 unit, while the amount of time spent differs significantly. I can't say that's fair enough. > >> 5. Shortcut !size case. >> It's super rare, but possible -- for example, if the last buffer of >> the fragmented frame contained only FCS, which was then stripped by >> the HW. Instead of checking for size several times when processing, >> quickly reuse the buffer and jump to the skb fields part. >> 6. Refill the ring after finishing the polling loop. >> Previously, the loop wasn't starting a new iteration after the 64th >> desc, meaning that we were always leaving 16 buffers non-refilled >> until the next NAPI poll. It's better to refill them while they're >> still hot, so do that right after exiting the loop as well. >> For a full cycle of 64 descs, there will be 4 refills of 16 descs >> from now on. >> >> Function: add/remove: 4/2 grow/shrink: 0/5 up/down: 473/-647 (-174) >> >> + up to 2% performance. >> > > What is the test you saw the 2% performance improvement in? Is it > something XDP related or a full stack test? Not XDP, it's not present in this driver at this point :D Stack test, but without usercopy overhead. Trafgen bombs the NIC, the driver builds skbs and passes it up the stack, the stack does GRO etc, and then the frames get dropped on IP input because there's no socket. > >> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com> > > Also one thing I am not a huge fan of is a patch that is really a > patchset onto itself. With all 6 items called out here I would have > preferred to see this as 6 patches as it would have been easier to > review. Agree BTW, I'm not a fan of this patch either. I wasn't sure what to do with it, as splitting it into 6 explodes the series into a monster, but proceeding without it increases diffstat and complicates things later on. I'll try the latter, but will see. 17 patches is not the End of Days after all. > >> --- >> drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +- >> drivers/net/ethernet/intel/iavf/iavf_txrx.c | 259 +++++++++----------- >> drivers/net/ethernet/intel/iavf/iavf_txrx.h | 3 +- >> 3 files changed, 114 insertions(+), 150 deletions(-) [...] >> @@ -943,23 +945,17 @@ bool iavf_alloc_rx_buffers(struct iavf_ring *rx_ring, u16 cleaned_count) >> >> /* clear the status bits for the next_to_use descriptor */ >> rx_desc->wb.qword1.status_error_len = 0; >> - >> - cleaned_count--; >> - } while (cleaned_count); >> + } while (--to_refill); > > Just a nit. You might want to break this up into two statements like I > had before. I know some people within Intel weren't a huge fan of when > I used to do that kind of thing all the time in loops where I would do > the decrement and test in one line.. :) Should I please them or do it as I want to? :D I realize from the compiler's PoV it's most likely the same, but dunno, why not. > >> >> if (rx_ring->next_to_use != ntu) >> iavf_release_rx_desc(rx_ring, ntu); >> >> - return false; [...] >> /* if we are the last buffer then there is nothing else to do */ >> #define IAVF_RXD_EOF BIT(IAVF_RX_DESC_STATUS_EOF_SHIFT) >> if (likely(iavf_test_staterr(rx_desc, IAVF_RXD_EOF))) > > You may want to see if you can get rid of this function entirely, > perhaps you do in a later patch. This function was added for ixgbe back > in the day to allow us to place the skb back in the ring for the RSC > based workloads where we had to deal with interleaved frames in the Rx > path. > > For example, one question here would be why are we passing skb? It > isn't used as far as I can tell. Yes, I'm optimizing all this out later in the series. I was surprised just as much as you when I saw skb getting passed to do nothing ._. [...] Thanks for the detailed reviews, stuff that Intel often lacks :s :D Olek _______________________________________________ Intel-wired-lan mailing list Intel-wired-lan@osuosl.org https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
next prev parent reply other threads:[~2023-05-31 15:15 UTC|newest] Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-25 12:57 [Intel-wired-lan] [PATCH net-next v2 00/12] net: intel: start The Great Code Dedup + Page Pool for iavf Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 01/12] net: intel: introduce Intel Ethernet common library Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 02/12] iavf: kill "legacy-rx" for good Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-30 15:29 ` Alexander H Duyck 2023-05-30 15:29 ` [Intel-wired-lan] " Alexander H Duyck 2023-05-30 16:22 ` Alexander Lobakin 2023-05-30 16:22 ` [Intel-wired-lan] " Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 03/12] iavf: optimize Rx buffer allocation a bunch Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-30 16:18 ` Alexander H Duyck 2023-05-30 16:18 ` [Intel-wired-lan] " Alexander H Duyck 2023-05-31 11:14 ` Maciej Fijalkowski 2023-05-31 11:14 ` [Intel-wired-lan] " Maciej Fijalkowski 2023-05-31 15:22 ` Alexander Lobakin 2023-05-31 15:22 ` [Intel-wired-lan] " Alexander Lobakin 2023-05-31 15:13 ` Alexander Lobakin [this message] 2023-05-31 15:13 ` Alexander Lobakin 2023-05-31 17:22 ` Alexander Duyck 2023-06-02 13:58 ` Alexander Lobakin 2023-06-02 13:58 ` Alexander Lobakin 2023-06-02 15:04 ` Alexander Duyck 2023-06-02 15:04 ` Alexander Duyck 2023-06-02 16:15 ` Alexander Lobakin 2023-06-02 16:15 ` Alexander Lobakin 2023-06-02 17:50 ` Alexander Duyck 2023-06-02 17:50 ` Alexander Duyck 2023-06-06 12:47 ` Alexander Lobakin 2023-06-06 12:47 ` Alexander Lobakin 2023-06-06 14:24 ` Alexander Duyck 2023-06-06 14:24 ` Alexander Duyck 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 04/12] iavf: remove page splitting/recycling Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 05/12] iavf: always use a full order-0 page Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-26 8:57 ` David Laight 2023-05-26 8:57 ` [Intel-wired-lan] " David Laight 2023-05-26 12:52 ` Alexander Lobakin 2023-05-26 12:52 ` [Intel-wired-lan] " Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 06/12] net: skbuff: don't include <net/page_pool.h> into <linux/skbuff.h> Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-27 3:54 ` Jakub Kicinski 2023-05-27 3:54 ` [Intel-wired-lan] " Jakub Kicinski 2023-05-30 13:12 ` Alexander Lobakin 2023-05-30 13:12 ` [Intel-wired-lan] " Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 07/12] net: page_pool: avoid calling no-op externals when possible Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 08/12] net: page_pool: add DMA-sync-for-CPU inline helpers Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 09/12] iavf: switch to Page Pool Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 10/12] libie: add common queue stats Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 11/12] libie: add per-queue Page Pool stats Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin 2023-05-25 12:57 ` [Intel-wired-lan] [PATCH net-next v2 12/12] iavf: switch queue stats to libie Alexander Lobakin 2023-05-25 12:57 ` Alexander Lobakin
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=cb7d3479-63a5-31b4-355d-b12a7e1b2878@intel.com \ --to=aleksander.lobakin@intel.com \ --cc=alexander.duyck@gmail.com \ --cc=davem@davemloft.net \ --cc=edumazet@google.com \ --cc=hawk@kernel.org \ --cc=hch@lst.de \ --cc=ilias.apalodimas@linaro.org \ --cc=intel-wired-lan@lists.osuosl.org \ --cc=kuba@kernel.org \ --cc=larysa.zaremba@intel.com \ --cc=linux-kernel@vger.kernel.org \ --cc=magnus.karlsson@intel.com \ --cc=michal.kubiak@intel.com \ --cc=netdev@vger.kernel.org \ --cc=pabeni@redhat.com \ --cc=pmenzel@molgen.mpg.de \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.