Re: [PATCH v7 04/14] mm/shmem: Support memfile_notifier

From: Chao Peng
Date: Wed Aug 10 2022 - 05:30:48 EST


On Fri, Aug 05, 2022 at 03:26:02PM +0200, David Hildenbrand wrote:
> On 06.07.22 10:20, Chao Peng wrote:
> > From: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
> >
> > Implement shmem as a memfile_notifier backing store. Essentially it
> > interacts with the memfile_notifier feature flags for userspace
> > access/page migration/page reclaiming and implements the necessary
> > memfile_backing_store callbacks.
> >
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
> > Signed-off-by: Chao Peng <chao.p.peng@xxxxxxxxxxxxxxx>
> > ---
>
> [...]
>
> > +#ifdef CONFIG_MEMFILE_NOTIFIER
> > +static struct memfile_node *shmem_lookup_memfile_node(struct file *file)
> > +{
> > + struct inode *inode = file_inode(file);
> > +
> > + if (!shmem_mapping(inode->i_mapping))
> > + return NULL;
> > +
> > + return &SHMEM_I(inode)->memfile_node;
> > +}
> > +
> > +
> > +static int shmem_get_pfn(struct file *file, pgoff_t offset, pfn_t *pfn,
> > + int *order)
> > +{
> > + struct page *page;
> > + int ret;
> > +
> > + ret = shmem_getpage(file_inode(file), offset, &page, SGP_WRITE);
> > + if (ret)
> > + return ret;
> > +
> > + unlock_page(page);
> > + *pfn = page_to_pfn_t(page);
> > + *order = thp_order(compound_head(page));
> > + return 0;
> > +}
> > +
> > +static void shmem_put_pfn(pfn_t pfn)
> > +{
> > + struct page *page = pfn_t_to_page(pfn);
> > +
> > + if (!page)
> > + return;
> > +
> > + put_page(page);
>
>
> Why do we export shmem_get_pfn/shmem_put_pfn and not simply
>
> get_folio()
>
> and let the caller deal with putting the folio? What's the reason to
>
> a) Operate on PFNs and not folios
> b) Have these get/put semantics?

We have a design assumption that somedays this can even support non-page
based backing stores. There are some discussions:
https://lkml.org/lkml/2022/3/28/1440
I should add document for this two callbacks.

>
> > +}
> > +
> > +static struct memfile_backing_store shmem_backing_store = {
> > + .lookup_memfile_node = shmem_lookup_memfile_node,
> > + .get_pfn = shmem_get_pfn,
> > + .put_pfn = shmem_put_pfn,
> > +};
> > +#endif /* CONFIG_MEMFILE_NOTIFIER */
> > +
> > void __init shmem_init(void)
> > {
> > int error;
> > @@ -3956,6 +4059,10 @@ void __init shmem_init(void)
> > else
> > shmem_huge = SHMEM_HUGE_NEVER; /* just in case it was patched */
> > #endif
> > +
> > +#ifdef CONFIG_MEMFILE_NOTIFIER
> > + memfile_register_backing_store(&shmem_backing_store);
>
> Can we instead prove a dummy function that does nothing without
> CONFIG_MEMFILE_NOTIFIER?

Sounds good.

Chao
>
> > +#endif
> > return;
> >
> > out1:
>
>
> --
> Thanks,
>
> David / dhildenb
>