page_cgroup.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef __LINUX_PAGE_CGROUP_H
  2. #define __LINUX_PAGE_CGROUP_H
  3. #ifdef CONFIG_CGROUP_MEM_RES_CTLR
  4. #include <linux/bit_spinlock.h>
  5. /*
  6. * Page Cgroup can be considered as an extended mem_map.
  7. * A page_cgroup page is associated with every page descriptor. The
  8. * page_cgroup helps us identify information about the cgroup
  9. * All page cgroups are allocated at boot or memory hotplug event,
  10. * then the page cgroup for pfn always exists.
  11. */
  12. struct page_cgroup {
  13. unsigned long flags;
  14. struct mem_cgroup *mem_cgroup;
  15. struct page *page;
  16. struct list_head lru; /* per cgroup LRU list */
  17. };
  18. void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
  19. #ifdef CONFIG_SPARSEMEM
  20. static inline void __init page_cgroup_init_flatmem(void)
  21. {
  22. }
  23. extern void __init page_cgroup_init(void);
  24. #else
  25. void __init page_cgroup_init_flatmem(void);
  26. static inline void __init page_cgroup_init(void)
  27. {
  28. }
  29. #endif
  30. struct page_cgroup *lookup_page_cgroup(struct page *page);
  31. enum {
  32. /* flags for mem_cgroup */
  33. PCG_LOCK, /* page cgroup is locked */
  34. PCG_CACHE, /* charged as cache */
  35. PCG_USED, /* this object is in use. */
  36. PCG_ACCT_LRU, /* page has been accounted for */
  37. };
  38. #define TESTPCGFLAG(uname, lname) \
  39. static inline int PageCgroup##uname(struct page_cgroup *pc) \
  40. { return test_bit(PCG_##lname, &pc->flags); }
  41. #define SETPCGFLAG(uname, lname) \
  42. static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
  43. { set_bit(PCG_##lname, &pc->flags); }
  44. #define CLEARPCGFLAG(uname, lname) \
  45. static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
  46. { clear_bit(PCG_##lname, &pc->flags); }
  47. #define TESTCLEARPCGFLAG(uname, lname) \
  48. static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
  49. { return test_and_clear_bit(PCG_##lname, &pc->flags); }
  50. TESTPCGFLAG(Locked, LOCK)
  51. /* Cache flag is set only once (at allocation) */
  52. TESTPCGFLAG(Cache, CACHE)
  53. CLEARPCGFLAG(Cache, CACHE)
  54. SETPCGFLAG(Cache, CACHE)
  55. TESTPCGFLAG(Used, USED)
  56. CLEARPCGFLAG(Used, USED)
  57. SETPCGFLAG(Used, USED)
  58. SETPCGFLAG(AcctLRU, ACCT_LRU)
  59. CLEARPCGFLAG(AcctLRU, ACCT_LRU)
  60. TESTPCGFLAG(AcctLRU, ACCT_LRU)
  61. TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU)
  62. static inline int page_cgroup_nid(struct page_cgroup *pc)
  63. {
  64. return page_to_nid(pc->page);
  65. }
  66. static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
  67. {
  68. return page_zonenum(pc->page);
  69. }
  70. static inline void lock_page_cgroup(struct page_cgroup *pc)
  71. {
  72. bit_spin_lock(PCG_LOCK, &pc->flags);
  73. }
  74. static inline void unlock_page_cgroup(struct page_cgroup *pc)
  75. {
  76. bit_spin_unlock(PCG_LOCK, &pc->flags);
  77. }
  78. #else /* CONFIG_CGROUP_MEM_RES_CTLR */
  79. struct page_cgroup;
  80. static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
  81. {
  82. }
  83. static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
  84. {
  85. return NULL;
  86. }
  87. static inline void page_cgroup_init(void)
  88. {
  89. }
  90. static inline void __init page_cgroup_init_flatmem(void)
  91. {
  92. }
  93. #endif
  94. #include <linux/swap.h>
  95. #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
  96. extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
  97. extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
  98. extern int swap_cgroup_swapon(int type, unsigned long max_pages);
  99. extern void swap_cgroup_swapoff(int type);
  100. #else
  101. static inline
  102. unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
  103. {
  104. return 0;
  105. }
  106. static inline
  107. unsigned short lookup_swap_cgroup(swp_entry_t ent)
  108. {
  109. return 0;
  110. }
  111. static inline int
  112. swap_cgroup_swapon(int type, unsigned long max_pages)
  113. {
  114. return 0;
  115. }
  116. static inline void swap_cgroup_swapoff(int type)
  117. {
  118. return;
  119. }
  120. #endif
  121. #endif