Skip to content

Commit bf0dea2

Browse files
JoonsooKimtorvalds
authored andcommitted
mm/slab: use percpu allocator for cpu cache
Because of chicken and egg problem, initialization of SLAB is really complicated. We need to allocate cpu cache through SLAB to make the kmem_cache work, but before initialization of kmem_cache, allocation through SLAB is impossible. On the other hand, SLUB does initialization in a more simple way. It uses percpu allocator to allocate cpu cache so there is no chicken and egg problem. So, this patch try to use percpu allocator in SLAB. This simplifies the initialization step in SLAB so that we could maintain SLAB code more easily. In my testing there is no performance difference. This implementation relies on percpu allocator. Because percpu allocator uses vmalloc address space, vmalloc address space could be exhausted by this change on many cpu system with *32 bit* kernel. This implementation can cover 1024 cpus in worst case by following calculation. Worst: 1024 cpus * 4 bytes for pointer * 300 kmem_caches * 120 objects per cpu_cache = 140 MB Normal: 1024 cpus * 4 bytes for pointer * 150 kmem_caches(slab merge) * 80 objects per cpu_cache = 46 MB Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Acked-by: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Jeremiah Mahler <jmmahler@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 12220de commit bf0dea2

3 files changed

Lines changed: 78 additions & 182 deletions

File tree

‎include/linux/slab_def.h‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99

1010
struct kmem_cache {
11+
struct array_cache __percpu *cpu_cache;
12+
1113
/* 1) Cache tunables. Protected by slab_mutex */
1214
unsigned int batchcount;
1315
unsigned int limit;
@@ -71,23 +73,7 @@ struct kmem_cache {
7173
struct memcg_cache_params *memcg_params;
7274
#endif
7375

74-
/* 6) per-cpu/per-node data, touched during every alloc/free */
75-
/*
76-
* We put array[] at the end of kmem_cache, because we want to size
77-
* this array to nr_cpu_ids slots instead of NR_CPUS
78-
* (see kmem_cache_init())
79-
* We still use [NR_CPUS] and not [1] or [0] because cache_cache
80-
* is statically defined, so we reserve the max number of cpus.
81-
*
82-
* We also need to guarantee that the list is able to accomodate a
83-
* pointer for each node since "nodelists" uses the remainder of
84-
* available pointers.
85-
*/
86-
struct kmem_cache_node **node;
87-
struct array_cache *array[NR_CPUS + MAX_NUMNODES];
88-
/*
89-
* Do not add fields after array[]
90-
*/
76+
struct kmem_cache_node *node[MAX_NUMNODES];
9177
};
9278

9379
#endif /* _LINUX_SLAB_DEF_H */

0 commit comments

Comments
 (0)