page_cgroup.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_CACHE, /* charged as cache */
  7. PCG_USED, /* this object is in use. */
  8. PCG_MIGRATION, /* under page migration */
  9. /* flags for mem_cgroup and file and I/O status */
  10. PCG_MOVE_LOCK, /* For race between move_account v.s. following bits */
  11. PCG_FILE_MAPPED, /* page is accounted as "mapped" */
  12. __NR_PCG_FLAGS,
  13. };
  14. #ifndef __GENERATING_BOUNDS_H
  15. #include <generated/bounds.h>
  16. #ifdef CONFIG_CGROUP_MEM_RES_CTLR
  17. #include <linux/bit_spinlock.h>
  18. /*
  19. * Page Cgroup can be considered as an extended mem_map.
  20. * A page_cgroup page is associated with every page descriptor. The
  21. * page_cgroup helps us identify information about the cgroup
  22. * All page cgroups are allocated at boot or memory hotplug event,
  23. * then the page cgroup for pfn always exists.
  24. */
  25. struct page_cgroup {
  26. unsigned long flags;
  27. struct mem_cgroup *mem_cgroup;
  28. };
  29. void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
  30. #ifdef CONFIG_SPARSEMEM
  31. static inline void __init page_cgroup_init_flatmem(void)
  32. {
  33. }
  34. extern void __init page_cgroup_init(void);
  35. #else
  36. void __init page_cgroup_init_flatmem(void);
  37. static inline void __init page_cgroup_init(void)
  38. {
  39. }
  40. #endif
  41. struct page_cgroup *lookup_page_cgroup(struct page *page);
  42. struct page *lookup_cgroup_page(struct page_cgroup *pc);
  43. #define TESTPCGFLAG(uname, lname) \
  44. static inline int PageCgroup##uname(struct page_cgroup *pc) \
  45. { return test_bit(PCG_##lname, &pc->flags); }
  46. #define SETPCGFLAG(uname, lname) \
  47. static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
  48. { set_bit(PCG_##lname, &pc->flags); }
  49. #define CLEARPCGFLAG(uname, lname) \
  50. static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
  51. { clear_bit(PCG_##lname, &pc->flags); }
  52. #define TESTCLEARPCGFLAG(uname, lname) \
  53. static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
  54. { return test_and_clear_bit(PCG_##lname, &pc->flags); }
  55. /* Cache flag is set only once (at allocation) */
  56. TESTPCGFLAG(Cache, CACHE)
  57. CLEARPCGFLAG(Cache, CACHE)
  58. SETPCGFLAG(Cache, CACHE)
  59. TESTPCGFLAG(Used, USED)
  60. CLEARPCGFLAG(Used, USED)
  61. SETPCGFLAG(Used, USED)
  62. SETPCGFLAG(FileMapped, FILE_MAPPED)
  63. CLEARPCGFLAG(FileMapped, FILE_MAPPED)
  64. TESTPCGFLAG(FileMapped, FILE_MAPPED)
  65. SETPCGFLAG(Migration, MIGRATION)
  66. CLEARPCGFLAG(Migration, MIGRATION)
  67. TESTPCGFLAG(Migration, MIGRATION)
  68. static inline void lock_page_cgroup(struct page_cgroup *pc)
  69. {
  70. /*
  71. * Don't take this lock in IRQ context.
  72. * This lock is for pc->mem_cgroup, USED, CACHE, MIGRATION
  73. */
  74. bit_spin_lock(PCG_LOCK, &pc->flags);
  75. }
  76. static inline void unlock_page_cgroup(struct page_cgroup *pc)
  77. {
  78. bit_spin_unlock(PCG_LOCK, &pc->flags);
  79. }
  80. static inline void move_lock_page_cgroup(struct page_cgroup *pc,
  81. unsigned long *flags)
  82. {
  83. /*
  84. * We know updates to pc->flags of page cache's stats are from both of
  85. * usual context or IRQ context. Disable IRQ to avoid deadlock.
  86. */
  87. local_irq_save(*flags);
  88. bit_spin_lock(PCG_MOVE_LOCK, &pc->flags);
  89. }
  90. static inline void move_unlock_page_cgroup(struct page_cgroup *pc,
  91. unsigned long *flags)
  92. {
  93. bit_spin_unlock(PCG_MOVE_LOCK, &pc->flags);
  94. local_irq_restore(*flags);
  95. }
  96. #else /* CONFIG_CGROUP_MEM_RES_CTLR */
  97. struct page_cgroup;
  98. static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
  99. {
  100. }
  101. static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
  102. {
  103. return NULL;
  104. }
  105. static inline void page_cgroup_init(void)
  106. {
  107. }
  108. static inline void __init page_cgroup_init_flatmem(void)
  109. {
  110. }
  111. #endif /* CONFIG_CGROUP_MEM_RES_CTLR */
  112. #include <linux/swap.h>
  113. #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
  114. extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
  115. unsigned short old, unsigned short new);
  116. extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
  117. extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
  118. extern int swap_cgroup_swapon(int type, unsigned long max_pages);
  119. extern void swap_cgroup_swapoff(int type);
  120. #else
  121. static inline
  122. unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
  123. {
  124. return 0;
  125. }
  126. static inline
  127. unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
  128. {
  129. return 0;
  130. }
  131. static inline int
  132. swap_cgroup_swapon(int type, unsigned long max_pages)
  133. {
  134. return 0;
  135. }
  136. static inline void swap_cgroup_swapoff(int type)
  137. {
  138. return;
  139. }
  140. #endif /* CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
  141. #endif /* !__GENERATING_BOUNDS_H */
  142. #endif /* __LINUX_PAGE_CGROUP_H */