On Wed, Sep 9, 2015 at 4:02 PM, Christoph Lameter <cl@xxxxxxxxx> wrote: > On Tue, 8 Sep 2015, Dmitry Vyukov wrote: > >> > There is no access to p in the first thread. If there are such accesses >> > then they are illegal. A user of slab allocators must ensure that there >> > are no accesses after freeing the object. And since there is a thread >> > that at random checks p and frees it when not NULL then no other thread >> > would be allowed to touch the object. >> >> >> But the memory allocator itself (kmalloc/kfree) generally reads and >> writes the object (e.g. storing object size in header before object, >> writing redzone in debug mode, reading and checking redzone in debug >> mode, building freelist using first word of the object, etc). There is >> no different between user accesses and memory allocator accesses just >> before returning the object from kmalloc and right after accepting the >> object in kfree. > > There is a difference. The object is not accessible to any code before > kmalloc() returns. And it must not be accessible anymore when kfree() is called. > Thus the object is under exclusive control of the allocators when it is > handled. Yes, the object should not be accessible to other threads when kfree is called. But in all examples above it is accessible. For example, in the last example it is still being accessed by kmalloc. Since there are no memory barriers, kmalloc does not happen-before kfree, it happens concurrently with kfree, thus memory accesses from kmalloc and kfree can be intermixed. It would not be the case on a sequentially consistent machine/language, but most machines and the implementation language do not give sequential consistency guarantees. -- Dmitry Vyukov, Software Engineer, dvyukov@xxxxxxxxxx Google Germany GmbH, Dienerstraße 12, 80331, München Geschäftsführer: Graham Law, Christine Elizabeth Flores Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Diese E-Mail ist vertraulich. Wenn Sie nicht der richtige Adressat sind, leiten Sie diese bitte nicht weiter, informieren Sie den Absender und löschen Sie die E-Mail und alle Anhänge. Vielen Dank. This e-mail is confidential. If you are not the right addressee please do not forward it, please inform the sender, and please erase this e-mail including any attachments. Thanks. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href