summaryrefslogtreecommitdiffstats
path: root/fs/dcache.c
diff options
context:
space:
mode:
authorVladimir Davydov <vdavydov@virtuozzo.com>2016-01-14 18:18:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-14 19:00:49 -0500
commit5d097056c9a017a3b720849efb5432f37acabbac (patch)
treee960a2513a789101097e97cfda27b247ef8650eb /fs/dcache.c
parent37f08dda29dac8a595999b8d3eaa9bf0f763dd9d (diff)
kmemcg: account certain kmem allocations to memcg
Mark those kmem allocations that are known to be easily triggered from userspace as __GFP_ACCOUNT/SLAB_ACCOUNT, which makes them accounted to memcg. For the list, see below: - threadinfo - task_struct - task_delay_info - pid - cred - mm_struct - vm_area_struct and vm_region (nommu) - anon_vma and anon_vma_chain - signal_struct - sighand_struct - fs_struct - files_struct - fdtable and fdtable->full_fds_bits - dentry and external_name - inode for all filesystems. This is the most tedious part, because most filesystems overwrite the alloc_inode method. The list is far from complete, so feel free to add more objects. Nevertheless, it should be close to "account everything" approach and keep most workloads within bounds. Malevolent users will be able to breach the limit, but this was possible even with the former "account everything" approach (simply because it did not account everything in fact). [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Tejun Heo <tj@kernel.org> Cc: Greg Thelen <gthelen@google.com> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/dcache.c')
-rw-r--r--fs/dcache.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index 8d38cd07b207..b4539e84e577 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1571,7 +1571,8 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
1571 dentry->d_iname[DNAME_INLINE_LEN-1] = 0; 1571 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
1572 if (name->len > DNAME_INLINE_LEN-1) { 1572 if (name->len > DNAME_INLINE_LEN-1) {
1573 size_t size = offsetof(struct external_name, name[1]); 1573 size_t size = offsetof(struct external_name, name[1]);
1574 struct external_name *p = kmalloc(size + name->len, GFP_KERNEL); 1574 struct external_name *p = kmalloc(size + name->len,
1575 GFP_KERNEL_ACCOUNT);
1575 if (!p) { 1576 if (!p) {
1576 kmem_cache_free(dentry_cache, dentry); 1577 kmem_cache_free(dentry_cache, dentry);
1577 return NULL; 1578 return NULL;
@@ -3415,7 +3416,7 @@ static void __init dcache_init(void)
3415 * of the dcache. 3416 * of the dcache.
3416 */ 3417 */
3417 dentry_cache = KMEM_CACHE(dentry, 3418 dentry_cache = KMEM_CACHE(dentry,
3418 SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD); 3419 SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD|SLAB_ACCOUNT);
3419 3420
3420 /* Hash may have been set up in dcache_init_early */ 3421 /* Hash may have been set up in dcache_init_early */
3421 if (!hashdist) 3422 if (!hashdist)