RE:Query on skb buffer (Kumar amit mehta)
-----Original Message----- From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies- bounces@kernelnewbies.org] On Behalf Of kernelnewbies- request@kernelnewbies.org Sent: Thursday, March 07, 2013 8:52 AM To: kernelnewbies@kernelnewbies.org Subject: Kernelnewbies Digest, Vol 28, Issue 12
Send Kernelnewbies mailing list submissions to kernelnewbies@kernelnewbies.org
To subscribe or unsubscribe via the World Wide Web, visit http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies or, via email, send a message with subject or body 'help' to kernelnewbies-request@kernelnewbies.org
You can reach the person managing the list at kernelnewbies-owner@kernelnewbies.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Kernelnewbies digest..."
Today's Topics:
1. Query on skb buffer (Kumar amit mehta) 2. Re: Query on skb buffer (Valdis.Kletnieks@vt.edu) 3. Several unrelated beginner questions. (Konstantin Kowalski) 4. Re: Several unrelated beginner questions. (Gaurav Jain) 5. Re: Several unrelated beginner questions. (Valdis.Kletnieks@vt.edu) 6. zap_low_mappings (ishare) 7. Re: zap_low_mappings (Valdis.Kletnieks@vt.edu)
----------------------------------------------------------------------
Message: 1 Date: Wed, 6 Mar 2013 10:39:13 -0800 From: Kumar amit mehta <gmate.amit@gmail.com> Subject: Query on skb buffer To: kernelnewbies@kernelnewbies.org Message-ID: <20130306183913.GA3328@gmail.com> Content-Type: text/plain; charset=us-ascii
My current understanding is that the skb, while being passed along various layers in linux network stack, will be manipulated majorly, using the skb->{head|data|tail|end|len} fields.
Suppose that my application (say 'ping') sends a ICMP echo request with a large packet size of 4k, i.e. $ ping -s 4096 <dest addr> Now, if alloc_skb(4096, GFP_KERNEL) is the routine that gets called to allocate the kernel buffer then, how does the kernel manages such prospective memory allocation failures and how kernel manages large packet requests from the application.
-Amit [Pranay Kumar Srivastava] Perhaps you should've a look at linear and non-linear data (skb_frags to be specific). That's how large data is handled however I don't think you'll be doing that with ICMP or UDP. Reading directly from skbuffs for UDP would also give you header information however with TCP it doesn't. So unless there's any need for it perhaps it can be done in userland or use sock_sendmsg or sendfile (for zero copy). --P.K.S
------------------------------
Message: 2 Date: Wed, 06 Mar 2013 14:32:27 -0500 From: Valdis.Kletnieks@vt.edu Subject: Re: Query on skb buffer To: Kumar amit mehta <gmate.amit@gmail.com> Cc: kernelnewbies@kernelnewbies.org Message-ID: <9932.1362598347@turing-police.cc.vt.edu> Content-Type: text/plain; charset="us-ascii"
On Wed, 06 Mar 2013 10:39:13 -0800, Kumar amit mehta said:
Now, if alloc_skb(4096, GFP_KERNEL) is the routine that gets called to allocate the kernel buffer then, how does the kernel manages such prospective memory allocation failures and how kernel manages large packet requests from the application.
Did you actually look at the source for use of alloc_skb() and how it handles error returns?
(Hint - the kernel doesn't do the same thing at every use of alloc_skb(), because an allocation failure needs to be handled differently depending on where it happens. At some places, just bailing out and dropping the packet on the floor without any notification to anybody is appropriate. At other places, we need to propagate an error condition to the caller).
Typical pattern (from net/core/sock.c:)
/* * Allocate a skb from the socket's send buffer. */ struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force, gfp_t priority) { if (force || atomic_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf) { struct sk_buff *skb = alloc_skb(size, priority); if (skb) { skb_set_owner_w(skb, sk); return skb; } } return NULL; } EXPORT_SYMBOL(sock_wmalloc);
and then the caller does something like this (net/ipv4/ip_output.c, in function __ip_append_data():
} else { skb = NULL; if (atomic_read(&sk->sk_wmem_alloc) <= 2 * sk->sk_sndbuf) skb = sock_wmalloc(sk, alloclen + hh_len + 15, 1, sk->sk_allocation); if (unlikely(skb == NULL)) err = -ENOBUFS; else /* only the initial fragment is time stamped */ cork->tx_flags = 0; } if (skb == NULL) goto error;
participants (1)
-
Pranay Kumar Srivastava