On Mon, Jul 29, 2019 at 03:47:18PM -0700, Dan Williams wrote: > On Mon, Jul 29, 2019 at 2:10 PM William Kucharski > <william.kucharski@xxxxxxxxxx> wrote: > > > > Add filemap_huge_fault() to attempt to satisfy page faults on > > memory-mapped read-only text pages using THP when possible. > > > > Signed-off-by: William Kucharski <william.kucharski@xxxxxxxxxx> > [..] > > +/** > > + * filemap_huge_fault - read in file data for page fault handling to THP > > + * @vmf: struct vm_fault containing details of the fault > > + * @pe_size: large page size to map, currently this must be PE_SIZE_PMD > > + * > > + * filemap_huge_fault() is invoked via the vma operations vector for a > > + * mapped memory region to read in file data to a transparent huge page during > > + * a page fault. > > + * > > + * If for any reason we can't allocate a THP, map it or add it to the page > > + * cache, VM_FAULT_FALLBACK will be returned which will cause the fault > > + * handler to try mapping the page using a PAGESIZE page, usually via > > + * filemap_fault() if so speicifed in the vma operations vector. > > + * > > + * Returns either VM_FAULT_FALLBACK or the result of calling allcc_set_pte() > > + * to map the new THP. > > + * > > + * NOTE: This routine depends upon the file system's readpage routine as > > + * specified in the address space operations vector to recognize when it > > + * is being passed a large page and to read the approprate amount of data > > + * in full and without polluting the page cache for the large page itself > > + * with PAGESIZE pages to perform a buffered read or to pollute what > > + * would be the page cache space for any succeeding pages with PAGESIZE > > + * pages due to readahead. > > + * > > + * It is VITAL that this routine not be enabled without such filesystem > > + * support. > > Rather than a hopeful comment, this wants an explicit mechanism to > prevent inadvertent mismatched ->readpage() assumptions. Filesystems have to opt in to this. If they add a ->huge_fault entry to their vm_operations_struct without updating their ->readpage implementation, they only have themselves to blame.