mm_inline.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 1 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. return !PageSwapBacked(page);
  19. }
  20. static inline void
  21. add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l)
  22. {
  23. list_add(&page->lru, &zone->lru[l].list);
  24. __inc_zone_state(zone, NR_LRU_BASE + l);
  25. mem_cgroup_add_lru_list(page, l);
  26. }
  27. static inline void
  28. del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
  29. {
  30. list_del(&page->lru);
  31. __dec_zone_state(zone, NR_LRU_BASE + l);
  32. mem_cgroup_del_lru_list(page, l);
  33. }
  34. /**
  35. * page_lru_base_type - which LRU list type should a page be on?
  36. * @page: the page to test
  37. *
  38. * Used for LRU list index arithmetic.
  39. *
  40. * Returns the base LRU type - file or anon - @page should be on.
  41. */
  42. static inline enum lru_list page_lru_base_type(struct page *page)
  43. {
  44. if (page_is_file_cache(page))
  45. return LRU_INACTIVE_FILE;
  46. return LRU_INACTIVE_ANON;
  47. }
  48. static inline void
  49. del_page_from_lru(struct zone *zone, struct page *page)
  50. {
  51. enum lru_list l;
  52. list_del(&page->lru);
  53. if (PageUnevictable(page)) {
  54. __ClearPageUnevictable(page);
  55. l = LRU_UNEVICTABLE;
  56. } else {
  57. l = page_lru_base_type(page);
  58. if (PageActive(page)) {
  59. __ClearPageActive(page);
  60. l += LRU_ACTIVE;
  61. }
  62. }
  63. __dec_zone_state(zone, NR_LRU_BASE + l);
  64. mem_cgroup_del_lru_list(page, l);
  65. }
  66. /**
  67. * page_lru - which LRU list should a page be on?
  68. * @page: the page to test
  69. *
  70. * Returns the LRU list a page should be on, as an index
  71. * into the array of LRU lists.
  72. */
  73. static inline enum lru_list page_lru(struct page *page)
  74. {
  75. enum lru_list lru;
  76. if (PageUnevictable(page))
  77. lru = LRU_UNEVICTABLE;
  78. else {
  79. lru = page_lru_base_type(page);
  80. if (PageActive(page))
  81. lru += LRU_ACTIVE;
  82. }
  83. return lru;
  84. }
  85. #endif