1*4882a593Smuzhiyun.. _page_frags: 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun============== 4*4882a593SmuzhiyunPage fragments 5*4882a593Smuzhiyun============== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunA page fragment is an arbitrary-length arbitrary-offset area of memory 8*4882a593Smuzhiyunwhich resides within a 0 or higher order compound page. Multiple 9*4882a593Smuzhiyunfragments within that page are individually refcounted, in the page's 10*4882a593Smuzhiyunreference counter. 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunThe page_frag functions, page_frag_alloc and page_frag_free, provide a 13*4882a593Smuzhiyunsimple allocation framework for page fragments. This is used by the 14*4882a593Smuzhiyunnetwork stack and network device drivers to provide a backing region of 15*4882a593Smuzhiyunmemory for use as either an sk_buff->head, or to be used in the "frags" 16*4882a593Smuzhiyunportion of skb_shared_info. 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunIn order to make use of the page fragment APIs a backing page fragment 19*4882a593Smuzhiyuncache is needed. This provides a central point for the fragment allocation 20*4882a593Smuzhiyunand tracks allows multiple calls to make use of a cached page. The 21*4882a593Smuzhiyunadvantage to doing this is that multiple calls to get_page can be avoided 22*4882a593Smuzhiyunwhich can be expensive at allocation time. However due to the nature of 23*4882a593Smuzhiyunthis caching it is required that any calls to the cache be protected by 24*4882a593Smuzhiyuneither a per-cpu limitation, or a per-cpu limitation and forcing interrupts 25*4882a593Smuzhiyunto be disabled when executing the fragment allocation. 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunThe network stack uses two separate caches per CPU to handle fragment 28*4882a593Smuzhiyunallocation. The netdev_alloc_cache is used by callers making use of the 29*4882a593Smuzhiyunnetdev_alloc_frag and __netdev_alloc_skb calls. The napi_alloc_cache is 30*4882a593Smuzhiyunused by callers of the __napi_alloc_frag and __napi_alloc_skb calls. The 31*4882a593Smuzhiyunmain difference between these two calls is the context in which they may be 32*4882a593Smuzhiyuncalled. The "netdev" prefixed functions are usable in any context as these 33*4882a593Smuzhiyunfunctions will disable interrupts, while the "napi" prefixed functions are 34*4882a593Smuzhiyunonly usable within the softirq context. 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunMany network device drivers use a similar methodology for allocating page 37*4882a593Smuzhiyunfragments, but the page fragments are cached at the ring or descriptor 38*4882a593Smuzhiyunlevel. In order to enable these cases it is necessary to provide a generic 39*4882a593Smuzhiyunway of tearing down a page cache. For this reason __page_frag_cache_drain 40*4882a593Smuzhiyunwas implemented. It allows for freeing multiple references from a single 41*4882a593Smuzhiyunpage via a single call. The advantage to doing this is that it allows for 42*4882a593Smuzhiyuncleaning up the multiple references that were added to a page in order to 43*4882a593Smuzhiyunavoid calling get_page per allocation. 44*4882a593Smuzhiyun 45*4882a593SmuzhiyunAlexander Duyck, Nov 29, 2016. 46