Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1519207

[mm PATCH v3 23/23] igb: Update code to better handle incrementing page count

From Alexander Duyck <alexander.h.duyck@intel.com>
Newsgroups linux.kernel
Subject [mm PATCH v3 23/23] igb: Update code to better handle incrementing page count
Date 2016-11-10 18:40 +0100
Message-ID <sC1ur-MX-77@gated-at.bofh.it> (permalink)
References <sC1up-MX-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This patch updates the driver code so that we do bulk updates of the page
reference count instead of just incrementing it by one reference at a time.
The advantage to doing this is that we cut down on atomic operations and
this in turn should give us a slight improvement in cycles per packet.  In
addition if we eventually move this over to using build_skb the gains will
be more noticeable.

Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
---
 drivers/net/ethernet/intel/igb/igb.h      |    7 ++++++-
 drivers/net/ethernet/intel/igb/igb_main.c |   24 +++++++++++++++++-------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index 5387b3a..786de01 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -210,7 +210,12 @@ struct igb_tx_buffer {
 struct igb_rx_buffer {
 	dma_addr_t dma;
 	struct page *page;
-	unsigned int page_offset;
+#if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
+	__u32 page_offset;
+#else
+	__u16 page_offset;
+#endif
+	__u16 pagecnt_bias;
 };
 
 struct igb_tx_queue_stats {
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index ba97392..f5a9fd6 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -3937,7 +3937,8 @@ static void igb_clean_rx_ring(struct igb_ring *rx_ring)
 				     PAGE_SIZE,
 				     DMA_FROM_DEVICE,
 				     DMA_ATTR_SKIP_CPU_SYNC);
-		__free_page(buffer_info->page);
+		__page_frag_drain(buffer_info->page, 0,
+				  buffer_info->pagecnt_bias);
 
 		buffer_info->page = NULL;
 	}
@@ -6813,13 +6814,15 @@ static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
 				  struct page *page,
 				  unsigned int truesize)
 {
+	unsigned int pagecnt_bias = rx_buffer->pagecnt_bias--;
+
 	/* avoid re-using remote pages */
 	if (unlikely(igb_page_is_reserved(page)))
 		return false;
 
 #if (PAGE_SIZE < 8192)
 	/* if we are only owner of page we can reuse it */
-	if (unlikely(page_count(page) != 1))
+	if (unlikely(page_ref_count(page) != pagecnt_bias))
 		return false;
 
 	/* flip page offset to other buffer */
@@ -6832,10 +6835,14 @@ static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
 		return false;
 #endif
 
-	/* Even if we own the page, we are not allowed to use atomic_set()
-	 * This would break get_page_unless_zero() users.
+	/* If we have drained the page fragment pool we need to update
+	 * the pagecnt_bias and page count so that we fully restock the
+	 * number of references the driver holds.
 	 */
-	page_ref_inc(page);
+	if (unlikely(pagecnt_bias == 1)) {
+		page_ref_add(page, USHRT_MAX);
+		rx_buffer->pagecnt_bias = USHRT_MAX;
+	}
 
 	return true;
 }
@@ -6887,7 +6894,6 @@ static bool igb_add_rx_frag(struct igb_ring *rx_ring,
 			return true;
 
 		/* this page cannot be reused so discard it */
-		__free_page(page);
 		return false;
 	}
 
@@ -6958,10 +6964,13 @@ static struct sk_buff *igb_fetch_rx_buffer(struct igb_ring *rx_ring,
 		/* hand second half of page back to the ring */
 		igb_reuse_rx_page(rx_ring, rx_buffer);
 	} else {
-		/* we are not reusing the buffer so unmap it */
+		/* We are not reusing the buffer so unmap it and free
+		 * any references we are holding to it
+		 */
 		dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
 				     PAGE_SIZE, DMA_FROM_DEVICE,
 				     DMA_ATTR_SKIP_CPU_SYNC);
+		__page_frag_drain(page, 0, rx_buffer->pagecnt_bias);
 	}
 
 	/* clear contents of rx_buffer */
@@ -7235,6 +7244,7 @@ static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
 	bi->dma = dma;
 	bi->page = page;
 	bi->page_offset = 0;
+	bi->pagecnt_bias = 1;
 
 	return true;
 }

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[mm PATCH v3 00/23] Add support for DMA writable pages being  writable by the network stack Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
  [mm PATCH v3 19/23] arch/xtensa: Add option to skip DMA sync as a  part of mapping Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
  [mm PATCH v3 08/23] arch/m68k: Add option to skip DMA sync as a  part of mapping Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
  [mm PATCH v3 17/23] arch/sparc: Add option to skip DMA sync as a  part of map and unmap Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
  [mm PATCH v3 23/23] igb: Update code to better handle incrementing  page count Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
  [mm PATCH v3 03/23] arch/avr32: Add option to skip sync on DMA map Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
  [mm PATCH v3 15/23] arch/powerpc: Add option to skip DMA sync as a  part of mapping Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
  [mm PATCH v3 12/23] arch/nios2: Add option to skip DMA sync as a  part of map and unmap Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
    Re: [mm PATCH v3 12/23] arch/nios2: Add option to skip DMA sync as a  part of map and unmap Tobias Klauser <tklauser@distanz.ch> - 2016-11-11 12:00 +0100
  [mm PATCH v3 10/23] arch/microblaze: Add option to skip DMA sync as  a part of map and unmap Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:40 +0100
  [mm PATCH v3 04/23] arch/blackfin: Add option to skip sync on DMA  map Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:50 +0100
  [mm PATCH v3 16/23] arch/sh: Add option to skip DMA sync as a part  of mapping Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:50 +0100
  [mm PATCH v3 05/23] arch/c6x: Add option to skip sync on DMA map  and unmap Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:50 +0100
  [mm PATCH v3 13/23] arch/openrisc: Add option to skip DMA sync as a  part of mapping Alexander Duyck <alexander.h.duyck@intel.com> - 2016-11-10 18:50 +0100

csiph-web