Re: [PATCH 2/8] mm: Use find_get_swap_page in memcontrol

Johannes Weiner
2020-08-26T16:26:47Z

On Wed, Aug 26, 2020 at 03:54:14PM +0100, Matthew Wilcox wrote:
> On Wed, Aug 26, 2020 at 10:20:02AM -0400, Johannes Weiner wrote:
> > On Wed, Aug 19, 2020 at 07:48:44PM +0100, Matthew Wilcox (Oracle) wrote:
> > > + return find_get_swap_page(vma->vm_file->f_mapping,
> > > + linear_page_index(vma, addr));
> >
> > The refactor makes sense to me, but the name is confusing. We're not
> > looking for a swap page, we're primarily looking for a file page in
> > the page cache mapping that's handed in. Only in the special case
> > where it's a shmem mapping and there is a swap entry do we consult the
> > auxiliary swap cache.
> >
> > How about find_get_page_or_swapcache()? find_get_page_shmemswap()?
> > Maybe you have a better idea. It's a fairly specialized operation that
> > isn't widely used, so a longer name isn't a bad thing IMO.
>
> Yeah, I had trouble with the naming here too.
>
> get_page_even_from_swap()
> find_get_shmem_page()
>
> or maybe refactor the whole thing:
>
> struct page *page = find_get_entry(mapping, index);
> page = find_swap_page(mapping, page);
>
> struct page *find_swap_page(struct address_space *mapping, struct page *page)
> {
> swp_entry_t swp;
> struct swap_info_struct *si;
>
> if (!xa_is_value(page))
> return page;
> if (!shmem_mapping(mapping))
> return NULL;
>
> ...
> }

Yeah, I like the idea of two lookups if we can't find a good name for
the operation that combines them. I'd just bubble the control flow
that links them up to the callsite - that still seems plenty compact
for two callsites, and keeps all the shmem magic in shmem code:

page = find_get_entry(mapping, index);
if (xa_is_value(page))
if (shmem_mapping(mapping))
page = lookup_shmem_swap_cache(page);
else
page = NULL;

So close to making radix_to_swp_entry() & co. private to shmem.c, too
- if it weren't for force_shm_swapin_readahead(). Ah well.