From: Peter Zijlstra > Sent: 13 February 2019 12:57 ... ... > In the past I've proposed a GCC plugin / checker that would verify the > alignment requirements against the various allocators. > > For instance: > > struct foo { > spinlock_t a; > int b; > } __cacheline_aligned; > > struct foo *my_foo = kmalloc(sizeof(struct foo), GFP_KERNEL); > > would result in a warning; because obviously kmalloc (as per > ARCH_SLAB_MINALIGN) doesn't respect the cacheline alignment of the type. > > Of course; it appears our kmalloc() function definition doesn't even > have a __malloc attribute, so there's plenty work to be done here. We could pass the alignment to the allocator by defining something like: #define do_malloc(x) ((x) = (typeof(*(x)))_do_malloc(sizeof *(x), __alignof__(*(x)))) Although you probably want to compile-time detect alignments that are smaller than the normal minimal alignment. If the allocator needs to add a header it would need to use the byte before the allocated item to find the header. OTOH adding a header is horrid for page-sized items. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) _______________________________________________ linux-snps-arc mailing list linux-snps-arc@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/linux-snps-arc