Skip to content

Commit b5d8ca7

Browse files
Ravikiran G ThirumalaiLinus Torvalds
authored andcommitted
[PATCH] slab: remove cachep->spinlock
Remove cachep->spinlock. Locking has moved to the kmem_list3 and most of the structures protected earlier by cachep->spinlock is now protected by the l3->list_lock. slab cache tunables like batchcount are accessed always with the cache_chain_mutex held. Patch tested on SMP and NUMA kernels with dbench processes running, constant onlining/offlining, and constant cache tuning, all at the same time. Signed-off-by: Ravikiran Thirumalai <kiran@scalex86.org> Cc: Christoph Lameter <christoph@lameter.com> Cc: Pekka Enberg <penberg@cs.helsinki.fi> Cc: Manfred Spraul <manfred@colorfullife.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent a737b3e commit b5d8ca7

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

‎mm/slab.c‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,19 @@ static void kmem_list3_init(struct kmem_list3 *parent)
372372
struct kmem_cache {
373373
/* 1) per-cpu data, touched during every alloc/free */
374374
struct array_cache *array[NR_CPUS];
375+
/* 2) Cache tunables. Protected by cache_chain_mutex */
375376
unsigned int batchcount;
376377
unsigned int limit;
377378
unsigned int shared;
379+
378380
unsigned int buffer_size;
379-
/* 2) touched by every alloc & free from the backend */
381+
/* 3) touched by every alloc & free from the backend */
380382
struct kmem_list3 *nodelists[MAX_NUMNODES];
383+
381384
unsigned int flags; /* constant flags */
382385
unsigned int num; /* # of objs per slab */
383-
spinlock_t spinlock;
384386

385-
/* 3) cache_grow/shrink */
387+
/* 4) cache_grow/shrink */
386388
/* order of pgs per slab (2^n) */
387389
unsigned int gfporder;
388390

@@ -401,11 +403,11 @@ struct kmem_cache {
401403
/* de-constructor func */
402404
void (*dtor) (void *, struct kmem_cache *, unsigned long);
403405

404-
/* 4) cache creation/removal */
406+
/* 5) cache creation/removal */
405407
const char *name;
406408
struct list_head next;
407409

408-
/* 5) statistics */
410+
/* 6) statistics */
409411
#if STATS
410412
unsigned long num_active;
411413
unsigned long num_allocations;
@@ -661,7 +663,6 @@ static struct kmem_cache cache_cache = {
661663
.shared = 1,
662664
.buffer_size = sizeof(struct kmem_cache),
663665
.flags = SLAB_NO_REAP,
664-
.spinlock = SPIN_LOCK_UNLOCKED,
665666
.name = "kmem_cache",
666667
#if DEBUG
667668
.obj_size = sizeof(struct kmem_cache),
@@ -2057,7 +2058,6 @@ kmem_cache_create (const char *name, size_t size, size_t align,
20572058
cachep->gfpflags = 0;
20582059
if (flags & SLAB_CACHE_DMA)
20592060
cachep->gfpflags |= GFP_DMA;
2060-
spin_lock_init(&cachep->spinlock);
20612061
cachep->buffer_size = size;
20622062

20632063
if (flags & CFLGS_OFF_SLAB)
@@ -3425,6 +3425,7 @@ static void do_ccupdate_local(void *info)
34253425
new->new[smp_processor_id()] = old;
34263426
}
34273427

3428+
/* Always called with the cache_chain_mutex held */
34283429
static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
34293430
int batchcount, int shared)
34303431
{
@@ -3446,11 +3447,9 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
34463447
smp_call_function_all_cpus(do_ccupdate_local, (void *)&new);
34473448

34483449
check_irq_on();
3449-
spin_lock(&cachep->spinlock);
34503450
cachep->batchcount = batchcount;
34513451
cachep->limit = limit;
34523452
cachep->shared = shared;
3453-
spin_unlock(&cachep->spinlock);
34543453

34553454
for_each_online_cpu(i) {
34563455
struct array_cache *ccold = new.new[i];
@@ -3471,6 +3470,7 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
34713470
return 0;
34723471
}
34733472

3473+
/* Called with cache_chain_mutex held always */
34743474
static void enable_cpucache(struct kmem_cache *cachep)
34753475
{
34763476
int err;
@@ -3705,7 +3705,6 @@ static int s_show(struct seq_file *m, void *p)
37053705
int node;
37063706
struct kmem_list3 *l3;
37073707

3708-
spin_lock(&cachep->spinlock);
37093708
active_objs = 0;
37103709
num_slabs = 0;
37113710
for_each_online_node(node) {
@@ -3788,7 +3787,6 @@ static int s_show(struct seq_file *m, void *p)
37883787
}
37893788
#endif
37903789
seq_putc(m, '\n');
3791-
spin_unlock(&cachep->spinlock);
37923790
return 0;
37933791
}
37943792

0 commit comments

Comments
 (0)