mm_inline.h 2.5 KB

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