Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1330248
| From | Vladimir Davydov <vdavydov@virtuozzo.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 4/6] radix-tree: account radix_tree_node to memory cgroup |
| Date | 2016-02-09 15:00 +0100 |
| Message-ID | <r0gZJ-4N6-29@gated-at.bofh.it> (permalink) |
| References | <r0gZH-4N6-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Allocation of radix_tree_node objects can be easily triggered from userspace, so we should account them to memory cgroup. Besides, we need them accounted for making shadow node shrinker per memcg (see mm/workingset.c). A tricky thing about accounting radix_tree_node objects is that they are mostly allocated through radix_tree_preload(), so we can't just set SLAB_ACCOUNT for radix_tree_node_cachep - that would likely result in a lot of unrelated cgroups using objects from each other's caches. One way to overcome this would be making radix tree preloads per memcg, but that would probably look cumbersome and overcomplicated. Instead, we make radix_tree_node_alloc() first try to allocate from the cache with __GFP_ACCOUNT, no matter if the caller has preloaded or not, and only if it fails fall back on using per cpu preloads. This should make most allocations accounted. Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> --- lib/radix-tree.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/radix-tree.c b/lib/radix-tree.c index e2511b8e2300..1624c4117961 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -227,6 +227,15 @@ radix_tree_node_alloc(struct radix_tree_root *root) struct radix_tree_preload *rtp; /* + * Even if the caller has preloaded, try to allocate from the + * cache first for the new node to get accounted. + */ + ret = kmem_cache_alloc(radix_tree_node_cachep, + gfp_mask | __GFP_ACCOUNT | __GFP_NOWARN); + if (ret) + goto out; + + /* * Provided the caller has preloaded here, we will always * succeed in getting a node here (and never reach * kmem_cache_alloc) @@ -243,10 +252,11 @@ radix_tree_node_alloc(struct radix_tree_root *root) * for debugging. */ kmemleak_update_trace(ret); + goto out; } - if (ret == NULL) - ret = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask); - + ret = kmem_cache_alloc(radix_tree_node_cachep, + gfp_mask | __GFP_ACCOUNT); +out: BUG_ON(radix_tree_is_indirect_ptr(ret)); return ret; } -- 2.1.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 0/6] mm: workingset: make shadow node shrinker memcg aware Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-09 15:00 +0100
[PATCH v2 4/6] radix-tree: account radix_tree_node to memory cgroup Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-09 15:00 +0100
[PATCH v2 5/6] mm: workingset: size shadow nodes lru basing on file cache size Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-09 15:00 +0100
Re: [PATCH v2 5/6] mm: workingset: size shadow nodes lru basing on file cache size Johannes Weiner <hannes@cmpxchg.org> - 2016-02-10 00:20 +0100
[PATCH v2 2/6] mm: vmscan: pass root_mem_cgroup instead of NULL to memcg aware shrinker Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-09 15:00 +0100
[PATCH v2 3/6] mm: memcontrol: zap memcg_kmem_online helper Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-09 15:00 +0100
[PATCH v2 1/6] mm: memcontrol: enable kmem accounting for all cgroups in the legacy hierarchy Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-09 15:00 +0100
csiph-web