2008-10-19 11:28:16 +08:00
|
|
|
#ifndef __LINUX_PAGE_CGROUP_H
|
|
|
|
#define __LINUX_PAGE_CGROUP_H
|
|
|
|
|
|
|
|
#ifdef CONFIG_CGROUP_MEM_RES_CTLR
|
|
|
|
#include <linux/bit_spinlock.h>
|
|
|
|
/*
|
|
|
|
* Page Cgroup can be considered as an extended mem_map.
|
|
|
|
* A page_cgroup page is associated with every page descriptor. The
|
|
|
|
* page_cgroup helps us identify information about the cgroup
|
|
|
|
* All page cgroups are allocated at boot or memory hotplug event,
|
|
|
|
* then the page cgroup for pfn always exists.
|
|
|
|
*/
|
|
|
|
struct page_cgroup {
|
|
|
|
unsigned long flags;
|
|
|
|
struct mem_cgroup *mem_cgroup;
|
|
|
|
struct page *page;
|
|
|
|
struct list_head lru; /* per cgroup LRU list */
|
|
|
|
};
|
|
|
|
|
2008-11-23 01:33:24 +08:00
|
|
|
void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
|
2009-06-12 15:33:53 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SPARSEMEM
|
|
|
|
static inline void __init page_cgroup_init_flatmem(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
extern void __init page_cgroup_init(void);
|
|
|
|
#else
|
|
|
|
void __init page_cgroup_init_flatmem(void);
|
|
|
|
static inline void __init page_cgroup_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-19 11:28:16 +08:00
|
|
|
struct page_cgroup *lookup_page_cgroup(struct page *page);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
/* flags for mem_cgroup */
|
|
|
|
PCG_LOCK, /* page cgroup is locked */
|
|
|
|
PCG_CACHE, /* charged as cache */
|
|
|
|
PCG_USED, /* this object is in use. */
|
2009-09-24 06:56:32 +08:00
|
|
|
PCG_ACCT_LRU, /* page has been accounted for */
|
2010-04-07 05:35:05 +08:00
|
|
|
PCG_FILE_MAPPED, /* page is accounted as "mapped" */
|
2008-10-19 11:28:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define TESTPCGFLAG(uname, lname) \
|
|
|
|
static inline int PageCgroup##uname(struct page_cgroup *pc) \
|
|
|
|
{ return test_bit(PCG_##lname, &pc->flags); }
|
|
|
|
|
|
|
|
#define SETPCGFLAG(uname, lname) \
|
|
|
|
static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
|
|
|
|
{ set_bit(PCG_##lname, &pc->flags); }
|
|
|
|
|
|
|
|
#define CLEARPCGFLAG(uname, lname) \
|
|
|
|
static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
|
|
|
|
{ clear_bit(PCG_##lname, &pc->flags); }
|
|
|
|
|
2009-09-24 06:56:32 +08:00
|
|
|
#define TESTCLEARPCGFLAG(uname, lname) \
|
|
|
|
static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
|
|
|
|
{ return test_and_clear_bit(PCG_##lname, &pc->flags); }
|
|
|
|
|
2009-12-16 08:47:11 +08:00
|
|
|
TESTPCGFLAG(Locked, LOCK)
|
|
|
|
|
2008-10-19 11:28:16 +08:00
|
|
|
/* Cache flag is set only once (at allocation) */
|
|
|
|
TESTPCGFLAG(Cache, CACHE)
|
2009-09-24 06:56:32 +08:00
|
|
|
CLEARPCGFLAG(Cache, CACHE)
|
|
|
|
SETPCGFLAG(Cache, CACHE)
|
2008-10-19 11:28:16 +08:00
|
|
|
|
|
|
|
TESTPCGFLAG(Used, USED)
|
|
|
|
CLEARPCGFLAG(Used, USED)
|
2009-09-24 06:56:32 +08:00
|
|
|
SETPCGFLAG(Used, USED)
|
|
|
|
|
|
|
|
SETPCGFLAG(AcctLRU, ACCT_LRU)
|
|
|
|
CLEARPCGFLAG(AcctLRU, ACCT_LRU)
|
|
|
|
TESTPCGFLAG(AcctLRU, ACCT_LRU)
|
|
|
|
TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU)
|
2008-10-19 11:28:16 +08:00
|
|
|
|
2010-04-07 05:35:05 +08:00
|
|
|
|
|
|
|
SETPCGFLAG(FileMapped, FILE_MAPPED)
|
|
|
|
CLEARPCGFLAG(FileMapped, FILE_MAPPED)
|
|
|
|
TESTPCGFLAG(FileMapped, FILE_MAPPED)
|
|
|
|
|
2008-10-19 11:28:16 +08:00
|
|
|
static inline int page_cgroup_nid(struct page_cgroup *pc)
|
|
|
|
{
|
|
|
|
return page_to_nid(pc->page);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
|
|
|
|
{
|
|
|
|
return page_zonenum(pc->page);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void lock_page_cgroup(struct page_cgroup *pc)
|
|
|
|
{
|
|
|
|
bit_spin_lock(PCG_LOCK, &pc->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void unlock_page_cgroup(struct page_cgroup *pc)
|
|
|
|
{
|
|
|
|
bit_spin_unlock(PCG_LOCK, &pc->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_CGROUP_MEM_RES_CTLR */
|
|
|
|
struct page_cgroup;
|
|
|
|
|
2008-11-23 01:33:24 +08:00
|
|
|
static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
|
2008-10-19 11:28:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-10-23 05:15:05 +08:00
|
|
|
|
|
|
|
static inline void page_cgroup_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-12 15:33:53 +08:00
|
|
|
static inline void __init page_cgroup_init_flatmem(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-08 10:07:58 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <linux/swap.h>
|
2009-09-20 18:50:44 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
|
2010-03-11 07:22:17 +08:00
|
|
|
extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
|
|
|
|
unsigned short old, unsigned short new);
|
2009-04-03 07:57:45 +08:00
|
|
|
extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
|
|
|
|
extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
|
2009-01-08 10:07:58 +08:00
|
|
|
extern int swap_cgroup_swapon(int type, unsigned long max_pages);
|
|
|
|
extern void swap_cgroup_swapoff(int type);
|
|
|
|
#else
|
|
|
|
|
|
|
|
static inline
|
2009-04-03 07:57:45 +08:00
|
|
|
unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
|
2009-01-08 10:07:58 +08:00
|
|
|
{
|
2009-04-03 07:57:45 +08:00
|
|
|
return 0;
|
2009-01-08 10:07:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
2009-04-03 07:57:45 +08:00
|
|
|
unsigned short lookup_swap_cgroup(swp_entry_t ent)
|
2009-01-08 10:07:58 +08:00
|
|
|
{
|
2009-04-03 07:57:45 +08:00
|
|
|
return 0;
|
2009-01-08 10:07:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
swap_cgroup_swapon(int type, unsigned long max_pages)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void swap_cgroup_swapoff(int type)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-19 11:28:16 +08:00
|
|
|
#endif
|
|
|
|
#endif
|