[Slub allocator] There are chances that kmem_cache_cpu->freelist islost if the process is rescheduled to a differenet cpu before the local irqis disabled when calling __slab_alloc()

From: zhihua che
Date: Sun Dec 11 2011 - 04:58:22 EST


Hi, everyone
I'm reading the linux kernel and now focusing on memory
management. Image a case like below, a process on cpu0 is calling
slab_alloc for a free obj, and finds that the c0->freelist is null,
where c0 is the pointer to a kmem_cache_cpu object corresponding to
the current cpu0. Then the process resorts to the __slab_alloc and
HERE, the process MAY BE rescheduled to a different cpu1 before the
local irq is disabled. Then, a new kmem_cache_cpu pointer c1 is
retrieved. I think there are chances that with respect to this
different kmem_cache_cpu pointer c1, c1->freelist is NOT null and
could be lost if the following code is executed in __slab_alloc:

load_freelist:
VM_BUG_ON(!page->frozen);
c->freelist = get_free_pointer(s, object);
/* THIS ASSIGNMENT */
c->tid = next_tid(c->tid);
local_irq_restore(flags);
return object;

I think the assignment above may cause the loss of the
freelist pointed by c->freelist, because c now points to a different
kmem_cache_cpu object due the reschedule and this freelist may be NOT
null as I imaged earlier.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/