Skip to content

Commit 2f9baa9

Browse files
Christoph Lameterpenberg
authored andcommitted
slab: Use the new create_boot_cache function to simplify bootstrap
Simplify setup and reduce code in kmem_cache_init(). This allows us to get rid of initarray_cache as well as the manual setup code for the kmem_cache and kmem_cache_node arrays during bootstrap. We introduce a new bootstrap state "PARTIAL" for slab that signals the creation of a kmem_cache boot cache. Signed-off-by: Christoph Lameter <cl@linux.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
1 parent dffb4d6 commit 2f9baa9

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

mm/slab.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,6 @@ static struct cache_names __initdata cache_names[] = {
547547
#undef CACHE
548548
};
549549

550-
static struct arraycache_init initarray_cache __initdata =
551-
{ {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
552550
static struct arraycache_init initarray_generic =
553551
{ {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
554552

@@ -1572,12 +1570,9 @@ static void setup_nodelists_pointer(struct kmem_cache *cachep)
15721570
*/
15731571
void __init kmem_cache_init(void)
15741572
{
1575-
size_t left_over;
15761573
struct cache_sizes *sizes;
15771574
struct cache_names *names;
15781575
int i;
1579-
int order;
1580-
int node;
15811576

15821577
kmem_cache = &kmem_cache_boot;
15831578
setup_nodelists_pointer(kmem_cache);
@@ -1618,36 +1613,16 @@ void __init kmem_cache_init(void)
16181613
* 6) Resize the head arrays of the kmalloc caches to their final sizes.
16191614
*/
16201615

1621-
node = numa_mem_id();
1622-
16231616
/* 1) create the kmem_cache */
1624-
INIT_LIST_HEAD(&slab_caches);
1625-
list_add(&kmem_cache->list, &slab_caches);
1626-
kmem_cache->colour_off = cache_line_size();
1627-
kmem_cache->array[smp_processor_id()] = &initarray_cache.cache;
16281617

16291618
/*
16301619
* struct kmem_cache size depends on nr_node_ids & nr_cpu_ids
16311620
*/
1632-
kmem_cache->size = offsetof(struct kmem_cache, array[nr_cpu_ids]) +
1633-
nr_node_ids * sizeof(struct kmem_list3 *);
1634-
kmem_cache->object_size = kmem_cache->size;
1635-
kmem_cache->size = ALIGN(kmem_cache->object_size,
1636-
cache_line_size());
1637-
kmem_cache->reciprocal_buffer_size =
1638-
reciprocal_value(kmem_cache->size);
1639-
1640-
for (order = 0; order < MAX_ORDER; order++) {
1641-
cache_estimate(order, kmem_cache->size,
1642-
cache_line_size(), 0, &left_over, &kmem_cache->num);
1643-
if (kmem_cache->num)
1644-
break;
1645-
}
1646-
BUG_ON(!kmem_cache->num);
1647-
kmem_cache->gfporder = order;
1648-
kmem_cache->colour = left_over / kmem_cache->colour_off;
1649-
kmem_cache->slab_size = ALIGN(kmem_cache->num * sizeof(kmem_bufctl_t) +
1650-
sizeof(struct slab), cache_line_size());
1621+
create_boot_cache(kmem_cache, "kmem_cache",
1622+
offsetof(struct kmem_cache, array[nr_cpu_ids]) +
1623+
nr_node_ids * sizeof(struct kmem_list3 *),
1624+
SLAB_HWCACHE_ALIGN);
1625+
list_add(&kmem_cache->list, &slab_caches);
16511626

16521627
/* 2+3) create the kmalloc caches */
16531628
sizes = malloc_sizes;
@@ -1695,7 +1670,6 @@ void __init kmem_cache_init(void)
16951670

16961671
ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT);
16971672

1698-
BUG_ON(cpu_cache_get(kmem_cache) != &initarray_cache.cache);
16991673
memcpy(ptr, cpu_cache_get(kmem_cache),
17001674
sizeof(struct arraycache_init));
17011675
/*
@@ -2250,15 +2224,23 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp)
22502224

22512225
if (slab_state == DOWN) {
22522226
/*
2253-
* Note: the first kmem_cache_create must create the cache
2227+
* Note: Creation of first cache (kmem_cache).
2228+
* The setup_list3s is taken care
2229+
* of by the caller of __kmem_cache_create
2230+
*/
2231+
cachep->array[smp_processor_id()] = &initarray_generic.cache;
2232+
slab_state = PARTIAL;
2233+
} else if (slab_state == PARTIAL) {
2234+
/*
2235+
* Note: the second kmem_cache_create must create the cache
22542236
* that's used by kmalloc(24), otherwise the creation of
22552237
* further caches will BUG().
22562238
*/
22572239
cachep->array[smp_processor_id()] = &initarray_generic.cache;
22582240

22592241
/*
22602242
* If the cache that's used by kmalloc(sizeof(kmem_list3)) is
2261-
* the first cache, then we need to set up all its list3s,
2243+
* the second cache, then we need to set up all its list3s,
22622244
* otherwise the creation of further caches will BUG().
22632245
*/
22642246
set_up_list3s(cachep, SIZE_AC);
@@ -2267,6 +2249,7 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp)
22672249
else
22682250
slab_state = PARTIAL_ARRAYCACHE;
22692251
} else {
2252+
/* Remaining boot caches */
22702253
cachep->array[smp_processor_id()] =
22712254
kmalloc(sizeof(struct arraycache_init), gfp);
22722255

0 commit comments

Comments
 (0)