2024-09-09 08:52:07 +00:00
|
|
|
#ifndef __LINUX_PAGE_CGROUP_H
|
|
|
|
#define __LINUX_PAGE_CGROUP_H
|
|
|
|
|
|
|
|
enum {
|
|
|
|
/* flags for mem_cgroup */
|
2024-09-09 08:57:42 +00:00
|
|
|
PCG_USED = 0x01, /* This page is charged to a memcg */
|
|
|
|
PCG_MEM = 0x02, /* This page holds a memory charge */
|
|
|
|
PCG_MEMSW = 0x04, /* This page holds a memory+swap charge */
|
2024-09-09 08:52:07 +00:00
|
|
|
};
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
struct pglist_data;
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
#ifdef CONFIG_MEMCG
|
|
|
|
struct mem_cgroup;
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
};
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
extern void pgdat_page_cgroup_init(struct pglist_data *pgdat);
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SPARSEMEM
|
2024-09-09 08:57:42 +00:00
|
|
|
static inline void page_cgroup_init_flatmem(void)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
|
|
|
}
|
2024-09-09 08:57:42 +00:00
|
|
|
extern void page_cgroup_init(void);
|
2024-09-09 08:52:07 +00:00
|
|
|
#else
|
2024-09-09 08:57:42 +00:00
|
|
|
extern void page_cgroup_init_flatmem(void);
|
|
|
|
static inline void page_cgroup_init(void)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct page_cgroup *lookup_page_cgroup(struct page *page);
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
static inline int PageCgroupUsed(struct page_cgroup *pc)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
2024-09-09 08:57:42 +00:00
|
|
|
return !!(pc->flags & PCG_USED);
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
2024-09-09 08:57:42 +00:00
|
|
|
#else /* !CONFIG_MEMCG */
|
2024-09-09 08:52:07 +00:00
|
|
|
struct page_cgroup;
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
static inline void pgdat_page_cgroup_init(struct pglist_data *pgdat)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void page_cgroup_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
static inline void page_cgroup_init_flatmem(void)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
|
|
|
}
|
2024-09-09 08:57:42 +00:00
|
|
|
#endif /* CONFIG_MEMCG */
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
#include <linux/swap.h>
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
#ifdef CONFIG_MEMCG_SWAP
|
2024-09-09 08:52:07 +00:00
|
|
|
extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
|
|
|
|
unsigned short old, unsigned short new);
|
|
|
|
extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
|
|
|
|
extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
|
|
|
|
extern int swap_cgroup_swapon(int type, unsigned long max_pages);
|
|
|
|
extern void swap_cgroup_swapoff(int type);
|
|
|
|
#else
|
|
|
|
|
|
|
|
static inline
|
|
|
|
unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
swap_cgroup_swapon(int type, unsigned long max_pages)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void swap_cgroup_swapoff(int type)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
#endif /* CONFIG_MEMCG_SWAP */
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
#endif /* __LINUX_PAGE_CGROUP_H */
|