mm_inline.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef LINUX_MM_INLINE_H
  2. #define LINUX_MM_INLINE_H
  3. #include <linux/huge_mm.h>
  4. #include <linux/swap.h>
  5. /**
  6. * page_is_file_cache - should the page be on a file LRU or anon LRU?
  7. * @page: the page to test
  8. *
  9. * Returns 1 if @page is page cache page backed by a regular filesystem,
  10. * or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed.
  11. * Used by functions that manipulate the LRU lists, to sort a page
  12. * onto the right LRU list.
  13. *
  14. * We would like to get this info without a page flag, but the state
  15. * needs to survive until the page is last deleted from the LRU, which
  16. * could be as far down as __page_cache_release.
  17. */
  18. static inline int page_is_file_cache(struct page *page)
  19. {
  20. return !PageSwapBacked(page);
  21. }
  22. static __always_inline void __update_lru_size(struct lruvec *lruvec,
  23. enum lru_list lru, int nr_pages)
  24. {
  25. __mod_zone_page_state(lruvec_zone(lruvec), NR_LRU_BASE + lru, nr_pages);
  26. }
  27. static __always_inline void update_lru_size(struct lruvec *lruvec,
  28. enum lru_list lru, int nr_pages)
  29. {
  30. #ifdef CONFIG_MEMCG
  31. mem_cgroup_update_lru_size(lruvec, lru, nr_pages);
  32. #else
  33. __update_lru_size(lruvec, lru, nr_pages);
  34. #endif
  35. }
  36. static __always_inline void add_page_to_lru_list(struct page *page,
  37. struct lruvec *lruvec, enum lru_list lru)
  38. {
  39. update_lru_size(lruvec, lru, hpage_nr_pages(page));
  40. list_add(&page->lru, &lruvec->lists[lru]);
  41. }
  42. static __always_inline void del_page_from_lru_list(struct page *page,
  43. struct lruvec *lruvec, enum lru_list lru)
  44. {
  45. list_del(&page->lru);
  46. update_lru_size(lruvec, lru, -hpage_nr_pages(page));
  47. }
  48. /**
  49. * page_lru_base_type - which LRU list type should a page be on?
  50. * @page: the page to test
  51. *
  52. * Used for LRU list index arithmetic.
  53. *
  54. * Returns the base LRU type - file or anon - @page should be on.
  55. */
  56. static inline enum lru_list page_lru_base_type(struct page *page)
  57. {
  58. if (page_is_file_cache(page))
  59. return LRU_INACTIVE_FILE;
  60. return LRU_INACTIVE_ANON;
  61. }
  62. /**
  63. * page_off_lru - which LRU list was page on? clearing its lru flags.
  64. * @page: the page to test
  65. *
  66. * Returns the LRU list a page was on, as an index into the array of LRU
  67. * lists; and clears its Unevictable or Active flags, ready for freeing.
  68. */
  69. static __always_inline enum lru_list page_off_lru(struct page *page)
  70. {
  71. enum lru_list lru;
  72. if (PageUnevictable(page)) {
  73. __ClearPageUnevictable(page);
  74. lru = LRU_UNEVICTABLE;
  75. } else {
  76. lru = page_lru_base_type(page);
  77. if (PageActive(page)) {
  78. __ClearPageActive(page);
  79. lru += LRU_ACTIVE;
  80. }
  81. }
  82. return lru;
  83. }
  84. /**
  85. * page_lru - which LRU list should a page be on?
  86. * @page: the page to test
  87. *
  88. * Returns the LRU list a page should be on, as an index
  89. * into the array of LRU lists.
  90. */
  91. static __always_inline enum lru_list page_lru(struct page *page)
  92. {
  93. enum lru_list lru;
  94. if (PageUnevictable(page))
  95. lru = LRU_UNEVICTABLE;
  96. else {
  97. lru = page_lru_base_type(page);
  98. if (PageActive(page))
  99. lru += LRU_ACTIVE;
  100. }
  101. return lru;
  102. }
  103. #define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
  104. #endif