Re: [PATCH v2 1/1] swap: shmem: remove SWAP_MAP_SHMEM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 11, 2024 at 2:39 AM Huang, Ying <ying.huang@xxxxxxxxx> wrote:
>
> Nhat Pham <nphamcs@xxxxxxxxx> writes:
>
> [snip]
>
> > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > index 0cded32414a1..9bb94e618914 100644
> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -1381,12 +1381,6 @@ static unsigned char __swap_entry_free_locked(struct swap_info_struct *si,
> >       if (usage == SWAP_HAS_CACHE) {
> >               VM_BUG_ON(!has_cache);
> >               has_cache = 0;
> > -     } else if (count == SWAP_MAP_SHMEM) {
> > -             /*
> > -              * Or we could insist on shmem.c using a special
> > -              * swap_shmem_free() and free_shmem_swap_and_cache()...
> > -              */
> > -             count = 0;
> >       } else if ((count & ~COUNT_CONTINUED) <= SWAP_MAP_MAX) {
> >               if (count == COUNT_CONTINUED) {
> >                       if (swap_count_continued(si, offset, count))
> > @@ -3626,7 +3620,6 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr)
> >
> >       offset = swp_offset(entry);
> >       VM_WARN_ON(nr > SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER);
> > -     VM_WARN_ON(usage == 1 && nr > 1);
> >       ci = lock_cluster_or_swap_info(si, offset);
> >
> >       err = 0;
> > @@ -3652,6 +3645,13 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr)
> >                               err = -EEXIST;
> >               } else if ((count & ~COUNT_CONTINUED) > SWAP_MAP_MAX) {
> >                       err = -EINVAL;
> > +             } else {
> > +                     /*
> > +                      * The only swap_duplicate_nr() caller that passes nr > 1 is shmem,
> > +                      * who never re-duplicates any swap entry it owns. So this should
> > +                      * not happen.
> > +                      */
> > +                     VM_WARN_ON(nr > 1 && (count & ~COUNT_CONTINUED) == SWAP_MAP_MAX);
>
> Why not
>
>         VM_WARN_ON_ONCE(nr > 1 && count);
>
> ?
>
> IIUC, count == 0 is always true for shmem swap entry allocation.  Then
> developers who use __swap_duplicate() with nr > 1 without noticing the
> unsupported feature can get warning during development immediately.
> "(count & ~COUNT_CONTINUED) == SWAP_MAP_MAX" is hard to be triggered
> during common swap test.

Yeah honestly, I agree with this. Let's not try to be smart and make
provision for things that can't happen (and make it harder to catch
issues in the future).

Thanks for the suggestion, Ying. I'll just do this in next version.

>
> >               }
> >
> >               if (err)
> > @@ -3686,27 +3686,28 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr)
> >       return err;
> >  }
>
> [snip]
>
> --
> Best Regards,
> Huang, Ying





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux