mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Pratt <Ian.Pratt@cl.cam.ac.uk>
To: Ian Pratt <Ian.Pratt@cl.cam.ac.uk>
Cc: linux-kernel@vger.kernel.org, Steven.Hand@cl.cam.ac.uk,
	Christian.Limpach@cl.cam.ac.uk, Keir.Fraser@cl.cam.ac.uk,
	davem@redhat.com
Subject: [6/7] Xen VMM patch set : add alloc_skb_from_cache
Date: Fri, 19 Nov 2004 23:25:07 +0000	[thread overview]
Message-ID: <E1CVI7o-0004cT-00@mta1.cl.cam.ac.uk> (raw)
In-Reply-To: Your message of "Fri, 19 Nov 2004 23:16:33 GMT." <E1CVHzW-0004XC-00@mta1.cl.cam.ac.uk>


This patch adds a new alloc_skb_from_cache function. This serves two
purposes: firstly, we like to allocate skb's with page-sized data
fragements as this means we can do zero-copy transfer of network
buffers between guest operating systems. Secondly, it enables us to
have a cache of pages that have been used for network buffers that we
can be more lax about scrubbing when they change VM ownership (since
they could be sniffed on the wire).

Signed-off-by: ian.pratt@cl.cam.ac.uk

---
diff -Nurp pristine-linux-2.6.10-rc2/net/core/skbuff.c tmp-linux-2.6.10-rc2-xen.patch/net/core/skbuff.c
--- pristine-linux-2.6.10-rc2/net/core/skbuff.c	2004-11-15 01:28:14.000000000 +0000
+++ tmp-linux-2.6.10-rc2-xen.patch/net/core/skbuff.c	2004-11-19 16:42:55.000000000 +0000
@@ -163,6 +163,59 @@ nodata:
 	goto out;
 }
 
+/**
+ *	alloc_skb_from_cache	-	allocate a network buffer
+ *	@cp: kmem_cache from which to allocate the data area
+ *	     (object size must be big enough for @size bytes + skb overheads)
+ *	@size: size to allocate
+ *	@gfp_mask: allocation mask
+ *
+ *	Allocate a new &sk_buff. The returned buffer has no headroom and a
+ *	tail room of size bytes. The object has a reference count of one.
+ *	The return is the buffer. On a failure the return is %NULL.
+ *
+ *	Buffers may only be allocated from interrupts using a @gfp_mask of
+ *	%GFP_ATOMIC.
+ */
+struct sk_buff *alloc_skb_from_cache(kmem_cache_t *cp,
+				     unsigned int size, int gfp_mask)
+{
+	struct sk_buff *skb;
+	u8 *data;
+
+	/* Get the HEAD */
+	skb = kmem_cache_alloc(skbuff_head_cache,
+			       gfp_mask & ~__GFP_DMA);
+	if (!skb)
+		goto out;
+
+	/* Get the DATA. */
+	size = SKB_DATA_ALIGN(size);
+	data = kmem_cache_alloc(cp, gfp_mask);
+	if (!data)
+		goto nodata;
+
+	memset(skb, 0, offsetof(struct sk_buff, truesize));
+	skb->truesize = size + sizeof(struct sk_buff);
+	atomic_set(&skb->users, 1);
+	skb->head = data;
+	skb->data = data;
+	skb->tail = data;
+	skb->end  = data + size;
+
+	atomic_set(&(skb_shinfo(skb)->dataref), 1);
+	skb_shinfo(skb)->nr_frags  = 0;
+	skb_shinfo(skb)->tso_size = 0;
+	skb_shinfo(skb)->tso_segs = 0;
+	skb_shinfo(skb)->frag_list = NULL;
+out:
+	return skb;
+nodata:
+	kmem_cache_free(skbuff_head_cache, skb);
+	skb = NULL;
+	goto out;
+}
+
 
 static void skb_drop_fraglist(struct sk_buff *skb)
 {
diff -Nurp pristine-linux-2.6.10-rc2/include/linux/skbuff.h tmp-linux-2.6.10-rc2-xen.patch/include/linux/skbuff.h
--- pristine-linux-2.6.10-rc2/include/linux/skbuff.h	2004-11-15 01:29:01.000000000 +0000
+++ tmp-linux-2.6.10-rc2-xen.patch/include/linux/skbuff.h	2004-11-18 19:58:13.000000000 +0000
@@ -292,6 +292,8 @@ struct sk_buff {
 
 extern void	       __kfree_skb(struct sk_buff *skb);
 extern struct sk_buff *alloc_skb(unsigned int size, int priority);
+extern struct sk_buff *alloc_skb_from_cache(kmem_cache_t *cp,
+					    unsigned int size, int priority);
 extern void	       kfree_skbmem(struct sk_buff *skb);
 extern struct sk_buff *skb_clone(struct sk_buff *skb, int priority);
 extern struct sk_buff *skb_copy(const struct sk_buff *skb, int priority);
@@ -935,6 +937,7 @@ static inline void __skb_queue_purge(str
  *
  *	%NULL is returned in there is no free memory.
  */
+#ifndef CONFIG_HAVE_ARCH_DEV_ALLOC_SKB
 static inline struct sk_buff *__dev_alloc_skb(unsigned int length,
 					      int gfp_mask)
 {
@@ -943,6 +946,9 @@ static inline struct sk_buff *__dev_allo
 		skb_reserve(skb, 16);
 	return skb;
 }
+#else
+extern struct sk_buff *__dev_alloc_skb(unsigned int length, int gfp_mask);
+#endif
 
 /**
  *	dev_alloc_skb - allocate an skbuff for sending


  parent reply	other threads:[~2004-11-19 23:30 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-19 23:16 Xen VMM patch set - take 2 Ian Pratt
2004-11-19 23:20 ` [1/7] Xen VMM patch set : add ptep_establish_new to make va available Ian Pratt
2004-11-19 23:20 ` [2/7] Xen VMM patch set : return code for arch_free_page Ian Pratt
2004-11-30  2:28   ` Andrea Arcangeli
2004-11-19 23:21 ` [3/7] Xen VMM patch set : runtime disable of VT console Ian Pratt
2004-11-19 23:22 ` [4/7] Xen VMM patch set : /dev/mem io_remap_page_range for CONFIG_XEN Ian Pratt
2004-11-20  2:03   ` William Lee Irwin III
2004-11-20 16:31   ` Christoph Hellwig
2004-11-20 18:03     ` Ian Pratt
2004-11-27 12:39       ` Ian Pratt
2004-11-27 16:51         ` Randy.Dunlap
2004-11-30  3:08   ` Andrea Arcangeli
2004-11-30  3:14     ` David S. Miller
2004-11-30  3:38     ` William Lee Irwin III
2004-11-30  8:56     ` Ian Pratt
2004-11-30  9:04       ` Arjan van de Ven
2004-11-30 12:09         ` Ian Pratt
2004-11-30 12:14           ` Arjan van de Ven
2004-11-30 12:18             ` Arjan van de Ven
2004-11-30 13:16             ` Ian Pratt
2004-11-30 18:03               ` Andrea Arcangeli
2004-12-04 23:49                 ` Ian Pratt
2004-12-05  0:40                   ` Andrea Arcangeli
2004-12-05  2:47                   ` William Lee Irwin III
2004-11-19 23:23 ` [5/7] Xen VMM patch set : split free_irq into teardown_irq Ian Pratt
2004-11-20 16:32   ` Christoph Hellwig
2004-11-20 19:20     ` Ian Pratt
2004-11-27 12:45       ` Ian Pratt
2004-11-19 23:25 ` Ian Pratt [this message]
2004-11-20  2:11   ` [6/7] Xen VMM patch set : add alloc_skb_from_cache James Morris
2004-11-20  6:03     ` Chris Wedgwood
2004-11-20  6:47       ` David S. Miller
2004-11-20 10:28       ` Keir Fraser
2004-11-20 10:33         ` Chris Wedgwood
2004-11-19 23:28 ` [7/7] Xen VMM patch set : handle fragemented skbs correctly in icmp_filter Ian Pratt
2004-11-25 15:46 ` Xen VMM patch set - take 2 Ian Pratt
2004-11-28 17:07   ` Rik van Riel

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=E1CVI7o-0004cT-00@mta1.cl.cam.ac.uk \
    --to=ian.pratt@cl.cam.ac.uk \
    --cc=Christian.Limpach@cl.cam.ac.uk \
    --cc=Keir.Fraser@cl.cam.ac.uk \
    --cc=Steven.Hand@cl.cam.ac.uk \
    --cc=davem@redhat.com \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®