brintos

brintos / linux-shallow public Read only

0
0
Text · 2.2 KiB · 503ca6c Raw
44 lines · plain
1==============2Page fragments3==============4 5A page fragment is an arbitrary-length arbitrary-offset area of memory6which resides within a 0 or higher order compound page.  Multiple7fragments within that page are individually refcounted, in the page's8reference counter.9 10The page_frag functions, page_frag_alloc and page_frag_free, provide a11simple allocation framework for page fragments.  This is used by the12network stack and network device drivers to provide a backing region of13memory for use as either an sk_buff->head, or to be used in the "frags"14portion of skb_shared_info.15 16In order to make use of the page fragment APIs a backing page fragment17cache is needed.  This provides a central point for the fragment allocation18and tracks allows multiple calls to make use of a cached page.  The19advantage to doing this is that multiple calls to get_page can be avoided20which can be expensive at allocation time.  However due to the nature of21this caching it is required that any calls to the cache be protected by22either a per-cpu limitation, or a per-cpu limitation and forcing interrupts23to be disabled when executing the fragment allocation.24 25The network stack uses two separate caches per CPU to handle fragment26allocation.  The netdev_alloc_cache is used by callers making use of the27netdev_alloc_frag and __netdev_alloc_skb calls.  The napi_alloc_cache is28used by callers of the __napi_alloc_frag and napi_alloc_skb calls.  The29main difference between these two calls is the context in which they may be30called.  The "netdev" prefixed functions are usable in any context as these31functions will disable interrupts, while the "napi" prefixed functions are32only usable within the softirq context.33 34Many network device drivers use a similar methodology for allocating page35fragments, but the page fragments are cached at the ring or descriptor36level.  In order to enable these cases it is necessary to provide a generic37way of tearing down a page cache.  For this reason __page_frag_cache_drain38was implemented.  It allows for freeing multiple references from a single39page via a single call.  The advantage to doing this is that it allows for40cleaning up the multiple references that were added to a page in order to41avoid calling get_page per allocation.42 43Alexander Duyck, Nov 29, 2016.44