Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Dumazet
Date: Wednesday, June 3, 2009 - 9:54 pm

David Miller a écrit :

Agreed.

We also can avoid the sock_put()/sock_hold() pair for each tx packet,
to only touch sk_wmem_alloc (with appropriate atomic_sub_return() in sock_wfree()
and atomic_dec_test in sk_free

We could initialize sk->sk_wmem_alloc to one instead of 0, so that
sock_wfree() could just synchronize itself with sk_free()

void sk_free(struct sock *sk)
{
	if (atomic_dec_test(&sk->sk_wmem_alloc))
		__sk_free(sk)
}

 static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk)
 {
-       sock_hold(sk);
        skb->sk = sk;
        skb->destructor = sock_wfree;
        atomic_add(skb->truesize, &sk->sk_wmem_alloc);
 }

 void sock_wfree(struct sk_buff *skb)
 {
        struct sock *sk = skb->sk;
+       int res;

        /* In case it might be waiting for more memory. */
-       atomic_sub(skb->truesize, &sk->sk_wmem_alloc);
+       res = atomic_sub_return(skb->truesize, &sk->sk_wmem_alloc);
        if (!sock_flag(sk, SOCK_USE_WRITE_QUEUE))
                sk->sk_write_space(sk);
-       sock_put(sk);
+       if (res == 0)
+               __sk_free(sk);
 }

Patch will follow after some testing

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, Rusty Russell, (Fri May 29, 7:14 am)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, Eric Dumazet, (Fri May 29, 8:11 am)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, Rusty Russell, (Mon Jun 1, 5:27 am)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, Patrick Ohly, (Mon Jun 1, 12:47 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, David Miller, (Tue Jun 2, 12:25 am)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, Rusty Russell, (Tue Jun 2, 7:08 am)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, David Miller, (Tue Jun 2, 5:14 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, Eric Dumazet, (Wed Jun 3, 2:02 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, Rusty Russell, (Wed Jun 3, 8:54 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, David Miller, (Wed Jun 3, 9:00 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, Eric Dumazet, (Wed Jun 3, 9:54 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, David Miller, (Wed Jun 3, 9:56 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, David Miller, (Fri Jul 3, 8:02 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, David Miller, (Fri Jul 3, 8:13 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, David Miller, (Mon Aug 17, 6:47 pm)
Re: [PATCH 1/4] net: skb_orphan on dev_hard_start_xmit, David Miller, (Tue Aug 18, 8:34 pm)