Skip to content

Commit

Permalink
idr: create idr_layer_cache at boot time
Browse files Browse the repository at this point in the history
Avoid a possible kmem_cache_create() failure by creating idr_layer_cache
unconditionary at boot time rather than creating it on-demand when idr_init()
is called the first time.

This change also enables us to eliminate the check every time idr_init() is
called.

[[email protected]: rename init_id_cache() to idr_init_cache()]
[[email protected]: fix alpha build]
Signed-off-by: Akinobu Mita <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
mita authored and torvalds committed Apr 29, 2008
1 parent 801678c commit 199f0ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/linux/idr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <linux/types.h>
#include <linux/bitops.h>
#include <linux/init.h>

#if BITS_PER_LONG == 32
# define IDR_BITS 5
Expand Down Expand Up @@ -115,4 +116,6 @@ void ida_remove(struct ida *ida, int id);
void ida_destroy(struct ida *ida);
void ida_init(struct ida *ida);

void __init idr_init_cache(void);

#endif /* __IDR_H__ */
2 changes: 2 additions & 0 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include <linux/kthread.h>
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/idr.h>

#include <asm/io.h>
#include <asm/bugs.h>
Expand Down Expand Up @@ -637,6 +638,7 @@ asmlinkage void __init start_kernel(void)
enable_debug_pagealloc();
cpu_hotplug_init();
kmem_cache_init();
idr_init_cache();
setup_per_cpu_pageset();
numa_policy_init();
if (late_time_init)
Expand Down
10 changes: 4 additions & 6 deletions lib/idr.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,11 @@ static void idr_cache_ctor(struct kmem_cache *idr_layer_cache, void *idr_layer)
memset(idr_layer, 0, sizeof(struct idr_layer));
}

static int init_id_cache(void)
void __init idr_init_cache(void)
{
if (!idr_layer_cache)
idr_layer_cache = kmem_cache_create("idr_layer_cache",
sizeof(struct idr_layer), 0, 0, idr_cache_ctor);
return 0;
idr_layer_cache = kmem_cache_create("idr_layer_cache",
sizeof(struct idr_layer), 0, SLAB_PANIC,
idr_cache_ctor);
}

/**
Expand All @@ -602,7 +601,6 @@ static int init_id_cache(void)
*/
void idr_init(struct idr *idp)
{
init_id_cache();
memset(idp, 0, sizeof(struct idr));
spin_lock_init(&idp->lock);
}
Expand Down

0 comments on commit 199f0ca

Please sign in to comment.