mm_inline.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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, enum zone_type zid,
  24. int nr_pages)
  25. {
  26. struct pglist_data *pgdat = lruvec_pgdat(lruvec);
  27. __mod_node_page_state(pgdat, NR_LRU_BASE + lru, nr_pages);
  28. __mod_zone_page_state(&pgdat->node_zones[zid],
  29. NR_ZONE_LRU_BASE + lru, nr_pages);
  30. }
  31. static __always_inline void update_lru_size(struct lruvec *lruvec,
  32. enum lru_list lru, enum zone_type zid,
  33. int nr_pages)
  34. {
  35. __update_lru_size(lruvec, lru, zid, nr_pages);
  36. #ifdef CONFIG_MEMCG
  37. mem_cgroup_update_lru_size(lruvec, lru, zid, nr_pages);
  38. #endif
  39. }
  40. static __always_inline void add_page_to_lru_list(struct page *page,
  41. struct lruvec *lruvec, enum lru_list lru)
  42. {
  43. update_lru_size(lruvec, lru, page_zonenum(page), hpage_nr_pages(page));
  44. list_add(&page->lru, &lruvec->lists[lru]);
  45. }
  46. static __always_inline void add_page_to_lru_list_tail(struct page *page,
  47. struct lruvec *lruvec, enum lru_list lru)
  48. {
  49. update_lru_size(lruvec, lru, page_zonenum(page), hpage_nr_pages(page));
  50. list_add_tail(&page->lru, &lruvec->lists[lru]);
  51. }
  52. static __always_inline void del_page_from_lru_list(struct page *page,
  53. struct lruvec *lruvec, enum lru_list lru)
  54. {
  55. list_del(&page->lru);
  56. update_lru_size(lruvec, lru, page_zonenum(page), -hpage_nr_pages(page));
  57. }
  58. /**
  59. * page_lru_base_type - which LRU list type should a page be on?
  60. * @page: the page to test
  61. *
  62. * Used for LRU list index arithmetic.
  63. *
  64. * Returns the base LRU type - file or anon - @page should be on.
  65. */
  66. static inline enum lru_list page_lru_base_type(struct page *page)
  67. {
  68. if (page_is_file_cache(page))
  69. return LRU_INACTIVE_FILE;
  70. return LRU_INACTIVE_ANON;
  71. }
  72. /**
  73. * page_off_lru - which LRU list was page on? clearing its lru flags.
  74. * @page: the page to test
  75. *
  76. * Returns the LRU list a page was on, as an index into the array of LRU
  77. * lists; and clears its Unevictable or Active flags, ready for freeing.
  78. */
  79. static __always_inline enum lru_list page_off_lru(struct page *page)
  80. {
  81. enum lru_list lru;
  82. if (PageUnevictable(page)) {
  83. __ClearPageUnevictable(page);
  84. lru = LRU_UNEVICTABLE;
  85. } else {
  86. lru = page_lru_base_type(page);
  87. if (PageActive(page)) {
  88. __ClearPageActive(page);
  89. lru += LRU_ACTIVE;
  90. }
  91. }
  92. return lru;
  93. }
  94. /**
  95. * page_lru - which LRU list should a page be on?
  96. * @page: the page to test
  97. *
  98. * Returns the LRU list a page should be on, as an index
  99. * into the array of LRU lists.
  100. */
  101. static __always_inline enum lru_list page_lru(struct page *page)
  102. {
  103. enum lru_list lru;
  104. if (PageUnevictable(page))
  105. lru = LRU_UNEVICTABLE;
  106. else {
  107. lru = page_lru_base_type(page);
  108. if (PageActive(page))
  109. lru += LRU_ACTIVE;
  110. }
  111. return lru;
  112. }
  113. #define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
  114. #endif