mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
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>
This commit is contained in:
committed by
Linus Torvalds
parent
37f08dda29
commit
5d097056c9
@@ -767,7 +767,7 @@ static int __init spufs_init(void)
|
||||
ret = -ENOMEM;
|
||||
spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
|
||||
sizeof(struct spufs_inode_info), 0,
|
||||
SLAB_HWCACHE_ALIGN, spufs_init_once);
|
||||
SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, spufs_init_once);
|
||||
|
||||
if (!spufs_inode_cache)
|
||||
goto out;
|
||||
|
||||
@@ -106,7 +106,8 @@ static int __init init_lustre_lite(void)
|
||||
rc = -ENOMEM;
|
||||
ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
|
||||
sizeof(struct ll_inode_info),
|
||||
0, SLAB_HWCACHE_ALIGN, NULL);
|
||||
0, SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT,
|
||||
NULL);
|
||||
if (ll_inode_cachep == NULL)
|
||||
goto out_cache;
|
||||
|
||||
|
||||
@@ -575,7 +575,7 @@ static int v9fs_init_inode_cache(void)
|
||||
v9fs_inode_cache = kmem_cache_create("v9fs_inode_cache",
|
||||
sizeof(struct v9fs_inode),
|
||||
0, (SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
||||
v9fs_inode_init_once);
|
||||
if (!v9fs_inode_cache)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -271,7 +271,7 @@ static int __init init_inodecache(void)
|
||||
adfs_inode_cachep = kmem_cache_create("adfs_inode_cache",
|
||||
sizeof(struct adfs_inode_info),
|
||||
0, (SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
||||
init_once);
|
||||
if (adfs_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -132,7 +132,7 @@ static int __init init_inodecache(void)
|
||||
affs_inode_cachep = kmem_cache_create("affs_inode_cache",
|
||||
sizeof(struct affs_inode_info),
|
||||
0, (SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
||||
init_once);
|
||||
if (affs_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -91,7 +91,7 @@ int __init afs_fs_init(void)
|
||||
afs_inode_cachep = kmem_cache_create("afs_inode_cache",
|
||||
sizeof(struct afs_vnode),
|
||||
0,
|
||||
SLAB_HWCACHE_ALIGN,
|
||||
SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT,
|
||||
afs_i_init_once);
|
||||
if (!afs_inode_cachep) {
|
||||
printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n");
|
||||
|
||||
@@ -434,7 +434,7 @@ befs_init_inodecache(void)
|
||||
befs_inode_cachep = kmem_cache_create("befs_inode_cache",
|
||||
sizeof (struct befs_inode_info),
|
||||
0, (SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
||||
init_once);
|
||||
if (befs_inode_cachep == NULL) {
|
||||
pr_err("%s: Couldn't initialize inode slabcache\n", __func__);
|
||||
|
||||
@@ -270,7 +270,7 @@ static int __init init_inodecache(void)
|
||||
bfs_inode_cachep = kmem_cache_create("bfs_inode_cache",
|
||||
sizeof(struct bfs_inode_info),
|
||||
0, (SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
||||
init_once);
|
||||
if (bfs_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -595,7 +595,7 @@ void __init bdev_cache_init(void)
|
||||
|
||||
bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),
|
||||
0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD|SLAB_PANIC),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT|SLAB_PANIC),
|
||||
init_once);
|
||||
err = register_filesystem(&bd_type);
|
||||
if (err)
|
||||
|
||||
@@ -9161,7 +9161,8 @@ int btrfs_init_cachep(void)
|
||||
{
|
||||
btrfs_inode_cachep = kmem_cache_create("btrfs_inode",
|
||||
sizeof(struct btrfs_inode), 0,
|
||||
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, init_once);
|
||||
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD | SLAB_ACCOUNT,
|
||||
init_once);
|
||||
if (!btrfs_inode_cachep)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -639,8 +639,8 @@ static int __init init_caches(void)
|
||||
ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
|
||||
sizeof(struct ceph_inode_info),
|
||||
__alignof__(struct ceph_inode_info),
|
||||
(SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
|
||||
ceph_inode_init_once);
|
||||
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
|
||||
SLAB_ACCOUNT, ceph_inode_init_once);
|
||||
if (ceph_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -1092,7 +1092,7 @@ cifs_init_inodecache(void)
|
||||
cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
|
||||
sizeof(struct cifsInodeInfo),
|
||||
0, (SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
||||
cifs_init_once);
|
||||
if (cifs_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -74,9 +74,9 @@ static void init_once(void *foo)
|
||||
int __init coda_init_inodecache(void)
|
||||
{
|
||||
coda_inode_cachep = kmem_cache_create("coda_inode_cache",
|
||||
sizeof(struct coda_inode_info),
|
||||
0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
|
||||
init_once);
|
||||
sizeof(struct coda_inode_info), 0,
|
||||
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
|
||||
SLAB_ACCOUNT, init_once);
|
||||
if (coda_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
|
||||
@@ -1571,7 +1571,8 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
|
||||
dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
|
||||
if (name->len > DNAME_INLINE_LEN-1) {
|
||||
size_t size = offsetof(struct external_name, name[1]);
|
||||
struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
|
||||
struct external_name *p = kmalloc(size + name->len,
|
||||
GFP_KERNEL_ACCOUNT);
|
||||
if (!p) {
|
||||
kmem_cache_free(dentry_cache, dentry);
|
||||
return NULL;
|
||||
@@ -3415,7 +3416,7 @@ static void __init dcache_init(void)
|
||||
* of the dcache.
|
||||
*/
|
||||
dentry_cache = KMEM_CACHE(dentry,
|
||||
SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
|
||||
SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD|SLAB_ACCOUNT);
|
||||
|
||||
/* Hash may have been set up in dcache_init_early */
|
||||
if (!hashdist)
|
||||
|
||||
@@ -663,6 +663,7 @@ static struct ecryptfs_cache_info {
|
||||
struct kmem_cache **cache;
|
||||
const char *name;
|
||||
size_t size;
|
||||
unsigned long flags;
|
||||
void (*ctor)(void *obj);
|
||||
} ecryptfs_cache_infos[] = {
|
||||
{
|
||||
@@ -684,6 +685,7 @@ static struct ecryptfs_cache_info {
|
||||
.cache = &ecryptfs_inode_info_cache,
|
||||
.name = "ecryptfs_inode_cache",
|
||||
.size = sizeof(struct ecryptfs_inode_info),
|
||||
.flags = SLAB_ACCOUNT,
|
||||
.ctor = inode_info_init_once,
|
||||
},
|
||||
{
|
||||
@@ -755,8 +757,8 @@ static int ecryptfs_init_kmem_caches(void)
|
||||
struct ecryptfs_cache_info *info;
|
||||
|
||||
info = &ecryptfs_cache_infos[i];
|
||||
*(info->cache) = kmem_cache_create(info->name, info->size,
|
||||
0, SLAB_HWCACHE_ALIGN, info->ctor);
|
||||
*(info->cache) = kmem_cache_create(info->name, info->size, 0,
|
||||
SLAB_HWCACHE_ALIGN | info->flags, info->ctor);
|
||||
if (!*(info->cache)) {
|
||||
ecryptfs_free_kmem_caches();
|
||||
ecryptfs_printk(KERN_WARNING, "%s: "
|
||||
|
||||
@@ -94,9 +94,9 @@ static void init_once(void *foo)
|
||||
static int __init init_inodecache(void)
|
||||
{
|
||||
efs_inode_cachep = kmem_cache_create("efs_inode_cache",
|
||||
sizeof(struct efs_inode_info),
|
||||
0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
|
||||
init_once);
|
||||
sizeof(struct efs_inode_info), 0,
|
||||
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
|
||||
SLAB_ACCOUNT, init_once);
|
||||
if (efs_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
|
||||
@@ -194,8 +194,8 @@ static int init_inodecache(void)
|
||||
{
|
||||
exofs_inode_cachep = kmem_cache_create("exofs_inode_cache",
|
||||
sizeof(struct exofs_i_info), 0,
|
||||
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
|
||||
exofs_init_once);
|
||||
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD |
|
||||
SLAB_ACCOUNT, exofs_init_once);
|
||||
if (exofs_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
|
||||
@@ -203,7 +203,7 @@ static int __init init_inodecache(void)
|
||||
ext2_inode_cachep = kmem_cache_create("ext2_inode_cache",
|
||||
sizeof(struct ext2_inode_info),
|
||||
0, (SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
||||
init_once);
|
||||
if (ext2_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -966,7 +966,7 @@ static int __init init_inodecache(void)
|
||||
ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
|
||||
sizeof(struct ext4_inode_info),
|
||||
0, (SLAB_RECLAIM_ACCOUNT|
|
||||
SLAB_MEM_SPREAD),
|
||||
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
||||
init_once);
|
||||
if (ext4_inode_cachep == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1541,8 +1541,9 @@ MODULE_ALIAS_FS("f2fs");
|
||||
|
||||
static int __init init_inodecache(void)
|
||||
{
|
||||
f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache",
|
||||
sizeof(struct f2fs_inode_info));
|
||||
f2fs_inode_cachep = kmem_cache_create("f2fs_inode_cache",
|
||||
sizeof(struct f2fs_inode_info), 0,
|
||||
SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT, NULL);
|
||||
if (!f2fs_inode_cachep)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user