aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.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 /kernel/fork.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 'kernel/fork.c')
-rw-r--r--kernel/fork.c22
1 files changed, 13 insertions, 9 deletions
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}