kernel: bump 4.9 to 4.9.116
[openwrt/staging/chunkeey.git] / target / linux / generic / backport-4.9 / 040-mm-add-support-for-releasing-multiple-instances-of-a.patch
1 From: Alexander Duyck <alexander.h.duyck@intel.com>
2 Date: Wed, 14 Dec 2016 15:05:26 -0800
3 Subject: [PATCH] mm: add support for releasing multiple instances of a page
4
5 Add a function that allows us to batch free a page that has multiple
6 references outstanding. Specifically this function can be used to drop
7 a page being used in the page frag alloc cache. With this drivers can
8 make use of functionality similar to the page frag alloc cache without
9 having to do any workarounds for the fact that there is no function that
10 frees multiple references.
11
12 Link: http://lkml.kernel.org/r/20161110113606.76501.70752.stgit@ahduyck-blue-test.jf.intel.com
13 Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
14 Cc: "David S. Miller" <davem@davemloft.net>
15 Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
16 Cc: Chris Metcalf <cmetcalf@mellanox.com>
17 Cc: David Howells <dhowells@redhat.com>
18 Cc: Geert Uytterhoeven <geert@linux-m68k.org>
19 Cc: Hans-Christian Noren Egtvedt <egtvedt@samfundet.no>
20 Cc: Helge Deller <deller@gmx.de>
21 Cc: James Hogan <james.hogan@imgtec.com>
22 Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
23 Cc: Jonas Bonn <jonas@southpole.se>
24 Cc: Keguang Zhang <keguang.zhang@gmail.com>
25 Cc: Ley Foon Tan <lftan@altera.com>
26 Cc: Mark Salter <msalter@redhat.com>
27 Cc: Max Filippov <jcmvbkbc@gmail.com>
28 Cc: Michael Ellerman <mpe@ellerman.id.au>
29 Cc: Michal Simek <monstr@monstr.eu>
30 Cc: Ralf Baechle <ralf@linux-mips.org>
31 Cc: Rich Felker <dalias@libc.org>
32 Cc: Richard Kuo <rkuo@codeaurora.org>
33 Cc: Russell King <linux@armlinux.org.uk>
34 Cc: Steven Miao <realmz6@gmail.com>
35 Cc: Tobias Klauser <tklauser@distanz.ch>
36 Cc: Vineet Gupta <vgupta@synopsys.com>
37 Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
38 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
39 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
40 ---
41
42 --- a/include/linux/gfp.h
43 +++ b/include/linux/gfp.h
44 @@ -506,6 +506,8 @@ extern void free_hot_cold_page(struct pa
45 extern void free_hot_cold_page_list(struct list_head *list, bool cold);
46
47 struct page_frag_cache;
48 +extern void __page_frag_drain(struct page *page, unsigned int order,
49 + unsigned int count);
50 extern void *__alloc_page_frag(struct page_frag_cache *nc,
51 unsigned int fragsz, gfp_t gfp_mask);
52 extern void __free_page_frag(void *addr);
53 --- a/mm/page_alloc.c
54 +++ b/mm/page_alloc.c
55 @@ -3945,6 +3945,20 @@ static struct page *__page_frag_refill(s
56 return page;
57 }
58
59 +void __page_frag_drain(struct page *page, unsigned int order,
60 + unsigned int count)
61 +{
62 + VM_BUG_ON_PAGE(page_ref_count(page) == 0, page);
63 +
64 + if (page_ref_sub_and_test(page, count)) {
65 + if (order == 0)
66 + free_hot_cold_page(page, false);
67 + else
68 + __free_pages_ok(page, order);
69 + }
70 +}
71 +EXPORT_SYMBOL(__page_frag_drain);
72 +
73 void *__alloc_page_frag(struct page_frag_cache *nc,
74 unsigned int fragsz, gfp_t gfp_mask)
75 {