Skip to contentSkip to conversation

race in mempool_alloc/free

PATCH New Chris Mason 1 participant 1 message Mar 11, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 race in mempool_alloc/free

Hello everyone,

mempool_alloc and mempool_free check pool->curr_nr without any locks held. This can lead to skipping a wakeup when there are people waiting, and sleeping when there are free elements in the pool.

I can't trigger this reliably, but sooner or later someone on ppc is probably going to hit it.

-chris

mm/mempool.c +3 -0
@@ -203,6 +203,7 @@
 	 * If the pool is less than 50% full and we can perform effective
 	 * page reclaim then try harder to allocate an element.
 	 */
+	mb();
 	if ((gfp_mask & __GFP_FS) && (gfp_mask != gfp_nowait) &&
 				(pool->curr_nr <= pool->min_nr/2)) {
 		element = pool->alloc(gfp_mask, pool->pool_data);
@@ -230,6 +231,7 @@
 	blk_run_queues();
 
 	prepare_to_wait(&pool->wait, &wait, TASK_UNINTERRUPTIBLE);
+	mb();
 	if (!pool->curr_nr)
 		io_schedule();
 	finish_wait(&pool->wait, &wait);
@@ -250,6 +252,7 @@
 {
 	unsigned long flags;
 
+	mb();
 	if (pool->curr_nr < pool->min_nr) {
 		spin_lock_irqsave(&pool->lock, flags);
 		if (pool->curr_nr < pool->min_nr) {