page_cgroup.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef __LINUX_PAGE_CGROUP_H
  2. #define __LINUX_PAGE_CGROUP_H
  3. enum {
  4. /* flags for mem_cgroup */
  5. PCG_USED = 0x01, /* This page is charged to a memcg */
  6. PCG_MEM = 0x02, /* This page holds a memory charge */
  7. PCG_MEMSW = 0x04, /* This page holds a memory+swap charge */
  8. };
  9. struct pglist_data;
  10. #ifdef CONFIG_MEMCG
  11. struct mem_cgroup;
  12. /*
  13. * Page Cgroup can be considered as an extended mem_map.
  14. * A page_cgroup page is associated with every page descriptor. The
  15. * page_cgroup helps us identify information about the cgroup
  16. * All page cgroups are allocated at boot or memory hotplug event,
  17. * then the page cgroup for pfn always exists.
  18. */
  19. struct page_cgroup {
  20. unsigned long flags;
  21. struct mem_cgroup *mem_cgroup;
  22. };
  23. extern void pgdat_page_cgroup_init(struct pglist_data *pgdat);
  24. #ifdef CONFIG_SPARSEMEM
  25. static inline void page_cgroup_init_flatmem(void)
  26. {
  27. }
  28. extern void page_cgroup_init(void);
  29. #else
  30. extern void page_cgroup_init_flatmem(void);
  31. static inline void page_cgroup_init(void)
  32. {
  33. }
  34. #endif
  35. struct page_cgroup *lookup_page_cgroup(struct page *page);
  36. static inline int PageCgroupUsed(struct page_cgroup *pc)
  37. {
  38. return !!(pc->flags & PCG_USED);
  39. }
  40. #else /* !CONFIG_MEMCG */
  41. struct page_cgroup;
  42. static inline void pgdat_page_cgroup_init(struct pglist_data *pgdat)
  43. {
  44. }
  45. static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
  46. {
  47. return NULL;
  48. }
  49. static inline void page_cgroup_init(void)
  50. {
  51. }
  52. static inline void page_cgroup_init_flatmem(void)
  53. {
  54. }
  55. #endif /* CONFIG_MEMCG */
  56. #include <linux/swap.h>
  57. #ifdef CONFIG_MEMCG_SWAP
  58. extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
  59. unsigned short old, unsigned short new);
  60. extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
  61. extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
  62. extern int swap_cgroup_swapon(int type, unsigned long max_pages);
  63. extern void swap_cgroup_swapoff(int type);
  64. #else
  65. static inline
  66. unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
  67. {
  68. return 0;
  69. }
  70. static inline
  71. unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
  72. {
  73. return 0;
  74. }
  75. static inline int
  76. swap_cgroup_swapon(int type, unsigned long max_pages)
  77. {
  78. return 0;
  79. }
  80. static inline void swap_cgroup_swapoff(int type)
  81. {
  82. return;
  83. }
  84. #endif /* CONFIG_MEMCG_SWAP */
  85. #endif /* __LINUX_PAGE_CGROUP_H */