mm_inline.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef LINUX_MM_INLINE_H
  2. #define LINUX_MM_INLINE_H
  3. /**
  4. * page_is_file_cache - should the page be on a file LRU or anon LRU?
  5. * @page: the page to test
  6. *
  7. * Returns LRU_FILE if @page is page cache page backed by a regular filesystem,
  8. * or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed.
  9. * Used by functions that manipulate the LRU lists, to sort a page
  10. * onto the right LRU list.
  11. *
  12. * We would like to get this info without a page flag, but the state
  13. * needs to survive until the page is last deleted from the LRU, which
  14. * could be as far down as __page_cache_release.
  15. */
  16. static inline int page_is_file_cache(struct page *page)
  17. {
  18. if (PageSwapBacked(page))
  19. return 0;
  20. /* The page is page cache backed by a normal filesystem. */
  21. return LRU_FILE;
  22. }
  23. static inline void
  24. add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l)
  25. {
  26. list_add(&page->lru, &zone->lru[l].list);
  27. __inc_zone_state(zone, NR_LRU_BASE + l);
  28. }
  29. static inline void
  30. del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
  31. {
  32. list_del(&page->lru);
  33. __dec_zone_state(zone, NR_LRU_BASE + l);
  34. }
  35. static inline void
  36. add_page_to_inactive_anon_list(struct zone *zone, struct page *page)
  37. {
  38. add_page_to_lru_list(zone, page, LRU_INACTIVE_ANON);
  39. }
  40. static inline void
  41. add_page_to_active_anon_list(struct zone *zone, struct page *page)
  42. {
  43. add_page_to_lru_list(zone, page, LRU_ACTIVE_ANON);
  44. }
  45. static inline void
  46. add_page_to_inactive_file_list(struct zone *zone, struct page *page)
  47. {
  48. add_page_to_lru_list(zone, page, LRU_INACTIVE_FILE);
  49. }
  50. static inline void
  51. add_page_to_active_file_list(struct zone *zone, struct page *page)
  52. {
  53. add_page_to_lru_list(zone, page, LRU_ACTIVE_FILE);
  54. }
  55. static inline void
  56. del_page_from_inactive_anon_list(struct zone *zone, struct page *page)
  57. {
  58. del_page_from_lru_list(zone, page, LRU_INACTIVE_ANON);
  59. }
  60. static inline void
  61. del_page_from_active_anon_list(struct zone *zone, struct page *page)
  62. {
  63. del_page_from_lru_list(zone, page, LRU_ACTIVE_ANON);
  64. }
  65. static inline void
  66. del_page_from_inactive_file_list(struct zone *zone, struct page *page)
  67. {
  68. del_page_from_lru_list(zone, page, LRU_INACTIVE_FILE);
  69. }
  70. static inline void
  71. del_page_from_active_file_list(struct zone *zone, struct page *page)
  72. {
  73. del_page_from_lru_list(zone, page, LRU_INACTIVE_FILE);
  74. }
  75. static inline void
  76. del_page_from_lru(struct zone *zone, struct page *page)
  77. {
  78. enum lru_list l = LRU_BASE;
  79. list_del(&page->lru);
  80. if (PageUnevictable(page)) {
  81. __ClearPageUnevictable(page);
  82. l = LRU_UNEVICTABLE;
  83. } else {
  84. if (PageActive(page)) {
  85. __ClearPageActive(page);
  86. l += LRU_ACTIVE;
  87. }
  88. l += page_is_file_cache(page);
  89. }
  90. __dec_zone_state(zone, NR_LRU_BASE + l);
  91. }
  92. /**
  93. * page_lru - which LRU list should a page be on?
  94. * @page: the page to test
  95. *
  96. * Returns the LRU list a page should be on, as an index
  97. * into the array of LRU lists.
  98. */
  99. static inline enum lru_list page_lru(struct page *page)
  100. {
  101. enum lru_list lru = LRU_BASE;
  102. if (PageUnevictable(page))
  103. lru = LRU_UNEVICTABLE;
  104. else {
  105. if (PageActive(page))
  106. lru += LRU_ACTIVE;
  107. lru += page_is_file_cache(page);
  108. }
  109. return lru;
  110. }
  111. /**
  112. * inactive_anon_is_low - check if anonymous pages need to be deactivated
  113. * @zone: zone to check
  114. *
  115. * Returns true if the zone does not have enough inactive anon pages,
  116. * meaning some active anon pages need to be deactivated.
  117. */
  118. static inline int inactive_anon_is_low(struct zone *zone)
  119. {
  120. unsigned long active, inactive;
  121. active = zone_page_state(zone, NR_ACTIVE_ANON);
  122. inactive = zone_page_state(zone, NR_INACTIVE_ANON);
  123. if (inactive * zone->inactive_ratio < active)
  124. return 1;
  125. return 0;
  126. }
  127. #endif