linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: David Hildenbrand <david@redhat.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org, Barry Song <v-songbaohua@oppo.com>,
	 Chuanhua Han <hanchuanhua@oppo.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	 Ryan Roberts <ryan.roberts@arm.com>, Zi Yan <ziy@nvidia.com>,
	Chris Li <chrisl@kernel.org>,  Kairui Song <kasong@tencent.com>,
	Kalesh Singh <kaleshsingh@google.com>,
	 Suren Baghdasaryan <surenb@google.com>
Subject: Re: [PATCH RFC] mm: entirely reuse the whole anon mTHP in do_wp_page
Date: Sat, 31 Aug 2024 22:09:05 +1200	[thread overview]
Message-ID: <CAGsJ_4z=wHXa4Mug8RZJa4zULndPA0k9dw+OC41Lbv4nJUw3Ww@mail.gmail.com> (raw)
In-Reply-To: <c0f79761-f753-4df7-9d02-3bbcbfbd902f@redhat.com>

On Sat, Aug 31, 2024 at 9:59 PM David Hildenbrand <david@redhat.com> wrote:
>
>
> > +             idx = folio_page_idx(folio, vmf->page);
> > +             folio_start = address - idx * PAGE_SIZE;
> > +             folio_end = folio_start + nr * PAGE_SIZE;
> > +
> > +             if (unlikely(folio_start < max(address & PMD_MASK, vma->vm_start)))
> > +                     return false;
> > +             if (unlikely(folio_end > pmd_addr_end(address, vma->vm_end)))
> > +                     return false;
> > +             folio_ptep = vmf->pte - idx;
> > +             folio_pte = ptep_get(folio_ptep);
> > +             if (!pte_present(folio_pte) || pte_pfn(folio_pte) != folio_pfn(folio))
> > +                     return false;
> > +             if (folio_pte_batch(folio, folio_start, folio_ptep, folio_pte, nr, 0,
> > +                             NULL, NULL, NULL) != nr)
> > +                     return false;
> > +             if (folio_mapcount(folio) != nr)
> > +                     return false;
>
> BTW, you're not checking against the refcount (and it's all a bit racy
> on concurrent unmapping!). So you're re-introducing the vmsplice
> child->parent attak.

i don't quite understand this, you mean the below is not enough?

-       if (folio_test_ksm(folio) || folio_ref_count(folio) > 3)
+       if (folio_test_ksm(folio) || folio_ref_count(folio) > 2 + nr)
                return false;
        if (!folio_test_lru(folio))
                /*
@@ -3591,13 +3627,13 @@ static bool wp_can_reuse_anon_folio(struct folio *folio,
                 * remote LRU caches or references to LRU folios.
                 */
                lru_add_drain();
-       if (folio_ref_count(folio) > 1 + folio_test_swapcache(folio))
+       if (folio_ref_count(folio) > nr + folio_test_swapcache(folio))
                return false;
        if (!folio_trylock(folio))
                return false;
        if (folio_test_swapcache(folio))
                folio_free_swap(folio);
-       if (folio_test_ksm(folio) || folio_ref_count(folio) != 1) {
+       if (folio_test_ksm(folio) || folio_ref_count(folio) != nr) {
                folio_unlock(folio);
                return false;

>
> --
> Cheers,
>
> David / dhildenb
>


  reply	other threads:[~2024-08-31 10:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-31  9:23 Barry Song
2024-08-31  9:44 ` David Hildenbrand
2024-08-31  9:55   ` Barry Song
2024-08-31 10:07     ` David Hildenbrand
2024-08-31 10:21       ` Barry Song
2024-08-31 10:29         ` David Hildenbrand
2024-08-31 10:49           ` Barry Song
2024-08-31 11:02             ` David Hildenbrand
2024-08-31  9:59 ` David Hildenbrand
2024-08-31 10:09   ` Barry Song [this message]
2024-08-31 10:14     ` 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='CAGsJ_4z=wHXa4Mug8RZJa4zULndPA0k9dw+OC41Lbv4nJUw3Ww@mail.gmail.com' \
    --to=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=hanchuanhua@oppo.com \
    --cc=kaleshsingh@google.com \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=surenb@google.com \
    --cc=v-songbaohua@oppo.com \
    --cc=ziy@nvidia.com \
    /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