All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 1/3] net: factor out a helper to decrement the skb refcount
Date: Mon, 29 May 2017 17:27:23 +0200	[thread overview]
Message-ID: <d8ae2b225a566fb1addf970db79cbcea834b4ad0.1496070490.git.pabeni@redhat.com> (raw)
In-Reply-To: <cover.1496070490.git.pabeni@redhat.com>

The same code is replicated in 3 different places; move it to a
common helper.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 include/linux/skbuff.h | 13 +++++++++++++
 net/core/datagram.c    |  4 +---
 net/core/skbuff.c      | 14 ++++----------
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 45a59c1..3c25fca 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -867,6 +867,19 @@ static inline unsigned int skb_napi_id(const struct sk_buff *skb)
 #endif
 }
 
+/* decrement the reference count and return true if we can free the skb */
+static inline bool skb_unref(struct sk_buff *skb)
+{
+	if (unlikely(!skb))
+		return false;
+	if (likely(atomic_read(&skb->users) == 1))
+		smp_rmb();
+	else if (likely(!atomic_dec_and_test(&skb->users)))
+		return false;
+
+	return true;
+}
+
 void kfree_skb(struct sk_buff *skb);
 void kfree_skb_list(struct sk_buff *segs);
 void skb_tx_error(struct sk_buff *skb);
diff --git a/net/core/datagram.c b/net/core/datagram.c
index bc46118..e5311a7 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -330,9 +330,7 @@ void __skb_free_datagram_locked(struct sock *sk, struct sk_buff *skb, int len)
 {
 	bool slow;
 
-	if (likely(atomic_read(&skb->users) == 1))
-		smp_rmb();
-	else if (likely(!atomic_dec_and_test(&skb->users))) {
+	if (!skb_unref(skb)) {
 		sk_peek_offset_bwd(sk, len);
 		return;
 	}
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 780b7c1..c81b828 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -694,12 +694,9 @@ EXPORT_SYMBOL(__kfree_skb);
  */
 void kfree_skb(struct sk_buff *skb)
 {
-	if (unlikely(!skb))
-		return;
-	if (likely(atomic_read(&skb->users) == 1))
-		smp_rmb();
-	else if (likely(!atomic_dec_and_test(&skb->users)))
+	if (!skb_unref(skb))
 		return;
+
 	trace_kfree_skb(skb, __builtin_return_address(0));
 	__kfree_skb(skb);
 }
@@ -746,12 +743,9 @@ EXPORT_SYMBOL(skb_tx_error);
  */
 void consume_skb(struct sk_buff *skb)
 {
-	if (unlikely(!skb))
-		return;
-	if (likely(atomic_read(&skb->users) == 1))
-		smp_rmb();
-	else if (likely(!atomic_dec_and_test(&skb->users)))
+	if (!skb_unref(skb))
 		return;
+
 	trace_consume_skb(skb);
 	__kfree_skb(skb);
 }
-- 
2.9.4

  reply	other threads:[~2017-05-29 15:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-29 15:27 [PATCH net-next 0/3] udp: reduce cache pressure Paolo Abeni
2017-05-29 15:27 ` Paolo Abeni [this message]
2017-05-31 16:56   ` [PATCH net-next 1/3] net: factor out a helper to decrement the skb refcount Eric Dumazet
2017-05-29 15:27 ` [PATCH net-next 2/3] udp: avoid a cache miss on dequeue Paolo Abeni
2017-05-31 17:00   ` Eric Dumazet
2017-06-01 10:39     ` Paolo Abeni
2017-06-01 15:58       ` Eric Dumazet
2017-06-01 16:21         ` Paolo Abeni
2017-06-01 16:40           ` Eric Dumazet
2017-06-01 20:35             ` Paolo Abeni
2017-06-01 20:50               ` Eric Dumazet
2017-05-29 15:27 ` [PATCH net-next 3/3] udp: try to avoid 2 " Paolo Abeni
2017-05-31 17:04   ` Eric Dumazet
2017-06-01 10:46     ` Paolo Abeni
2017-06-07  2:12   ` [lkp-robot] [udp] bc0d3d0639: apachebench.requests_per_second -21% regression kernel test robot
2017-06-07  2:12     ` kernel test robot
2017-06-07 21:40     ` Paolo Abeni
2017-06-09 15:35       ` Paolo Abeni
2017-06-30  6:55         ` Ye Xiaolong
2017-05-31 16:47 ` [PATCH net-next 0/3] udp: reduce cache pressure David Miller
2017-05-31 16:52   ` Eric Dumazet

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=d8ae2b225a566fb1addf970db79cbcea834b4ad0.1496070490.git.pabeni@redhat.com \
    --to=pabeni@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    /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: link
Be 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.