mm_inline.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. mem_cgroup_add_lru_list(page, l);
  29. }
  30. static inline void
  31. del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
  32. {
  33. list_del(&page->lru);
  34. __dec_zone_state(zone, NR_LRU_BASE + l);
  35. mem_cgroup_del_lru_list(page, l);
  36. }
  37. static inline void
  38. del_page_from_lru(struct zone *zone, struct page *page)
  39. {
  40. enum lru_list l = LRU_BASE;
  41. list_del(&page->lru);
  42. if (PageUnevictable(page)) {
  43. __ClearPageUnevictable(page);
  44. l = LRU_UNEVICTABLE;
  45. } else {
  46. if (PageActive(page)) {
  47. __ClearPageActive(page);
  48. l += LRU_ACTIVE;
  49. }
  50. l += page_is_file_cache(page);
  51. }
  52. __dec_zone_state(zone, NR_LRU_BASE + l);
  53. mem_cgroup_del_lru_list(page, l);
  54. }
  55. /**
  56. * page_lru - which LRU list should a page be on?
  57. * @page: the page to test
  58. *
  59. * Returns the LRU list a page should be on, as an index
  60. * into the array of LRU lists.
  61. */
  62. static inline enum lru_list page_lru(struct page *page)
  63. {
  64. enum lru_list lru = LRU_BASE;
  65. if (PageUnevictable(page))
  66. lru = LRU_UNEVICTABLE;
  67. else {
  68. if (PageActive(page))
  69. lru += LRU_ACTIVE;
  70. lru += page_is_file_cache(page);
  71. }
  72. return lru;
  73. }
  74. /**
  75. * inactive_anon_is_low - check if anonymous pages need to be deactivated
  76. * @zone: zone to check
  77. *
  78. * Returns true if the zone does not have enough inactive anon pages,
  79. * meaning some active anon pages need to be deactivated.
  80. */
  81. static inline int inactive_anon_is_low(struct zone *zone)
  82. {
  83. unsigned long active, inactive;
  84. active = zone_page_state(zone, NR_ACTIVE_ANON);
  85. inactive = zone_page_state(zone, NR_INACTIVE_ANON);
  86. if (inactive * zone->inactive_ratio < active)
  87. return 1;
  88. return 0;
  89. }
  90. #endif