Skip to content

Commit 4d09d0f

Browse files
Alexander Duycktorvalds
Alexander Duyck
authored andcommitted
mm: add documentation for page fragment APIs
This is a first pass at trying to add documentation for the page_frag APIs. They may still change over time but for now I thought I would try to get these documented so that as more network drivers and stack calls make use of them we have one central spot to document how they are meant to be used. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Alexander Duyck <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 2976db8 commit 4d09d0f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Documentation/vm/page_frags

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Page fragments
2+
--------------
3+
4+
A page fragment is an arbitrary-length arbitrary-offset area of memory
5+
which resides within a 0 or higher order compound page. Multiple
6+
fragments within that page are individually refcounted, in the page's
7+
reference counter.
8+
9+
The page_frag functions, page_frag_alloc and page_frag_free, provide a
10+
simple allocation framework for page fragments. This is used by the
11+
network stack and network device drivers to provide a backing region of
12+
memory for use as either an sk_buff->head, or to be used in the "frags"
13+
portion of skb_shared_info.
14+
15+
In order to make use of the page fragment APIs a backing page fragment
16+
cache is needed. This provides a central point for the fragment allocation
17+
and tracks allows multiple calls to make use of a cached page. The
18+
advantage to doing this is that multiple calls to get_page can be avoided
19+
which can be expensive at allocation time. However due to the nature of
20+
this caching it is required that any calls to the cache be protected by
21+
either a per-cpu limitation, or a per-cpu limitation and forcing interrupts
22+
to be disabled when executing the fragment allocation.
23+
24+
The network stack uses two separate caches per CPU to handle fragment
25+
allocation. The netdev_alloc_cache is used by callers making use of the
26+
__netdev_alloc_frag and __netdev_alloc_skb calls. The napi_alloc_cache is
27+
used by callers of the __napi_alloc_frag and __napi_alloc_skb calls. The
28+
main difference between these two calls is the context in which they may be
29+
called. The "netdev" prefixed functions are usable in any context as these
30+
functions will disable interrupts, while the "napi" prefixed functions are
31+
only usable within the softirq context.
32+
33+
Many network device drivers use a similar methodology for allocating page
34+
fragments, but the page fragments are cached at the ring or descriptor
35+
level. In order to enable these cases it is necessary to provide a generic
36+
way of tearing down a page cache. For this reason __page_frag_cache_drain
37+
was implemented. It allows for freeing multiple references from a single
38+
page via a single call. The advantage to doing this is that it allows for
39+
cleaning up the multiple references that were added to a page in order to
40+
avoid calling get_page per allocation.
41+
42+
Alexander Duyck, Nov 29, 2016.

0 commit comments

Comments
 (0)