Module Name: src Committed By: msaitoh Date: Wed Sep 8 08:46:29 UTC 2021
Modified Files: src/sys/dev/pci/ixgbe: ix_txrx.c Log Message: Don't pre-allocate a cluster not to do m_freem() it on RXCOPY case. To generate a diff of this commit: cvs rdiff -u -r1.92 -r1.93 src/sys/dev/pci/ixgbe/ix_txrx.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/ixgbe/ix_txrx.c diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.92 src/sys/dev/pci/ixgbe/ix_txrx.c:1.93 --- src/sys/dev/pci/ixgbe/ix_txrx.c:1.92 Tue Sep 7 08:17:20 2021 +++ src/sys/dev/pci/ixgbe/ix_txrx.c Wed Sep 8 08:46:28 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ix_txrx.c,v 1.92 2021/09/07 08:17:20 msaitoh Exp $ */ +/* $NetBSD: ix_txrx.c,v 1.93 2021/09/08 08:46:28 msaitoh Exp $ */ /****************************************************************************** @@ -64,7 +64,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.92 2021/09/07 08:17:20 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.93 2021/09/08 08:46:28 msaitoh Exp $"); #include "opt_inet.h" #include "opt_inet6.h" @@ -1837,6 +1837,7 @@ ixgbe_rxeof(struct ix_queue *que) u16 len; u16 vtag = 0; bool eop; + bool discard = false; /* Sync the ring. */ ixgbe_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map, @@ -1852,7 +1853,7 @@ ixgbe_rxeof(struct ix_queue *que) break; loopcount++; - sendmp = NULL; + sendmp = newmp = NULL; nbuf = NULL; rsc = 0; cur->wb.upper.status_error = 0; @@ -1876,15 +1877,30 @@ ixgbe_rxeof(struct ix_queue *que) goto next_desc; } - /* pre-alloc new mbuf */ - if (!discard_multidesc) { - newmp = ixgbe_getcl(); - if (__predict_false(newmp == NULL)) - rxr->no_mbuf.ev_count++; - } else - newmp = NULL; + if (__predict_false(discard_multidesc)) + discard = true; + else { + /* Pre-alloc new mbuf. */ + + if ((rbuf->fmp == NULL) && + eop && (len <= adapter->rx_copy_len)) { + /* For short packet. See below. */ + sendmp = m_gethdr(M_NOWAIT, MT_DATA); + if (__predict_false(sendmp == NULL)) { + rxr->no_mbuf.ev_count++; + discard = true; + } + } else { + /* For long packet. */ + newmp = ixgbe_getcl(); + if (__predict_false(newmp == NULL)) { + rxr->no_mbuf.ev_count++; + discard = true; + } + } + } - if (__predict_false(newmp == NULL)) { + if (__predict_false(discard)) { /* * Descriptor initialization is already done by the * above code (cur->wb.upper.status_error = 0). @@ -1950,8 +1966,10 @@ ixgbe_rxeof(struct ix_queue *que) * See if there is a stored head * that determines what we are */ - sendmp = rbuf->fmp; - if (sendmp != NULL) { /* secondary frag */ + if (rbuf->fmp != NULL) { + /* Secondary frag */ + sendmp = rbuf->fmp; + /* Update new (used in future) mbuf */ newmp->m_pkthdr.len = newmp->m_len = rxr->mbuf_sz; IXGBE_M_ADJ(adapter, rxr, newmp); @@ -1971,35 +1989,20 @@ ixgbe_rxeof(struct ix_queue *que) * packet. */ - /* - * Optimize. This might be a small packet, maybe just - * a TCP ACK. Copy into a new mbuf, and Leave the old - * mbuf+cluster for re-use. - */ - if (eop && len <= adapter->rx_copy_len) { - sendmp = m_gethdr(M_NOWAIT, MT_DATA); - if (sendmp != NULL) { - sendmp->m_data += ETHER_ALIGN; - memcpy(mtod(sendmp, void *), - mtod(mp, void *), len); - rxr->rx_copies.ev_count++; - rbuf->flags |= IXGBE_RX_COPY; - - /* - * Free pre-allocated mbuf anymore - * because we recycle the current - * buffer. - */ - m_freem(newmp); - } - } + if (eop && (len <= adapter->rx_copy_len)) { + /* + * Optimize. This might be a small packet, may + * be just a TCP ACK. Copy into a new mbuf, and + * Leave the old mbuf+cluster for re-use. + */ + sendmp->m_data += ETHER_ALIGN; + memcpy(mtod(sendmp, void *), + mtod(mp, void *), len); + rxr->rx_copies.ev_count++; + rbuf->flags |= IXGBE_RX_COPY; + } else { + /* Non short packet */ - /* - * Two cases: - * a) non small packet(i.e. !IXGBE_RX_COPY). - * b) a small packet but the above m_gethdr() failed. - */ - if (sendmp == NULL) { /* Update new (used in future) mbuf */ newmp->m_pkthdr.len = newmp->m_len = rxr->mbuf_sz;