netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Witten <mfwitten@gmail.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
	Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 3/3] net: skb_queue_purge(): lock/unlock the queue only once
Date: Mon, 02 Oct 2017 05:15:32 -0000	[thread overview]
Message-ID: <057dd5367241468691b2b9adbc38a3ba-mfwitten@gmail.com> (raw)
In-Reply-To: <20171001175909.4b9e53d8@xeon-e3>

On Sun, 1 Oct 2017 17:59:09 -0700, Stephen Hemminger wrote:

> On Sun, 01 Oct 2017 22:19:20 -0000 Michael Witten wrote:
>
>> +	spin_lock_irqsave(&q->lock, flags);
>> +	skb = q->next;
>> +	__skb_queue_head_init(q);
>> +	spin_unlock_irqrestore(&q->lock, flags);
>
> Other code manipulating lists uses splice operation and
> a sk_buff_head temporary on the stack. That would be easier
> to understand.
>
> 	struct sk_buf_head head;
>
> 	__skb_queue_head_init(&head);
> 	spin_lock_irqsave(&q->lock, flags);
> 	skb_queue_splice_init(q, &head);
> 	spin_unlock_irqrestore(&q->lock, flags);
>
>
>> +	while (skb != head) {
>> +		next = skb->next;
>>  		kfree_skb(skb);
>> +		skb = next;
>> +	}
>
> It would be cleaner if you could use
> skb_queue_walk_safe rather than open coding the loop.
>
> 	skb_queue_walk_safe(&head, skb,  tmp)
> 		kfree_skb(skb);

I appreciate abstraction as much as anybody, but I do not believe
that such abstractions would actually be an improvement here.

* Splice-initing seems more like an idiom than an abstraction;
  at first blush, it wouldn't be clear to me what the intention
  is.

* Such abstractions are fairly unnecessary.

    * The function as written is already so short as to be
      easily digested.

    * More to the point, this function is not some generic,
      higher-level algorithm that just happens to employ the
      socket buffer interface; rather, it is a function that
      implements part of that very interface, and may thus
      twiddle the intimate bits of these data structures
      without being accused of abusing a leaky abstraction.

* Such abstractions add overhead, if only conceptually. In this
  case, a temporary socket buffer queue allocates *3* unnecessary
  struct members, including a whole `spinlock_t' member:
  
    prev
    qlen
    lock

  It's possible that the compiler will be smart enough to leave
  those out, but I have my suspicions that it won't, not only
  given that the interface contract requires that the temporary
  socket buffer queue be properly initialized before use, but
  also because splicing into the temporary will manipulate its
  `qlen'. Yet, why worry whether optimization happens? The whole
  issue can simply be avoided by exploiting the intimate details
  that are already philosophically available to us.

  Similarly, the function `skb_queue_walk_safe' is nice, but it
  loses value both because a temporary queue loses value (as just
  described), and because it ignores the fact that legitimate
  access to the internals of these data structures allows for
  setting up the requested loop in advance; that is to say, the
  two parts of the function that we are now debating can be woven
  together more tightly than `skb_queue_walk_safe' allows.

For these reasons, I stand by the way that the patch currently
implements this function; it does exactly what is desired, no more
or less.

Sincerely,
Michael Witten

  reply	other threads:[~2017-10-02  5:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-08  5:05 [PATCH 0/3] net: TCP/IP: A few minor cleanups Michael Witten
2017-09-08  5:05 ` [PATCH 1/3] net: __sock_cmsg_send(): Remove unused parameter `msg' Michael Witten
2017-09-08  5:06 ` [PATCH 2/3] net: inet_recvmsg(): Remove unnecessary bitwise operation Michael Witten
2017-09-08  5:06 ` [PATCH 3/3] net: skb_queue_purge(): lock/unlock the list only once Michael Witten
2017-09-08 16:01   ` Eric Dumazet
2017-09-08 16:51   ` Stephen Hemminger
2017-09-09  5:50   ` [PATCH v1 3/3] net: skb_queue_purge(): lock/unlock the queue " Michael Witten
2017-09-09 16:52     ` Eric Dumazet
2017-10-01 22:19   ` [PATCH net " Michael Witten
2017-10-02  0:59     ` Stephen Hemminger
2017-10-02  5:15       ` Michael Witten [this message]
2017-10-02 14:55         ` Stephen Hemminger
2017-10-01 22:19 ` [PATCH net 0/3] net: TCP/IP: A few minor cleanups Michael Witten
2017-10-01 22:19   ` [PATCH net 1/3] net: __sock_cmsg_send(): Remove unused parameter `msg' Michael Witten
2017-10-01 22:19   ` [PATCH net 2/3] net: inet_recvmsg(): Remove unnecessary bitwise operation Michael Witten
2018-02-06  0:54   ` Please apply these tiny, 4-month-old patches Michael Witten
2018-02-06  1:12     ` David Miller
2018-02-06  1:31       ` Michael Witten
2018-02-06  1:42         ` Andrew Lunn
2018-02-06  2:19           ` Michael Witten
2018-02-06 12:58             ` Andrew Lunn

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=057dd5367241468691b2b9adbc38a3ba-mfwitten@gmail.com \
    --to=mfwitten@gmail.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    --cc=yoshfuji@linux-ipv6.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).