On Fri, Apr 05, 2019 at 04:37:42PM +0300, Kirill A. Shutemov wrote: > On Thu, Apr 04, 2019 at 05:28:02PM -0400, Qian Cai wrote: > > On Thu, 2019-04-04 at 16:45 +0300, Kirill A. Shutemov wrote: > > > What about this: > > > > > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > > > index f939e004c5d1..2e8438a1216a 100644 > > > --- a/include/linux/pagemap.h > > > +++ b/include/linux/pagemap.h > > > @@ -335,12 +335,15 @@ static inline struct page *grab_cache_page_nowait(struct > > > address_space *mapping, > > > > > > static inline struct page *find_subpage(struct page *page, pgoff_t offset) > > > { > > > - unsigned long index = page_index(page); > > > + unsigned long mask; > > > + > > > + if (PageHuge(page)) > > > + return page; > > > > > > VM_BUG_ON_PAGE(PageTail(page), page); > > > - VM_BUG_ON_PAGE(index > offset, page); > > > - VM_BUG_ON_PAGE(index + (1 << compound_order(page)) <= offset, page); > > > - return page - index + offset; > > > + > > > + mask = (1UL << compound_order(page)) - 1; > > > + return page + (offset & mask); > > > } > > > > > > struct page *find_get_entry(struct address_space *mapping, pgoff_t offset); > > > > It works fine. > > Nice. > > Matthew, does it look fine to you? Yes, this looks good to me. I think we'll have opportunities to improve it later (eg when unifying THP and hugetlbfs uses of the page cache). But for now, Andrew can you add this version as -fix-fix?