mm_inline.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 __always_inline void add_page_to_lru_list(struct page *page,
  22. struct lruvec *lruvec, enum lru_list lru)
  23. {
  24. int nr_pages = hpage_nr_pages(page);
  25. mem_cgroup_update_lru_size(lruvec, lru, nr_pages);
  26. list_add(&page->lru, &lruvec->lists[lru]);
  27. __mod_zone_page_state(lruvec_zone(lruvec), NR_LRU_BASE + lru, nr_pages);
  28. }
  29. static __always_inline void del_page_from_lru_list(struct page *page,
  30. struct lruvec *lruvec, enum lru_list lru)
  31. {
  32. int nr_pages = hpage_nr_pages(page);
  33. mem_cgroup_update_lru_size(lruvec, lru, -nr_pages);
  34. list_del(&page->lru);
  35. __mod_zone_page_state(lruvec_zone(lruvec), NR_LRU_BASE + lru, -nr_pages);
  36. }
  37. /**
  38. * page_lru_base_type - which LRU list type should a page be on?
  39. * @page: the page to test
  40. *
  41. * Used for LRU list index arithmetic.
  42. *
  43. * Returns the base LRU type - file or anon - @page should be on.
  44. */
  45. static inline enum lru_list page_lru_base_type(struct page *page)
  46. {
  47. if (page_is_file_cache(page))
  48. return LRU_INACTIVE_FILE;
  49. return LRU_INACTIVE_ANON;
  50. }
  51. /**
  52. * page_off_lru - which LRU list was page on? clearing its lru flags.
  53. * @page: the page to test
  54. *
  55. * Returns the LRU list a page was on, as an index into the array of LRU
  56. * lists; and clears its Unevictable or Active flags, ready for freeing.
  57. */
  58. static __always_inline enum lru_list page_off_lru(struct page *page)
  59. {
  60. enum lru_list lru;
  61. if (PageUnevictable(page)) {
  62. __ClearPageUnevictable(page);
  63. lru = LRU_UNEVICTABLE;
  64. } else {
  65. lru = page_lru_base_type(page);
  66. if (PageActive(page)) {
  67. __ClearPageActive(page);
  68. lru += LRU_ACTIVE;
  69. }
  70. }
  71. return lru;
  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 __always_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