Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 315175
b: refs/heads/master
c: 540eb7b
h: refs/heads/master
i:
  315173: b710d31
  315171: 2bdd221
  315167: f5c0e2a
v: v3
  • Loading branch information
Alexander Duyck authored and David S. Miller committed Jul 13, 2012
1 parent 62f8235 commit 755be2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 391e5c22f5f4e55817f8ba18a08ea717ed2d4a1f
refs/heads/master: 540eb7bf0bbedb65277d68ab89ae43cdec3fd6ba
28 changes: 20 additions & 8 deletions trunk/net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,12 @@ EXPORT_SYMBOL(build_skb);
struct netdev_alloc_cache {
struct page *page;
unsigned int offset;
unsigned int pagecnt_bias;
};
static DEFINE_PER_CPU(struct netdev_alloc_cache, netdev_alloc_cache);

#define NETDEV_PAGECNT_BIAS (PAGE_SIZE / SMP_CACHE_BYTES)

/**
* netdev_alloc_frag - allocate a page fragment
* @fragsz: fragment size
Expand All @@ -317,17 +320,26 @@ void *netdev_alloc_frag(unsigned int fragsz)
if (unlikely(!nc->page)) {
refill:
nc->page = alloc_page(GFP_ATOMIC | __GFP_COLD);
if (unlikely(!nc->page))
goto end;
recycle:
atomic_set(&nc->page->_count, NETDEV_PAGECNT_BIAS);
nc->pagecnt_bias = NETDEV_PAGECNT_BIAS;
nc->offset = 0;
}
if (likely(nc->page)) {
if (nc->offset + fragsz > PAGE_SIZE) {
put_page(nc->page);
goto refill;
}
data = page_address(nc->page) + nc->offset;
nc->offset += fragsz;
get_page(nc->page);

if (nc->offset + fragsz > PAGE_SIZE) {
/* avoid unnecessary locked operations if possible */
if ((atomic_read(&nc->page->_count) == nc->pagecnt_bias) ||
atomic_sub_and_test(nc->pagecnt_bias, &nc->page->_count))
goto recycle;
goto refill;
}

data = page_address(nc->page) + nc->offset;
nc->offset += fragsz;
nc->pagecnt_bias--;
end:
local_irq_restore(flags);
return data;
}
Expand Down

0 comments on commit 755be2e

Please sign in to comment.