page_cgroup.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /* flags for LRU placement */
  27. PCG_ACTIVE, /* page is active in this cgroup */
  28. PCG_FILE, /* page is file system backed */
  29. PCG_UNEVICTABLE, /* page is unevictableable */
  30. };
  31. #define TESTPCGFLAG(uname, lname) \
  32. static inline int PageCgroup##uname(struct page_cgroup *pc) \
  33. { return test_bit(PCG_##lname, &pc->flags); }
  34. #define SETPCGFLAG(uname, lname) \
  35. static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
  36. { set_bit(PCG_##lname, &pc->flags); }
  37. #define CLEARPCGFLAG(uname, lname) \
  38. static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
  39. { clear_bit(PCG_##lname, &pc->flags); }
  40. /* Cache flag is set only once (at allocation) */
  41. TESTPCGFLAG(Cache, CACHE)
  42. TESTPCGFLAG(Used, USED)
  43. CLEARPCGFLAG(Used, USED)
  44. /* LRU management flags (from global-lru definition) */
  45. TESTPCGFLAG(File, FILE)
  46. SETPCGFLAG(File, FILE)
  47. CLEARPCGFLAG(File, FILE)
  48. TESTPCGFLAG(Active, ACTIVE)
  49. SETPCGFLAG(Active, ACTIVE)
  50. CLEARPCGFLAG(Active, ACTIVE)
  51. TESTPCGFLAG(Unevictable, UNEVICTABLE)
  52. SETPCGFLAG(Unevictable, UNEVICTABLE)
  53. CLEARPCGFLAG(Unevictable, UNEVICTABLE)
  54. static inline int page_cgroup_nid(struct page_cgroup *pc)
  55. {
  56. return page_to_nid(pc->page);
  57. }
  58. static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
  59. {
  60. return page_zonenum(pc->page);
  61. }
  62. static inline void lock_page_cgroup(struct page_cgroup *pc)
  63. {
  64. bit_spin_lock(PCG_LOCK, &pc->flags);
  65. }
  66. static inline int trylock_page_cgroup(struct page_cgroup *pc)
  67. {
  68. return bit_spin_trylock(PCG_LOCK, &pc->flags);
  69. }
  70. static inline void unlock_page_cgroup(struct page_cgroup *pc)
  71. {
  72. bit_spin_unlock(PCG_LOCK, &pc->flags);
  73. }
  74. #else /* CONFIG_CGROUP_MEM_RES_CTLR */
  75. struct page_cgroup;
  76. static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
  77. {
  78. }
  79. static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
  80. {
  81. return NULL;
  82. }
  83. static inline void page_cgroup_init(void)
  84. {
  85. }
  86. #endif
  87. #endif