page_cgroup.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. void __init page_cgroup_init(void);
  20. struct page_cgroup *lookup_page_cgroup(struct page *page);
  21. enum {
  22. /* flags for mem_cgroup */
  23. PCG_LOCK, /* page cgroup is locked */
  24. PCG_CACHE, /* charged as cache */
  25. PCG_USED, /* this object is in use. */
  26. };
  27. #define TESTPCGFLAG(uname, lname) \
  28. static inline int PageCgroup##uname(struct page_cgroup *pc) \
  29. { return test_bit(PCG_##lname, &pc->flags); }
  30. #define SETPCGFLAG(uname, lname) \
  31. static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
  32. { set_bit(PCG_##lname, &pc->flags); }
  33. #define CLEARPCGFLAG(uname, lname) \
  34. static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
  35. { clear_bit(PCG_##lname, &pc->flags); }
  36. /* Cache flag is set only once (at allocation) */
  37. TESTPCGFLAG(Cache, CACHE)
  38. TESTPCGFLAG(Used, USED)
  39. CLEARPCGFLAG(Used, USED)
  40. static inline int page_cgroup_nid(struct page_cgroup *pc)
  41. {
  42. return page_to_nid(pc->page);
  43. }
  44. static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
  45. {
  46. return page_zonenum(pc->page);
  47. }
  48. static inline void lock_page_cgroup(struct page_cgroup *pc)
  49. {
  50. bit_spin_lock(PCG_LOCK, &pc->flags);
  51. }
  52. static inline int trylock_page_cgroup(struct page_cgroup *pc)
  53. {
  54. return bit_spin_trylock(PCG_LOCK, &pc->flags);
  55. }
  56. static inline void unlock_page_cgroup(struct page_cgroup *pc)
  57. {
  58. bit_spin_unlock(PCG_LOCK, &pc->flags);
  59. }
  60. #else /* CONFIG_CGROUP_MEM_RES_CTLR */
  61. struct page_cgroup;
  62. static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
  63. {
  64. }
  65. static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
  66. {
  67. return NULL;
  68. }
  69. static inline void page_cgroup_init(void)
  70. {
  71. }
  72. #endif
  73. #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
  74. #include <linux/swap.h>
  75. extern struct mem_cgroup *
  76. swap_cgroup_record(swp_entry_t ent, struct mem_cgroup *mem);
  77. extern struct mem_cgroup *lookup_swap_cgroup(swp_entry_t ent);
  78. extern int swap_cgroup_swapon(int type, unsigned long max_pages);
  79. extern void swap_cgroup_swapoff(int type);
  80. #else
  81. #include <linux/swap.h>
  82. static inline
  83. struct mem_cgroup *swap_cgroup_record(swp_entry_t ent, struct mem_cgroup *mem)
  84. {
  85. return NULL;
  86. }
  87. static inline
  88. struct mem_cgroup *lookup_swap_cgroup(swp_entry_t ent)
  89. {
  90. return NULL;
  91. }
  92. static inline int
  93. swap_cgroup_swapon(int type, unsigned long max_pages)
  94. {
  95. return 0;
  96. }
  97. static inline void swap_cgroup_swapoff(int type)
  98. {
  99. return;
  100. }
  101. #endif
  102. #endif