Re: [PATCH -mm -V3 03/21] mm, THP, swap: Support PMD swap mapping in swap_duplicate()

From: Daniel Jordan
Date: Tue Jun 12 2018 - 08:05:17 EST


On Tue, Jun 12, 2018 at 09:23:19AM +0800, Huang, Ying wrote:
> Daniel Jordan <daniel.m.jordan@xxxxxxxxxx> writes:
> > #2: We've masked off SWAP_HAS_CACHE and COUNT_CONTINUED, and already checked
> > for SWAP_MAP_BAD, so I think condition #2 always fails and can just be removed.
>
> I think this is used to check some software bug. For example,
> SWAP_MAP_SHMEM will yield true here.

So it does! And so __swap_duplicate returns -EINVAL in that case, which
swap_shmem_alloc just ignores. Confusing, and an explicit check for
SWAP_MAP_SHMEM would be cleaner, but why fix what isn't broken.

>
> >> +#ifdef CONFIG_THP_SWAP
> >> +static int __swap_duplicate_cluster(swp_entry_t *entry, unsigned char usage)
> > ...
> >> + } else {
> >> + for (i = 0; i < SWAPFILE_CLUSTER; i++) {
> >> +retry:
> >> + err = __swap_duplicate_locked(si, offset + i, 1);
> >
> > I guess usage is assumed to be 1 at this point (__swap_duplicate_locked makes
> > the same assumption). Maybe make this explicit with
> >
> > err = __swap_duplicate_locked(si, offset + i, usage);
> >
> > , use 'usage' in cluster_set_count and __swap_entry_free too, and then
> > earlier have a
> >
> > VM_BUG_ON(usage != SWAP_HAS_CACHE && usage != 1);
> >
> > ?
>
> Yes. I will fix this. And we can just check it in
> __swap_duplicate_locked() and all these will be covered.

I'll respond to your other mail.

> > Not related to your changes, but while we're here, the comment with
> > SWAP_HAS_CONT in swap_count() could be deleted: I don't think there ever was a
> > SWAP_HAS_CONT.
>
> Yes. We should correct this. Because this should go to a separate patch,
> would you mind to submit a patch to fix it?

Sure, I'll do that.

Daniel