Skip to content

Commit 57c2561

Browse files
arter97Demon000
authored andcommitted
cgroup: use kmem_cache pool for struct cgrp_cset_link
These get allocated and freed millions of times on Android. Use a dedicated kmem_cache pool and avoid costly dynamic memory allocations. Signed-off-by: Park Ju Hyung <[email protected]>
1 parent aa40052 commit 57c2561

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

kernel/cgroup/cgroup.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ EXPORT_SYMBOL_GPL(of_css);
727727
; \
728728
else
729729

730+
static struct kmem_cache *cgrp_cset_link_pool;
731+
730732
/*
731733
* The default css_set - used by init and its children prior to any
732734
* hierarchies being mounted. It contains a pointer to the root state
@@ -957,7 +959,7 @@ void put_css_set_locked(struct css_set *cset)
957959
list_del(&link->cgrp_link);
958960
if (cgroup_parent(link->cgrp))
959961
cgroup_put(link->cgrp);
960-
kfree(link);
962+
kmem_cache_free(cgrp_cset_link_pool, link);
961963
}
962964

963965
if (css_set_threaded(cset)) {
@@ -1107,7 +1109,7 @@ static void free_cgrp_cset_links(struct list_head *links_to_free)
11071109

11081110
list_for_each_entry_safe(link, tmp_link, links_to_free, cset_link) {
11091111
list_del(&link->cset_link);
1110-
kfree(link);
1112+
kmem_cache_free(cgrp_cset_link_pool, link);
11111113
}
11121114
}
11131115

@@ -1127,7 +1129,7 @@ static int allocate_cgrp_cset_links(int count, struct list_head *tmp_links)
11271129
INIT_LIST_HEAD(tmp_links);
11281130

11291131
for (i = 0; i < count; i++) {
1130-
link = kzalloc(sizeof(*link), GFP_KERNEL);
1132+
link = kmem_cache_zalloc(cgrp_cset_link_pool, GFP_KERNEL);
11311133
if (!link) {
11321134
free_cgrp_cset_links(tmp_links);
11331135
return -ENOMEM;
@@ -1339,7 +1341,7 @@ static void cgroup_destroy_root(struct cgroup_root *root)
13391341
list_for_each_entry_safe(link, tmp_link, &cgrp->cset_links, cset_link) {
13401342
list_del(&link->cset_link);
13411343
list_del(&link->cgrp_link);
1342-
kfree(link);
1344+
kmem_cache_free(cgrp_cset_link_pool, link);
13431345
}
13441346

13451347
spin_unlock_irq(&css_set_lock);
@@ -5732,6 +5734,8 @@ int __init cgroup_init(void)
57325734
struct cgroup_subsys *ss;
57335735
int ssid;
57345736

5737+
cgrp_cset_link_pool = KMEM_CACHE(cgrp_cset_link, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
5738+
57355739
BUILD_BUG_ON(CGROUP_SUBSYS_COUNT > 16);
57365740
BUG_ON(cgroup_init_cftypes(NULL, cgroup_base_files));
57375741
BUG_ON(cgroup_init_cftypes(NULL, cgroup1_base_files));

0 commit comments

Comments
 (0)