[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1389914224-10453-4-git-send-email-dbanerje@akamai.com>
Date: Thu, 16 Jan 2014 18:17:04 -0500
From: Debabrata Banerjee <dbanerje@...mai.com>
To: eric.dumazet@...il.com, fw@...len.de, netdev@...r.kernel.org
Cc: dbanerje@...mai.com, johunt@...mai.com, jbaron@...mai.com,
davem@...emloft.net, linux-mm@...ck.org
Subject: [RFC PATCH 3/3] Use slab allocations for sk page_frag send buffers
---
net/core/sock.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index 6565431..dbbd2f9 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1792,10 +1792,12 @@ EXPORT_SYMBOL(sock_alloc_send_skb);
/* On 32bit arches, an skb frag is limited to 2^15 */
#define SKB_FRAG_PAGE_ORDER get_order(32768)
+struct kmem_cache *sk_page_frag_cache;
bool sk_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
{
int order;
+ gfp_t gfp_mask = sk->sk_allocation;
if (pfrag->page) {
if (atomic_read(&pfrag->page->_count) == 1) {
@@ -1807,21 +1809,25 @@ bool sk_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
put_page(pfrag->page);
}
- /* We restrict high order allocations to users that can afford to wait */
- order = (sk->sk_allocation & __GFP_WAIT) ? SKB_FRAG_PAGE_ORDER : 0;
+ order = SKB_FRAG_PAGE_ORDER;
- do {
- gfp_t gfp = sk->sk_allocation;
-
- if (order)
- gfp |= __GFP_COMP | __GFP_NOWARN;
- pfrag->page = alloc_pages(gfp, order);
- if (likely(pfrag->page)) {
+ if (order > 0) {
+ void *kmem = kmem_cache_alloc(sk_page_frag_cache, gfp_mask | __GFP_NOWARN);
+ if (likely(kmem)) {
+ pfrag->page = virt_to_page(kmem);
pfrag->offset = 0;
pfrag->size = PAGE_SIZE << order;
return true;
}
- } while (--order >= 0);
+ }
+
+ pfrag->page = alloc_page(gfp_mask);
+
+ if (likely(pfrag->page)) {
+ pfrag->offset = 0;
+ pfrag->size = PAGE_SIZE;
+ return true;
+ }
sk_enter_memory_pressure(sk);
sk_stream_moderate_sndbuf(sk);
@@ -2822,13 +2828,18 @@ static __net_init int proto_init_net(struct net *net)
{
if (!proc_create("protocols", S_IRUGO, net->proc_net, &proto_seq_fops))
return -ENOMEM;
-
+ sk_page_frag_cache = kmem_cache_create("sk_page_frag_cache",
+ PAGE_SIZE << SKB_FRAG_PAGE_ORDER,
+ PAGE_SIZE,
+ SLAB_HWCACHE_ALIGN,
+ NULL);
return 0;
}
static __net_exit void proto_exit_net(struct net *net)
{
remove_proc_entry("protocols", net->proc_net);
+ kmem_cache_destroy(sk_page_frag_cache);
}
--
1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists