[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAKEwX=NsBWQkzpwFZHbbtnZ-2AsNjb7_PnUa6aLs76ZksD-=8w@mail.gmail.com>
Date: Fri, 11 Oct 2024 11:56:02 -0400
From: Nhat Pham <nphamcs@...il.com>
To: "Huang, Ying" <ying.huang@...el.com>
Cc: akpm@...ux-foundation.org, hannes@...xchg.org, yosryahmed@...gle.com,
hughd@...gle.com, shakeel.butt@...ux.dev, ryan.roberts@....com,
chrisl@...nel.org, david@...hat.com, kasong@...cent.com, willy@...radead.org,
viro@...iv.linux.org.uk, baohua@...nel.org, chengming.zhou@...ux.dev,
v-songbaohua@...o.com, linux-mm@...ck.org, kernel-team@...a.com,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/1] swap: shmem: remove SWAP_MAP_SHMEM
On Fri, Oct 11, 2024 at 2:39 AM Huang, Ying <ying.huang@...el.com> wrote:
>
> Nhat Pham <nphamcs@...il.com> 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
Powered by blists - more mailing lists