mm_inline.h 2.7 KB

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