040-mm-add-support-for-releasing-multiple-instances-of-a.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From: Alexander Duyck <[email protected]>
  2. Date: Wed, 14 Dec 2016 15:05:26 -0800
  3. Subject: [PATCH] mm: add support for releasing multiple instances of a page
  4. Add a function that allows us to batch free a page that has multiple
  5. references outstanding. Specifically this function can be used to drop
  6. a page being used in the page frag alloc cache. With this drivers can
  7. make use of functionality similar to the page frag alloc cache without
  8. having to do any workarounds for the fact that there is no function that
  9. frees multiple references.
  10. Link: http://lkml.kernel.org/r/[email protected]
  11. Signed-off-by: Alexander Duyck <[email protected]>
  12. Cc: "David S. Miller" <[email protected]>
  13. Cc: "James E.J. Bottomley" <[email protected]>
  14. Cc: Chris Metcalf <[email protected]>
  15. Cc: David Howells <[email protected]>
  16. Cc: Geert Uytterhoeven <[email protected]>
  17. Cc: Hans-Christian Noren Egtvedt <[email protected]>
  18. Cc: Helge Deller <[email protected]>
  19. Cc: James Hogan <[email protected]>
  20. Cc: Jeff Kirsher <[email protected]>
  21. Cc: Jonas Bonn <[email protected]>
  22. Cc: Keguang Zhang <[email protected]>
  23. Cc: Ley Foon Tan <[email protected]>
  24. Cc: Mark Salter <[email protected]>
  25. Cc: Max Filippov <[email protected]>
  26. Cc: Michael Ellerman <[email protected]>
  27. Cc: Michal Simek <[email protected]>
  28. Cc: Ralf Baechle <[email protected]>
  29. Cc: Rich Felker <[email protected]>
  30. Cc: Richard Kuo <[email protected]>
  31. Cc: Russell King <[email protected]>
  32. Cc: Steven Miao <[email protected]>
  33. Cc: Tobias Klauser <[email protected]>
  34. Cc: Vineet Gupta <[email protected]>
  35. Cc: Yoshinori Sato <[email protected]>
  36. Signed-off-by: Andrew Morton <[email protected]>
  37. Signed-off-by: Linus Torvalds <[email protected]>
  38. ---
  39. --- a/include/linux/gfp.h
  40. +++ b/include/linux/gfp.h
  41. @@ -506,6 +506,8 @@ extern void free_hot_cold_page(struct pa
  42. extern void free_hot_cold_page_list(struct list_head *list, bool cold);
  43. struct page_frag_cache;
  44. +extern void __page_frag_drain(struct page *page, unsigned int order,
  45. + unsigned int count);
  46. extern void *__alloc_page_frag(struct page_frag_cache *nc,
  47. unsigned int fragsz, gfp_t gfp_mask);
  48. extern void __free_page_frag(void *addr);
  49. --- a/mm/page_alloc.c
  50. +++ b/mm/page_alloc.c
  51. @@ -3945,6 +3945,20 @@ static struct page *__page_frag_refill(s
  52. return page;
  53. }
  54. +void __page_frag_drain(struct page *page, unsigned int order,
  55. + unsigned int count)
  56. +{
  57. + VM_BUG_ON_PAGE(page_ref_count(page) == 0, page);
  58. +
  59. + if (page_ref_sub_and_test(page, count)) {
  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. +
  68. void *__alloc_page_frag(struct page_frag_cache *nc,
  69. unsigned int fragsz, gfp_t gfp_mask)
  70. {