Commit f4b00eab authored by Roman Gushchin's avatar Roman Gushchin Committed by Linus Torvalds

mm: kmem: rename memcg_kmem_(un)charge() into memcg_kmem_(un)charge_page()

Rename (__)memcg_kmem_(un)charge() into (__)memcg_kmem_(un)charge_page()
to better reflect what they are actually doing:

1) call __memcg_kmem_(un)charge_memcg() to actually charge or uncharge
   the current memcg

2) set or clear the PageKmemcg flag
Signed-off-by: default avatarRoman Gushchin <guro@fb.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarShakeel Butt <shakeelb@google.com>
Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Link: http://lkml.kernel.org/r/20200109202659.752357-4-guro@fb.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 50591183
...@@ -146,7 +146,7 @@ static int anon_pipe_buf_steal(struct pipe_inode_info *pipe, ...@@ -146,7 +146,7 @@ static int anon_pipe_buf_steal(struct pipe_inode_info *pipe,
struct page *page = buf->page; struct page *page = buf->page;
if (page_count(page) == 1) { if (page_count(page) == 1) {
memcg_kmem_uncharge(page, 0); memcg_kmem_uncharge_page(page, 0);
__SetPageLocked(page); __SetPageLocked(page);
return 0; return 0;
} }
......
...@@ -1367,8 +1367,8 @@ struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep); ...@@ -1367,8 +1367,8 @@ struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep);
void memcg_kmem_put_cache(struct kmem_cache *cachep); void memcg_kmem_put_cache(struct kmem_cache *cachep);
#ifdef CONFIG_MEMCG_KMEM #ifdef CONFIG_MEMCG_KMEM
int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order); int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order);
void __memcg_kmem_uncharge(struct page *page, int order); void __memcg_kmem_uncharge_page(struct page *page, int order);
int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, int order); int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, int order);
void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg, void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg,
unsigned int nr_pages); unsigned int nr_pages);
...@@ -1393,17 +1393,18 @@ static inline bool memcg_kmem_enabled(void) ...@@ -1393,17 +1393,18 @@ static inline bool memcg_kmem_enabled(void)
return static_branch_unlikely(&memcg_kmem_enabled_key); return static_branch_unlikely(&memcg_kmem_enabled_key);
} }
static inline int memcg_kmem_charge(struct page *page, gfp_t gfp, int order) static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
int order)
{ {
if (memcg_kmem_enabled()) if (memcg_kmem_enabled())
return __memcg_kmem_charge(page, gfp, order); return __memcg_kmem_charge_page(page, gfp, order);
return 0; return 0;
} }
static inline void memcg_kmem_uncharge(struct page *page, int order) static inline void memcg_kmem_uncharge_page(struct page *page, int order)
{ {
if (memcg_kmem_enabled()) if (memcg_kmem_enabled())
__memcg_kmem_uncharge(page, order); __memcg_kmem_uncharge_page(page, order);
} }
static inline int memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, static inline int memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp,
...@@ -1435,21 +1436,23 @@ struct mem_cgroup *mem_cgroup_from_obj(void *p); ...@@ -1435,21 +1436,23 @@ struct mem_cgroup *mem_cgroup_from_obj(void *p);
#else #else
static inline int memcg_kmem_charge(struct page *page, gfp_t gfp, int order) static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
int order)
{ {
return 0; return 0;
} }
static inline void memcg_kmem_uncharge(struct page *page, int order) static inline void memcg_kmem_uncharge_page(struct page *page, int order)
{ {
} }
static inline int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order) static inline int __memcg_kmem_charge_page(struct page *page, gfp_t gfp,
int order)
{ {
return 0; return 0;
} }
static inline void __memcg_kmem_uncharge(struct page *page, int order) static inline void __memcg_kmem_uncharge_page(struct page *page, int order)
{ {
} }
......
...@@ -281,7 +281,7 @@ static inline void free_thread_stack(struct task_struct *tsk) ...@@ -281,7 +281,7 @@ static inline void free_thread_stack(struct task_struct *tsk)
MEMCG_KERNEL_STACK_KB, MEMCG_KERNEL_STACK_KB,
-(int)(PAGE_SIZE / 1024)); -(int)(PAGE_SIZE / 1024));
memcg_kmem_uncharge(vm->pages[i], 0); memcg_kmem_uncharge_page(vm->pages[i], 0);
} }
for (i = 0; i < NR_CACHED_STACKS; i++) { for (i = 0; i < NR_CACHED_STACKS; i++) {
...@@ -413,12 +413,13 @@ static int memcg_charge_kernel_stack(struct task_struct *tsk) ...@@ -413,12 +413,13 @@ static int memcg_charge_kernel_stack(struct task_struct *tsk)
for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) { for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) {
/* /*
* If memcg_kmem_charge() fails, page->mem_cgroup * If memcg_kmem_charge_page() fails, page->mem_cgroup
* pointer is NULL, and both memcg_kmem_uncharge() * pointer is NULL, and both memcg_kmem_uncharge_page()
* and mod_memcg_page_state() in free_thread_stack() * and mod_memcg_page_state() in free_thread_stack()
* will ignore this page. So it's safe. * will ignore this page. So it's safe.
*/ */
ret = memcg_kmem_charge(vm->pages[i], GFP_KERNEL, 0); ret = memcg_kmem_charge_page(vm->pages[i], GFP_KERNEL,
0);
if (ret) if (ret)
return ret; return ret;
......
...@@ -2917,14 +2917,14 @@ int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, int order) ...@@ -2917,14 +2917,14 @@ int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, int order)
} }
/** /**
* __memcg_kmem_charge: charge a kmem page to the current memory cgroup * __memcg_kmem_charge_page: charge a kmem page to the current memory cgroup
* @page: page to charge * @page: page to charge
* @gfp: reclaim mode * @gfp: reclaim mode
* @order: allocation order * @order: allocation order
* *
* Returns 0 on success, an error code on failure. * Returns 0 on success, an error code on failure.
*/ */
int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order) int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order)
{ {
struct mem_cgroup *memcg; struct mem_cgroup *memcg;
int ret = 0; int ret = 0;
...@@ -2960,11 +2960,11 @@ void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg, ...@@ -2960,11 +2960,11 @@ void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg,
page_counter_uncharge(&memcg->memsw, nr_pages); page_counter_uncharge(&memcg->memsw, nr_pages);
} }
/** /**
* __memcg_kmem_uncharge: uncharge a kmem page * __memcg_kmem_uncharge_page: uncharge a kmem page
* @page: page to uncharge * @page: page to uncharge
* @order: allocation order * @order: allocation order
*/ */
void __memcg_kmem_uncharge(struct page *page, int order) void __memcg_kmem_uncharge_page(struct page *page, int order)
{ {
struct mem_cgroup *memcg = page->mem_cgroup; struct mem_cgroup *memcg = page->mem_cgroup;
unsigned int nr_pages = 1 << order; unsigned int nr_pages = 1 << order;
......
...@@ -1153,7 +1153,7 @@ static __always_inline bool free_pages_prepare(struct page *page, ...@@ -1153,7 +1153,7 @@ static __always_inline bool free_pages_prepare(struct page *page,
if (PageMappingFlags(page)) if (PageMappingFlags(page))
page->mapping = NULL; page->mapping = NULL;
if (memcg_kmem_enabled() && PageKmemcg(page)) if (memcg_kmem_enabled() && PageKmemcg(page))
__memcg_kmem_uncharge(page, order); __memcg_kmem_uncharge_page(page, order);
if (check_free) if (check_free)
bad += free_pages_check(page); bad += free_pages_check(page);
if (bad) if (bad)
...@@ -4753,7 +4753,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid, ...@@ -4753,7 +4753,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
out: out:
if (memcg_kmem_enabled() && (gfp_mask & __GFP_ACCOUNT) && page && if (memcg_kmem_enabled() && (gfp_mask & __GFP_ACCOUNT) && page &&
unlikely(__memcg_kmem_charge(page, gfp_mask, order) != 0)) { unlikely(__memcg_kmem_charge_page(page, gfp_mask, order) != 0)) {
__free_pages(page, order); __free_pages(page, order);
page = NULL; page = NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment