Commit 10eaec2f authored by Roman Gushchin's avatar Roman Gushchin Committed by Linus Torvalds

mm: kmem: cleanup (__)memcg_kmem_charge_memcg() arguments

Patch series "mm: memcg: kmem API cleanup", v2.

This patchset aims to clean up the kernel memory charging API.  It doesn't
bring any functional changes, just removes unused arguments, renames some
functions and fixes some comments.

Currently it's not obvious which functions are most basic
(memcg_kmem_(un)charge_memcg()) and which are based on them
(memcg_kmem_(un)charge()).  The patchset renames these functions and
removes unused arguments:

TL;DR:
was:
  memcg_kmem_charge_memcg(page, gfp, order, memcg)
  memcg_kmem_uncharge_memcg(memcg, nr_pages)
  memcg_kmem_charge(page, gfp, order)
  memcg_kmem_uncharge(page, order)

now:
  memcg_kmem_charge(memcg, gfp, nr_pages)
  memcg_kmem_uncharge(memcg, nr_pages)
  memcg_kmem_charge_page(page, gfp, order)
  memcg_kmem_uncharge_page(page, order)

This patch (of 6):

The first argument of memcg_kmem_charge_memcg() and
__memcg_kmem_charge_memcg() is the page pointer and it's not used.  Let's
drop it.

Memcg pointer is passed as the last argument.  Move it to the first place
for consistency with other memcg functions, e.g.
__memcg_kmem_uncharge_memcg() or try_charge().
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-2-guro@fb.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4f103c63
...@@ -1369,8 +1369,7 @@ void memcg_kmem_put_cache(struct kmem_cache *cachep); ...@@ -1369,8 +1369,7 @@ 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(struct page *page, gfp_t gfp, int order);
void __memcg_kmem_uncharge(struct page *page, int order); void __memcg_kmem_uncharge(struct page *page, int order);
int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order, int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, int order);
struct mem_cgroup *memcg);
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);
...@@ -1407,11 +1406,11 @@ static inline void memcg_kmem_uncharge(struct page *page, int order) ...@@ -1407,11 +1406,11 @@ static inline void memcg_kmem_uncharge(struct page *page, int order)
__memcg_kmem_uncharge(page, order); __memcg_kmem_uncharge(page, order);
} }
static inline int memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, static inline int memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp,
int order, struct mem_cgroup *memcg) int order)
{ {
if (memcg_kmem_enabled()) if (memcg_kmem_enabled())
return __memcg_kmem_charge_memcg(page, gfp, order, memcg); return __memcg_kmem_charge_memcg(memcg, gfp, order);
return 0; return 0;
} }
......
...@@ -2882,15 +2882,13 @@ void memcg_kmem_put_cache(struct kmem_cache *cachep) ...@@ -2882,15 +2882,13 @@ void memcg_kmem_put_cache(struct kmem_cache *cachep)
/** /**
* __memcg_kmem_charge_memcg: charge a kmem page * __memcg_kmem_charge_memcg: charge a kmem page
* @page: page to charge * @memcg: memory cgroup to charge
* @gfp: reclaim mode * @gfp: reclaim mode
* @order: allocation order * @order: allocation order
* @memcg: memory cgroup to charge
* *
* Returns 0 on success, an error code on failure. * Returns 0 on success, an error code on failure.
*/ */
int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order, int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, int order)
struct mem_cgroup *memcg)
{ {
unsigned int nr_pages = 1 << order; unsigned int nr_pages = 1 << order;
struct page_counter *counter; struct page_counter *counter;
...@@ -2936,7 +2934,7 @@ int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order) ...@@ -2936,7 +2934,7 @@ int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order)
memcg = get_mem_cgroup_from_current(); memcg = get_mem_cgroup_from_current();
if (!mem_cgroup_is_root(memcg)) { if (!mem_cgroup_is_root(memcg)) {
ret = __memcg_kmem_charge_memcg(page, gfp, order, memcg); ret = __memcg_kmem_charge_memcg(memcg, gfp, order);
if (!ret) { if (!ret) {
page->mem_cgroup = memcg; page->mem_cgroup = memcg;
__SetPageKmemcg(page); __SetPageKmemcg(page);
......
...@@ -365,7 +365,7 @@ static __always_inline int memcg_charge_slab(struct page *page, ...@@ -365,7 +365,7 @@ static __always_inline int memcg_charge_slab(struct page *page,
return 0; return 0;
} }
ret = memcg_kmem_charge_memcg(page, gfp, order, memcg); ret = memcg_kmem_charge_memcg(memcg, gfp, order);
if (ret) if (ret)
goto out; goto out;
......
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