page_cgroup.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. };
  37. #define TESTPCGFLAG(uname, lname) \
  38. static inline int PageCgroup##uname(struct page_cgroup *pc) \
  39. { return test_bit(PCG_##lname, &pc->flags); }
  40. #define SETPCGFLAG(uname, lname) \
  41. static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
  42. { set_bit(PCG_##lname, &pc->flags); }
  43. #define CLEARPCGFLAG(uname, lname) \
  44. static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
  45. { clear_bit(PCG_##lname, &pc->flags); }
  46. /* Cache flag is set only once (at allocation) */
  47. TESTPCGFLAG(Cache, CACHE)
  48. TESTPCGFLAG(Used, USED)
  49. CLEARPCGFLAG(Used, USED)
  50. static inline int page_cgroup_nid(struct page_cgroup *pc)
  51. {
  52. return page_to_nid(pc->page);
  53. }
  54. static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
  55. {
  56. return page_zonenum(pc->page);
  57. }
  58. static inline void lock_page_cgroup(struct page_cgroup *pc)
  59. {
  60. bit_spin_lock(PCG_LOCK, &pc->flags);
  61. }
  62. static inline int trylock_page_cgroup(struct page_cgroup *pc)
  63. {
  64. return bit_spin_trylock(PCG_LOCK, &pc->flags);
  65. }
  66. static inline void unlock_page_cgroup(struct page_cgroup *pc)
  67. {
  68. bit_spin_unlock(PCG_LOCK, &pc->flags);
  69. }
  70. #else /* CONFIG_CGROUP_MEM_RES_CTLR */
  71. struct page_cgroup;
  72. static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
  73. {
  74. }
  75. static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
  76. {
  77. return NULL;
  78. }
  79. static inline void page_cgroup_init(void)
  80. {
  81. }
  82. static inline void __init page_cgroup_init_flatmem(void)
  83. {
  84. }
  85. #endif
  86. #include <linux/swap.h>
  87. #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
  88. extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
  89. extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
  90. extern int swap_cgroup_swapon(int type, unsigned long max_pages);
  91. extern void swap_cgroup_swapoff(int type);
  92. #else
  93. static inline
  94. unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
  95. {
  96. return 0;
  97. }
  98. static inline
  99. unsigned short lookup_swap_cgroup(swp_entry_t ent)
  100. {
  101. return 0;
  102. }
  103. static inline int
  104. swap_cgroup_swapon(int type, unsigned long max_pages)
  105. {
  106. return 0;
  107. }
  108. static inline void swap_cgroup_swapoff(int type)
  109. {
  110. return;
  111. }
  112. #endif
  113. #endif