mm_inline.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 (PageActive(page)) {
  81. __ClearPageActive(page);
  82. l += LRU_ACTIVE;
  83. }
  84. l += page_is_file_cache(page);
  85. __dec_zone_state(zone, NR_LRU_BASE + l);
  86. }
  87. /**
  88. * page_lru - which LRU list should a page be on?
  89. * @page: the page to test
  90. *
  91. * Returns the LRU list a page should be on, as an index
  92. * into the array of LRU lists.
  93. */
  94. static inline enum lru_list page_lru(struct page *page)
  95. {
  96. enum lru_list lru = LRU_BASE;
  97. if (PageActive(page))
  98. lru += LRU_ACTIVE;
  99. lru += page_is_file_cache(page);
  100. return lru;
  101. }
  102. #endif