Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1326718 > unrolled thread
| Started by | Vladimir Davydov <vdavydov@virtuozzo.com> |
|---|---|
| First post | 2016-02-04 13:20 +0100 |
| Last post | 2016-02-04 21:40 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] mm: memcontrol: do not bypass slab charge if memcg is offline Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-04 13:20 +0100
Re: [PATCH] mm: memcontrol: do not bypass slab charge if memcg is offline Johannes Weiner <hannes@cmpxchg.org> - 2016-02-04 21:40 +0100
| From | Vladimir Davydov <vdavydov@virtuozzo.com> |
|---|---|
| Date | 2016-02-04 13:20 +0100 |
| Subject | [PATCH] mm: memcontrol: do not bypass slab charge if memcg is offline |
| Message-ID | <qYr3c-8vU-15@gated-at.bofh.it> |
Slab pages are charged in two steps. First, an appropriate per memcg
cache is selected (see memcg_kmem_get_cache) basing on the current
context, then the new slab page is charged to the memory cgroup which
the selected cache was created for (see memcg_charge_slab ->
__memcg_kmem_charge_memcg). It is OK to bypass kmemcg charge at step 1,
but if step 1 succeeded and we successfully allocated a new slab page,
step 2 must be performed, otherwise we would get a per memcg kmem cache
which contains a slab that does not hold a reference to the memory
cgroup owning the cache. Since per memcg kmem caches are destroyed on
memcg css free, this could result in freeing a cache while there are
still active objects in it.
However, currently we will bypass slab page charge if the memory cgroup
owning the cache is offline (see __memcg_kmem_charge_memcg). This is
very unlikely to occur in practice, because for this to happen a process
must be migrated to a different cgroup and the old cgroup must be
removed while the process is in kmalloc somewhere between steps 1 and 2
(e.g. trying to allocate a new page). Nevertheless, it's still better
to eliminate such a possibility.
Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
---
mm/memcontrol.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 3e4199830456..f36b20f5b3ed 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2325,9 +2325,6 @@ int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order,
struct page_counter *counter;
int ret;
- if (!memcg_kmem_online(memcg))
- return 0;
-
ret = try_charge(memcg, gfp, nr_pages);
if (ret)
return ret;
@@ -2346,10 +2343,11 @@ int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order,
int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order)
{
struct mem_cgroup *memcg;
- int ret;
+ int ret = 0;
memcg = get_mem_cgroup_from_mm(current->mm);
- ret = __memcg_kmem_charge_memcg(page, gfp, order, memcg);
+ if (memcg_kmem_online(memcg))
+ ret = __memcg_kmem_charge_memcg(page, gfp, order, memcg);
css_put(&memcg->css);
return ret;
}
--
2.1.4
[toc] | [next] | [standalone]
| From | Johannes Weiner <hannes@cmpxchg.org> |
|---|---|
| Date | 2016-02-04 21:40 +0100 |
| Subject | Re: [PATCH] mm: memcontrol: do not bypass slab charge if memcg is offline |
| Message-ID | <qYyR4-6Xw-5@gated-at.bofh.it> |
| In reply to | #1326718 |
On Thu, Feb 04, 2016 at 03:17:55PM +0300, Vladimir Davydov wrote: > Slab pages are charged in two steps. First, an appropriate per memcg > cache is selected (see memcg_kmem_get_cache) basing on the current > context, then the new slab page is charged to the memory cgroup which > the selected cache was created for (see memcg_charge_slab -> > __memcg_kmem_charge_memcg). It is OK to bypass kmemcg charge at step 1, > but if step 1 succeeded and we successfully allocated a new slab page, > step 2 must be performed, otherwise we would get a per memcg kmem cache > which contains a slab that does not hold a reference to the memory > cgroup owning the cache. Since per memcg kmem caches are destroyed on > memcg css free, this could result in freeing a cache while there are > still active objects in it. > > However, currently we will bypass slab page charge if the memory cgroup > owning the cache is offline (see __memcg_kmem_charge_memcg). This is > very unlikely to occur in practice, because for this to happen a process > must be migrated to a different cgroup and the old cgroup must be > removed while the process is in kmalloc somewhere between steps 1 and 2 > (e.g. trying to allocate a new page). Nevertheless, it's still better > to eliminate such a possibility. > > Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web