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