aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
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 /kernel
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 'kernel')
-rw-r--r--kernel/cred.c4
-rw-r--r--kernel/delayacct.c2
-rw-r--r--kernel/fork.c22
-rw-r--r--kernel/pid.c2
4 files changed, 17 insertions, 13 deletions
diff --git a/kernel/cred.c b/kernel/cred.c
index 71179a09c1d6..0c0cd8a62285 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -569,8 +569,8 @@ EXPORT_SYMBOL(revert_creds);
569void __init cred_init(void) 569void __init cred_init(void)
570{ 570{
571 /* allocate a slab in which we can store credentials */ 571 /* allocate a slab in which we can store credentials */
572 cred_jar = kmem_cache_create("cred_jar", sizeof(struct cred), 572 cred_jar = kmem_cache_create("cred_jar", sizeof(struct cred), 0,
573 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL); 573 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL);
574} 574}
575 575
576/** 576/**
diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index ef90b04d783f..435c14a45118 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -34,7 +34,7 @@ __setup("nodelayacct", delayacct_setup_disable);
34 34
35void delayacct_init(void) 35void delayacct_init(void)
36{ 36{
37 delayacct_cache = KMEM_CACHE(task_delay_info, SLAB_PANIC); 37 delayacct_cache = KMEM_CACHE(task_delay_info, SLAB_PANIC|SLAB_ACCOUNT);
38 delayacct_tsk_init(&init_task); 38 delayacct_tsk_init(&init_task);
39} 39}
40 40
diff --git a/kernel/fork.c b/kernel/fork.c
index 6774e6b2e96d..51915842f1c0 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -300,9 +300,9 @@ void __init fork_init(void)
300#define ARCH_MIN_TASKALIGN L1_CACHE_BYTES 300#define ARCH_MIN_TASKALIGN L1_CACHE_BYTES
301#endif 301#endif
302 /* create a slab on which task_structs can be allocated */ 302 /* create a slab on which task_structs can be allocated */
303 task_struct_cachep = 303 task_struct_cachep = kmem_cache_create("task_struct",
304 kmem_cache_create("task_struct", arch_task_struct_size, 304 arch_task_struct_size, ARCH_MIN_TASKALIGN,
305 ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL); 305 SLAB_PANIC|SLAB_NOTRACK|SLAB_ACCOUNT, NULL);
306#endif 306#endif
307 307
308 /* do the arch specific task caches init */ 308 /* do the arch specific task caches init */
@@ -1848,16 +1848,19 @@ void __init proc_caches_init(void)
1848 sighand_cachep = kmem_cache_create("sighand_cache", 1848 sighand_cachep = kmem_cache_create("sighand_cache",
1849 sizeof(struct sighand_struct), 0, 1849 sizeof(struct sighand_struct), 0,
1850 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_DESTROY_BY_RCU| 1850 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_DESTROY_BY_RCU|
1851 SLAB_NOTRACK, sighand_ctor); 1851 SLAB_NOTRACK|SLAB_ACCOUNT, sighand_ctor);
1852 signal_cachep = kmem_cache_create("signal_cache", 1852 signal_cachep = kmem_cache_create("signal_cache",
1853 sizeof(struct signal_struct), 0, 1853 sizeof(struct signal_struct), 0,
1854 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL); 1854 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK|SLAB_ACCOUNT,
1855 NULL);
1855 files_cachep = kmem_cache_create("files_cache", 1856 files_cachep = kmem_cache_create("files_cache",
1856 sizeof(struct files_struct), 0, 1857 sizeof(struct files_struct), 0,
1857 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL); 1858 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK|SLAB_ACCOUNT,
1859 NULL);
1858 fs_cachep = kmem_cache_create("fs_cache", 1860 fs_cachep = kmem_cache_create("fs_cache",
1859 sizeof(struct fs_struct), 0, 1861 sizeof(struct fs_struct), 0,
1860 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL); 1862 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK|SLAB_ACCOUNT,
1863 NULL);
1861 /* 1864 /*
1862 * FIXME! The "sizeof(struct mm_struct)" currently includes the 1865 * FIXME! The "sizeof(struct mm_struct)" currently includes the
1863 * whole struct cpumask for the OFFSTACK case. We could change 1866 * whole struct cpumask for the OFFSTACK case. We could change
@@ -1867,8 +1870,9 @@ void __init proc_caches_init(void)
1867 */ 1870 */
1868 mm_cachep = kmem_cache_create("mm_struct", 1871 mm_cachep = kmem_cache_create("mm_struct",
1869 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN, 1872 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
1870 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL); 1873 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK|SLAB_ACCOUNT,
1871 vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC); 1874 NULL);
1875 vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC|SLAB_ACCOUNT);
1872 mmap_init(); 1876 mmap_init();
1873 nsproxy_cache_init(); 1877 nsproxy_cache_init();
1874} 1878}
diff --git a/kernel/pid.c b/kernel/pid.c
index 78b3d9f80d44..f4ad91b746f1 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -604,5 +604,5 @@ void __init pidmap_init(void)
604 atomic_dec(&init_pid_ns.pidmap[0].nr_free); 604 atomic_dec(&init_pid_ns.pidmap[0].nr_free);
605 605
606 init_pid_ns.pid_cachep = KMEM_CACHE(pid, 606 init_pid_ns.pid_cachep = KMEM_CACHE(pid,
607 SLAB_HWCACHE_ALIGN | SLAB_PANIC); 607 SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
608} 608}