linux/include/linux/page_cgroup.h
<<
>>
Prefs
   1#ifndef __LINUX_PAGE_CGROUP_H
   2#define __LINUX_PAGE_CGROUP_H
   3
   4enum {
   5        /* flags for mem_cgroup */
   6        PCG_LOCK,  /* Lock for pc->mem_cgroup and following bits. */
   7        PCG_USED, /* this object is in use. */
   8        PCG_MIGRATION, /* under page migration */
   9        __NR_PCG_FLAGS,
  10};
  11
  12#ifndef __GENERATING_BOUNDS_H
  13#include <generated/bounds.h>
  14
  15#ifdef CONFIG_MEMCG
  16#include <linux/bit_spinlock.h>
  17
  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 */
  25struct page_cgroup {
  26        unsigned long flags;
  27        struct mem_cgroup *mem_cgroup;
  28};
  29
  30void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
  31
  32#ifdef CONFIG_SPARSEMEM
  33static inline void __init page_cgroup_init_flatmem(void)
  34{
  35}
  36extern void __init page_cgroup_init(void);
  37#else
  38void __init page_cgroup_init_flatmem(void);
  39static inline void __init page_cgroup_init(void)
  40{
  41}
  42#endif
  43
  44struct page_cgroup *lookup_page_cgroup(struct page *page);
  45struct page *lookup_cgroup_page(struct page_cgroup *pc);
  46
  47#define TESTPCGFLAG(uname, lname)                       \
  48static inline int PageCgroup##uname(struct page_cgroup *pc)     \
  49        { return test_bit(PCG_##lname, &pc->flags); }
  50
  51#define SETPCGFLAG(uname, lname)                        \
  52static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
  53        { set_bit(PCG_##lname, &pc->flags);  }
  54
  55#define CLEARPCGFLAG(uname, lname)                      \
  56static inline void ClearPageCgroup##uname(struct page_cgroup *pc)       \
  57        { clear_bit(PCG_##lname, &pc->flags);  }
  58
  59#define TESTCLEARPCGFLAG(uname, lname)                  \
  60static inline int TestClearPageCgroup##uname(struct page_cgroup *pc)    \
  61        { return test_and_clear_bit(PCG_##lname, &pc->flags);  }
  62
  63TESTPCGFLAG(Used, USED)
  64CLEARPCGFLAG(Used, USED)
  65SETPCGFLAG(Used, USED)
  66
  67SETPCGFLAG(Migration, MIGRATION)
  68CLEARPCGFLAG(Migration, MIGRATION)
  69TESTPCGFLAG(Migration, MIGRATION)
  70
  71static inline void lock_page_cgroup(struct page_cgroup *pc)
  72{
  73        /*
  74         * Don't take this lock in IRQ context.
  75         * This lock is for pc->mem_cgroup, USED, MIGRATION
  76         */
  77        bit_spin_lock(PCG_LOCK, &pc->flags);
  78}
  79
  80static inline void unlock_page_cgroup(struct page_cgroup *pc)
  81{
  82        bit_spin_unlock(PCG_LOCK, &pc->flags);
  83}
  84
  85#else /* CONFIG_MEMCG */
  86struct page_cgroup;
  87
  88static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
  89{
  90}
  91
  92static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
  93{
  94        return NULL;
  95}
  96
  97static inline void page_cgroup_init(void)
  98{
  99}
 100
 101static inline void __init page_cgroup_init_flatmem(void)
 102{
 103}
 104
 105#endif /* CONFIG_MEMCG */
 106
 107#include <linux/swap.h>
 108
 109#ifdef CONFIG_MEMCG_SWAP
 110extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
 111                                        unsigned short old, unsigned short new);
 112extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
 113extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
 114extern int swap_cgroup_swapon(int type, unsigned long max_pages);
 115extern void swap_cgroup_swapoff(int type);
 116#else
 117
 118static inline
 119unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
 120{
 121        return 0;
 122}
 123
 124static inline
 125unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
 126{
 127        return 0;
 128}
 129
 130static inline int
 131swap_cgroup_swapon(int type, unsigned long max_pages)
 132{
 133        return 0;
 134}
 135
 136static inline void swap_cgroup_swapoff(int type)
 137{
 138        return;
 139}
 140
 141#endif /* CONFIG_MEMCG_SWAP */
 142
 143#endif /* !__GENERATING_BOUNDS_H */
 144
 145#endif /* __LINUX_PAGE_CGROUP_H */
 146