Re: [PATCH v4 06/36] mm: Introduce offset_in_thp

From: Matthew Wilcox
Date: Fri May 29 2020 - 09:00:04 EST


On Fri, May 22, 2020 at 08:15:17PM +0300, Kirill A. Shutemov wrote:
> On Fri, May 15, 2020 at 06:16:26AM -0700, Matthew Wilcox wrote:
> > +#define offset_in_thp(page, p) ((unsigned long)(p) & (thp_size(page) - 1))
>
> Looks like thp_mask() would be handy here.

It's not the only place we could use a thp_mask(), but PAGE_MASK is the
inverse of what I think it should be:

include/asm-generic/page.h:#define PAGE_MASK (~(PAGE_SIZE-1))

ie addr & PAGE_MASK returns the address aligned to page size, not the
offset within the page. Given this ambiguity, I'm inclined to leave
it as (thp_size(page) - 1), as it's clear which bits we're masking off.