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

From: Kirill A. Shutemov
Date: Fri May 22 2020 - 13:15:21 EST


On Fri, May 15, 2020 at 06:16:26AM -0700, Matthew Wilcox wrote:
> From: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>
>
> Mirroring offset_in_page(), this gives you the offset within this
> particular page, no matter what size page it is. It optimises down
> to offset_in_page() if CONFIG_TRANSPARENT_HUGEPAGE is not set.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
> ---
> include/linux/mm.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 088acbda722d..9a55dce6a535 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1577,6 +1577,7 @@ static inline void clear_page_pfmemalloc(struct page *page)
> extern void pagefault_out_of_memory(void);
>
> #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
> +#define offset_in_thp(page, p) ((unsigned long)(p) & (thp_size(page) - 1))

Looks like thp_mask() would be handy here.

--
Kirill A. Shutemov