Re: [PATCH v2 1/2] mm/pageblock: mitigation cmpxchg false sharing in pageblock flags

From: Matthew Wilcox
Date: Sun Aug 30 2020 - 06:18:51 EST


On Sun, Aug 30, 2020 at 06:14:33PM +0800, Alex Shi wrote:
> +++ b/mm/page_alloc.c
> @@ -532,9 +536,18 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags,
> mask <<= bitidx;
> flags <<= bitidx;
>
> +#ifdef CONFIG_CPU_V6
> + byte = (unsigned long)READ_ONCE(bitmap[byte_bitidx]);
> +#else
> byte = READ_ONCE(bitmap[byte_bitidx]);
> +#endif
> for (;;) {
> +#ifdef CONFIG_CPU_V6
> + /* arm v6 has no cmpxchgb function, so still false sharing long word */
> + old_byte = cmpxchg((unsigned long*)&bitmap[byte_bitidx], byte, (byte & ~mask) | flags);
> +#else
> old_byte = cmpxchg(&bitmap[byte_bitidx], byte, (byte & ~mask) | flags);
> +#endif

Good grief, no. Either come up with an appropriate abstraction or
abandon this patch. We can't possibly put this kind of ifdef in the
memory allocator!