linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yang Shi <shy828301@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@redhat.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Hugh Dickins <hughd@google.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux MM <linux-mm@kvack.org>,
	Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH] mm: thp: don't have to lock page anymore when splitting PMD
Date: Mon, 7 Mar 2022 16:03:12 -0800	[thread overview]
Message-ID: <CAHbLzkqY69nFniK+ckQaeu117Q+OqZ2hvFEdVbZaW2C_zAzDbg@mail.gmail.com> (raw)
In-Reply-To: <20220307154326.6494f7fca7def491a23e5df1@linux-foundation.org>

On Mon, Mar 7, 2022 at 3:43 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Mon, 7 Mar 2022 09:24:58 +0100 David Hildenbrand <david@redhat.com> wrote:
>
> > On 07.03.22 03:07, Andrew Morton wrote:
> > > On Fri, 4 Mar 2022 19:50:08 +0100 David Hildenbrand <david@redhat.com> wrote:
> > >
> > >> @Andrew, the last mail I received was
> > >>
> > >> + mm-huge_memory-remove-stale-locking-logic-from-__split_huge_pmd.patch
> > >> added to -mm tree
> > >>
> > >> The patch shows up in mmotm as
> > >>
> > >> #[merged]mm-huge_memory-remove-stale-locking-logic-from-__split_huge_pmd.patch
> > >>
> > >> ... which shouldn't be true.
> > >
> > > I guess I mislabelled the reason for dropping it.  Should have been to-be-updated,
> > > due to https://lkml.kernel.org/r/CAHbLzkpbnQyHRckoRtbZoaLvANu92MY4kEsbKudaQ8MDUA3nVg@mail.gmail.com
> > >
> >
> > Let me clarify.
> >
> > 1. I sent [1] (9 patches)
> >
> > 2. You queued the 9 patches
> >
> > E.g., in "mmotm 2022-02-15-20-22 uploaded"
> >
> > * mm-optimize-do_wp_page-for-exclusive-pages-in-the-swapcache.patch
> > * mm-optimize-do_wp_page-for-fresh-pages-in-local-lru-pagevecs.patch
> > * mm-slightly-clarify-ksm-logic-in-do_swap_page.patch
> > * mm-streamline-cow-logic-in-do_swap_page.patch
> > * mm-huge_memory-streamline-cow-logic-in-do_huge_pmd_wp_page.patch
> > * mm-khugepaged-remove-reuse_swap_page-usage.patch
> > * mm-swapfile-remove-stale-reuse_swap_page.patch
> > * mm-huge_memory-remove-stale-page_trans_huge_mapcount.patch
> > * mm-huge_memory-remove-stale-locking-logic-from-__split_huge_pmd.patch
> >
> > 3. The last patch in the series was dropped. What remains are 8 patches.
> >
> > E.g., in "mmotm 2022-02-24-22-38 uploaded"
> >
> > * mm-optimize-do_wp_page-for-exclusive-pages-in-the-swapcache.patch
> > * mm-optimize-do_wp_page-for-fresh-pages-in-local-lru-pagevecs.patch
> > * mm-slightly-clarify-ksm-logic-in-do_swap_page.patch
> > * mm-streamline-cow-logic-in-do_swap_page.patch
> > * mm-huge_memory-streamline-cow-logic-in-do_huge_pmd_wp_page.patch
> > * mm-khugepaged-remove-reuse_swap_page-usage.patch
> > * mm-swapfile-remove-stale-reuse_swap_page.patch
> > * mm-huge_memory-remove-stale-page_trans_huge_mapcount.patch
> >
> > 4. Yang Shi sent his patch (the one we're replying to)
> >
> > 5. You picked his patch and dropped it again due to [2]
> >
> >
> > I'm wondering why 3 happened and why
> > https://www.ozlabs.org/~akpm/mmotm/series contains:
> >
> >
> > mm-optimize-do_wp_page-for-exclusive-pages-in-the-swapcache.patch
> > mm-optimize-do_wp_page-for-fresh-pages-in-local-lru-pagevecs.patch
> > mm-slightly-clarify-ksm-logic-in-do_swap_page.patch
> > mm-streamline-cow-logic-in-do_swap_page.patch
> > mm-huge_memory-streamline-cow-logic-in-do_huge_pmd_wp_page.patch
> > mm-khugepaged-remove-reuse_swap_page-usage.patch
> > mm-swapfile-remove-stale-reuse_swap_page.patch
> > mm-huge_memory-remove-stale-page_trans_huge_mapcount.patch
> > ...
> > #[merged]mm-huge_memory-remove-stale-locking-logic-from-__split_huge_pmd.patch
>
> OK, thanks.  I guess it was me seeing 100% rejects when merging onto
> the folio changes then incorrectly deciding the patch was now in
> linux-next via some other tree.
>
> I restored it and fixed things up.  Please check.

Thanks, Andrew. I think we could clean it up a little bit further.

>
>
> --- a/mm/huge_memory.c~mm-huge_memory-remove-stale-locking-logic-from-__split_huge_pmd
> +++ a/mm/huge_memory.c
> @@ -2133,8 +2133,6 @@ void __split_huge_pmd(struct vm_area_str
>  {
>         spinlock_t *ptl;
>         struct mmu_notifier_range range;
> -       bool do_unlock_folio = false;
> -       pmd_t _pmd;
>
>         mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm,
>                                 address & HPAGE_PMD_MASK,
> @@ -2153,42 +2151,14 @@ void __split_huge_pmd(struct vm_area_str
>                         goto out;
>         }
>
> -repeat:
>         if (pmd_trans_huge(*pmd)) {
> -               if (!folio) {
> +               if (!folio)
>                         folio = page_folio(pmd_page(*pmd));

We could remove the "if (pmd_trans_huge(*pmd))" section since folio is
actually not used afterward at all.

> -                       /*
> -                        * An anonymous page must be locked, to ensure that a
> -                        * concurrent reuse_swap_page() sees stable mapcount;
> -                        * but reuse_swap_page() is not used on shmem or file,
> -                        * and page lock must not be taken when zap_pmd_range()
> -                        * calls __split_huge_pmd() while i_mmap_lock is held.
> -                        */
> -                       if (folio_test_anon(folio)) {
> -                               if (unlikely(!folio_trylock(folio))) {
> -                                       folio_get(folio);
> -                                       _pmd = *pmd;
> -                                       spin_unlock(ptl);
> -                                       folio_lock(folio);
> -                                       spin_lock(ptl);
> -                                       if (unlikely(!pmd_same(*pmd, _pmd))) {
> -                                               folio_unlock(folio);
> -                                               folio_put(folio);
> -                                               folio = NULL;
> -                                               goto repeat;
> -                                       }
> -                                       folio_put(folio);
> -                               }
> -                               do_unlock_folio = true;
> -                       }
> -               }
>         } else if (!(pmd_devmap(*pmd) || is_pmd_migration_entry(*pmd)))
>                 goto out;
>         __split_huge_pmd_locked(vma, pmd, range.start, freeze);

With the above if removed, this could be changed to:

if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd) ||
            is_pmd_migration_entry(*pmd))
                __split_huge_pmd_locked(vma, pmd, range.start, freeze);

>  out:
>         spin_unlock(ptl);
> -       if (do_unlock_folio)
> -               folio_unlock(folio);
>         /*
>          * No need to double call mmu_notifier->invalidate_range() callback.
>          * They are 3 cases to consider inside __split_huge_pmd_locked():
> _
>

  reply	other threads:[~2022-03-08  0:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 22:20 [PATCH] mm: thp: don't have to lock page anymore when splitting PMD Yang Shi
2022-03-04  2:25 ` Miaohe Lin
2022-03-04  3:12   ` Yang Shi
     [not found] ` <CADFyXm6W9CVkO4XPYep-tHg55c8m8NES783kcVYrdjSMbzYoDA@mail.gmail.com>
2022-03-04 18:30   ` Yang Shi
2022-03-04 18:50     ` David Hildenbrand
2022-03-04 19:01       ` Yang Shi
2022-03-07  2:07       ` Andrew Morton
2022-03-07  8:24         ` David Hildenbrand
2022-03-07 23:43           ` Andrew Morton
2022-03-08  0:03             ` Yang Shi [this message]
2022-03-08  0:50               ` Andrew Morton
2022-03-08  0:59                 ` Yang Shi
2022-03-08  2:36                 ` Hugh Dickins
2022-03-08  3:12                   ` Yang Shi
2022-03-08  8:53             ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHbLzkqY69nFniK+ckQaeu117Q+OqZ2hvFEdVbZaW2C_zAzDbg@mail.gmail.com \
    --to=shy828301@gmail.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).