Re: [PATCH v2 02/25] mm: Optimise find_subpage for !THP

From: Christoph Hellwig
Date: Wed Feb 12 2020 - 12:52:52 EST


On Wed, Feb 12, 2020 at 05:02:00AM -0800, Matthew Wilcox wrote:
> > Can you add comments describing the use case of this function and why
> > it does all these checks? It looks like black magic to me.
>
> Would this help?
>
> -static inline struct page *find_subpage(struct page *page, pgoff_t offset)
> +/*
> + * Given the page we found in the page cache, return the page corresponding
> + * to this offset in the file
> + */
> +static inline struct page *find_subpage(struct page *head, pgoff_t offset)
> {
> - if (PageHuge(page))
> - return page;
> + /* HugeTLBfs wants the head page regardless */
> + if (PageHuge(head))
> + return head;
>
> - VM_BUG_ON_PAGE(PageTail(page), page);
> + VM_BUG_ON_PAGE(PageTail(head), head);
>
> - return page + (offset & (hpage_nr_pages(page) - 1));
> + return head + (offset & (hpage_nr_pages(head) - 1));

Much better.