page_cgroup.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef __LINUX_PAGE_CGROUP_H
  2. #define __LINUX_PAGE_CGROUP_H
  3. enum {
  4. /* flags for mem_cgroup */
  5. PCG_LOCK, /* Lock for pc->mem_cgroup and following bits. */
  6. PCG_USED, /* this object is in use. */
  7. PCG_MIGRATION, /* under page migration */
  8. __NR_PCG_FLAGS,
  9. };
  10. #ifndef __GENERATING_BOUNDS_H
  11. #include <generated/bounds.h>
  12. #ifdef CONFIG_MEMCG
  13. #include <linux/bit_spinlock.h>
  14. /*
  15. * Page Cgroup can be considered as an extended mem_map.
  16. * A page_cgroup page is associated with every page descriptor. The
  17. * page_cgroup helps us identify information about the cgroup
  18. * All page cgroups are allocated at boot or memory hotplug event,
  19. * then the page cgroup for pfn always exists.
  20. */
  21. struct page_cgroup {
  22. unsigned long flags;
  23. struct mem_cgroup *mem_cgroup;
  24. };
  25. void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
  26. #ifdef CONFIG_SPARSEMEM
  27. static inline void __init page_cgroup_init_flatmem(void)
  28. {
  29. }
  30. extern void __init page_cgroup_init(void);
  31. #else
  32. void __init page_cgroup_init_flatmem(void);
  33. static inline void __init page_cgroup_init(void)
  34. {
  35. }
  36. #endif
  37. struct page_cgroup *lookup_page_cgroup(struct page *page);
  38. struct page *lookup_cgroup_page(struct page_cgroup *pc);
  39. #define TESTPCGFLAG(uname, lname) \
  40. static inline int PageCgroup##uname(struct page_cgroup *pc) \
  41. { return test_bit(PCG_##lname, &pc->flags); }
  42. #define SETPCGFLAG(uname, lname) \
  43. static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
  44. { set_bit(PCG_##lname, &pc->flags); }
  45. #define CLEARPCGFLAG(uname, lname) \
  46. static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
  47. { clear_bit(PCG_##lname, &pc->flags); }
  48. #define TESTCLEARPCGFLAG(uname, lname) \
  49. static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
  50. { return test_and_clear_bit(PCG_##lname, &pc->flags); }
  51. TESTPCGFLAG(Used, USED)
  52. CLEARPCGFLAG(Used, USED)
  53. SETPCGFLAG(Used, USED)
  54. SETPCGFLAG(Migration, MIGRATION)
  55. CLEARPCGFLAG(Migration, MIGRATION)
  56. TESTPCGFLAG(Migration, MIGRATION)
  57. static inline void lock_page_cgroup(struct page_cgroup *pc)
  58. {
  59. /*
  60. * Don't take this lock in IRQ context.
  61. * This lock is for pc->mem_cgroup, USED, MIGRATION
  62. */
  63. bit_spin_lock(PCG_LOCK, &pc->flags);
  64. }
  65. static inline void unlock_page_cgroup(struct page_cgroup *pc)
  66. {
  67. bit_spin_unlock(PCG_LOCK, &pc->flags);
  68. }
  69. #else /* CONFIG_MEMCG */
  70. struct page_cgroup;
  71. static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
  72. {
  73. }
  74. static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
  75. {
  76. return NULL;
  77. }
  78. static inline void page_cgroup_init(void)
  79. {
  80. }
  81. static inline void __init page_cgroup_init_flatmem(void)
  82. {
  83. }
  84. #endif /* CONFIG_MEMCG */
  85. #include <linux/swap.h>
  86. #ifdef CONFIG_MEMCG_SWAP
  87. extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
  88. unsigned short old, unsigned short new);
  89. extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
  90. extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
  91. extern int swap_cgroup_swapon(int type, unsigned long max_pages);
  92. extern void swap_cgroup_swapoff(int type);
  93. #else
  94. static inline
  95. unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
  96. {
  97. return 0;
  98. }
  99. static inline
  100. unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
  101. {
  102. return 0;
  103. }
  104. static inline int
  105. swap_cgroup_swapon(int type, unsigned long max_pages)
  106. {
  107. return 0;
  108. }
  109. static inline void swap_cgroup_swapoff(int type)
  110. {
  111. return;
  112. }
  113. #endif /* CONFIG_MEMCG_SWAP */
  114. #endif /* !__GENERATING_BOUNDS_H */
  115. #endif /* __LINUX_PAGE_CGROUP_H */