kernel: backport page fragment API changes from 4.10+ to 4.9
[openwrt/openwrt.git] / target / linux / generic / backport-4.9 / 042-mm-rename-__page_frag-functions-to-__page_frag_cache.patch
1 From: Alexander Duyck <alexander.h.duyck@intel.com>
2 Date: Tue, 10 Jan 2017 16:58:09 -0800
3 Subject: [PATCH] mm: rename __page_frag functions to __page_frag_cache, drop
4 order from drain
5
6 This patch does two things.
7
8 First it goes through and renames the __page_frag prefixed functions to
9 __page_frag_cache so that we can be clear that we are draining or
10 refilling the cache, not the frags themselves.
11
12 Second we drop the order parameter from __page_frag_cache_drain since we
13 don't actually need to pass it since all fragments are either order 0 or
14 must be a compound page.
15
16 Link: http://lkml.kernel.org/r/20170104023954.13451.5678.stgit@localhost.localdomain
17 Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
18 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
19 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
20 ---
21
22 --- a/include/linux/gfp.h
23 +++ b/include/linux/gfp.h
24 @@ -506,8 +506,7 @@ extern void free_hot_cold_page(struct pa
25 extern void free_hot_cold_page_list(struct list_head *list, bool cold);
26
27 struct page_frag_cache;
28 -extern void __page_frag_drain(struct page *page, unsigned int order,
29 - unsigned int count);
30 +extern void __page_frag_cache_drain(struct page *page, unsigned int count);
31 extern void *page_frag_alloc(struct page_frag_cache *nc,
32 unsigned int fragsz, gfp_t gfp_mask);
33 extern void page_frag_free(void *addr);
34 --- a/mm/page_alloc.c
35 +++ b/mm/page_alloc.c
36 @@ -3925,8 +3925,8 @@ EXPORT_SYMBOL(free_pages);
37 * drivers to provide a backing region of memory for use as either an
38 * sk_buff->head, or to be used in the "frags" portion of skb_shared_info.
39 */
40 -static struct page *__page_frag_refill(struct page_frag_cache *nc,
41 - gfp_t gfp_mask)
42 +static struct page *__page_frag_cache_refill(struct page_frag_cache *nc,
43 + gfp_t gfp_mask)
44 {
45 struct page *page = NULL;
46 gfp_t gfp = gfp_mask;
47 @@ -3946,19 +3946,20 @@ static struct page *__page_frag_refill(s
48 return page;
49 }
50
51 -void __page_frag_drain(struct page *page, unsigned int order,
52 - unsigned int count)
53 +void __page_frag_cache_drain(struct page *page, unsigned int count)
54 {
55 VM_BUG_ON_PAGE(page_ref_count(page) == 0, page);
56
57 if (page_ref_sub_and_test(page, count)) {
58 + unsigned int order = compound_order(page);
59 +
60 if (order == 0)
61 free_hot_cold_page(page, false);
62 else
63 __free_pages_ok(page, order);
64 }
65 }
66 -EXPORT_SYMBOL(__page_frag_drain);
67 +EXPORT_SYMBOL(__page_frag_cache_drain);
68
69 void *page_frag_alloc(struct page_frag_cache *nc,
70 unsigned int fragsz, gfp_t gfp_mask)
71 @@ -3969,7 +3970,7 @@ void *page_frag_alloc(struct page_frag_c
72
73 if (unlikely(!nc->va)) {
74 refill:
75 - page = __page_frag_refill(nc, gfp_mask);
76 + page = __page_frag_cache_refill(nc, gfp_mask);
77 if (!page)
78 return NULL;
79