Skip to content

Commit 3406e91

Browse files
committed
mm, slub: make locking in deactivate_slab() irq-safe
dectivate_slab() now no longer touches the kmem_cache_cpu structure, so it will be possible to call it with irqs enabled. Just convert the spin_lock calls to their irq saving/restoring variants to make it irq-safe. Note we now have to use cmpxchg_double_slab() for irq-safe slab_lock(), because in some situations we don't take the list_lock, which would disable irqs. Signed-off-by: Vlastimil Babka <[email protected]>
1 parent a019d20 commit 3406e91

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mm/slub.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
22232223
enum slab_modes l = M_NONE, m = M_NONE;
22242224
void *nextfree, *freelist_iter, *freelist_tail;
22252225
int tail = DEACTIVATE_TO_HEAD;
2226+
unsigned long flags = 0;
22262227
struct page new;
22272228
struct page old;
22282229

@@ -2298,7 +2299,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
22982299
* that acquire_slab() will see a slab page that
22992300
* is frozen
23002301
*/
2301-
spin_lock(&n->list_lock);
2302+
spin_lock_irqsave(&n->list_lock, flags);
23022303
}
23032304
} else {
23042305
m = M_FULL;
@@ -2309,7 +2310,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
23092310
* slabs from diagnostic functions will not see
23102311
* any frozen slabs.
23112312
*/
2312-
spin_lock(&n->list_lock);
2313+
spin_lock_irqsave(&n->list_lock, flags);
23132314
}
23142315
}
23152316

@@ -2326,14 +2327,14 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
23262327
}
23272328

23282329
l = m;
2329-
if (!__cmpxchg_double_slab(s, page,
2330+
if (!cmpxchg_double_slab(s, page,
23302331
old.freelist, old.counters,
23312332
new.freelist, new.counters,
23322333
"unfreezing slab"))
23332334
goto redo;
23342335

23352336
if (lock)
2336-
spin_unlock(&n->list_lock);
2337+
spin_unlock_irqrestore(&n->list_lock, flags);
23372338

23382339
if (m == M_PARTIAL)
23392340
stat(s, tail);

0 commit comments

Comments
 (0)