linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Huang, Ying" <ying.huang@intel.com>
To: <alexlzhu@fb.com>
Cc: <linux-mm@kvack.org>,  <kernel-team@fb.com>,
	 <willy@infradead.org>, <hannes@cmpxchg.org>,  <riel@surriel.com>
Subject: Re: [PATCH v3 2/3] mm: changes to split_huge_page() to free zero filled tail pages
Date: Wed, 19 Oct 2022 13:43:17 +0800	[thread overview]
Message-ID: <87h700pdvu.fsf@yhuang6-desk2.ccr.corp.intel.com> (raw)
In-Reply-To: <8d286a7029079c1da0b062fbb045317508409187.1665614216.git.alexlzhu@fb.com> (alexlzhu@fb.com's message of "Wed, 12 Oct 2022 15:51:46 -0700")

<alexlzhu@fb.com> writes:

[snip]

> diff --git a/mm/migrate.c b/mm/migrate.c
> index c228afba0963..504ea5d7fd43 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -168,13 +168,62 @@ void putback_movable_pages(struct list_head *l)
>  	}
>  }
>  
> +static bool try_to_unmap_clean(struct page_vma_mapped_walk *pvmw, struct page *page)
> +{
> +	void *addr;
> +	bool dirty;
> +	pte_t newpte;
> +
> +	VM_BUG_ON_PAGE(PageCompound(page), page);
> +	VM_BUG_ON_PAGE(!PageAnon(page), page);
> +	VM_BUG_ON_PAGE(!PageLocked(page), page);
> +	VM_BUG_ON_PAGE(pte_present(*pvmw->pte), page);
> +
> +	if (PageMlocked(page) || (pvmw->vma->vm_flags & VM_LOCKED))
> +		return false;
> +
> +	/*
> +	 * The pmd entry mapping the old thp was flushed and the pte mapping
> +	 * this subpage has been non present. Therefore, this subpage is
> +	 * inaccessible. We don't need to remap it if it contains only zeros.
> +	 */
> +	addr = kmap_local_page(page);
> +	dirty = memchr_inv(addr, 0, PAGE_SIZE);
> +	kunmap_local(addr);
> +
> +	if (dirty)
> +		return false;
> +
> +	pte_clear_not_present_full(pvmw->vma->vm_mm, pvmw->address, pvmw->pte, false);
> +
> +	if (userfaultfd_armed(pvmw->vma)) {
> +		newpte = pte_mkspecial(pfn_pte(page_to_pfn(ZERO_PAGE(pvmw->address)),
> +					       pvmw->vma->vm_page_prot));
> +		ptep_clear_flush(pvmw->vma, pvmw->address, pvmw->pte);

Why do we need clear PTE and flush TLB again?  If my understanding were
correct, the TLB has been flushed when unmapping the page.  Otherwise,
we need to flush TLB before checking whether the page is all-zero.

> +		set_pte_at(pvmw->vma->vm_mm, pvmw->address, pvmw->pte, newpte);
> +		dec_mm_counter(pvmw->vma->vm_mm, MM_ANONPAGES);
> +		count_vm_event(THP_SPLIT_REMAP_READONLY_ZERO_PAGE);
> +		return true;
> +	}
> +
> +	dec_mm_counter(pvmw->vma->vm_mm, mm_counter(page));

This can be moved before "if (userfaultfd_armed(pvmw->vma))".

> +	count_vm_event(THP_SPLIT_UNMAP);
> +	return true;
> +}
> +

[snip]

Best Regards,
Huang, Ying


  parent reply	other threads:[~2022-10-19  5:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12 22:51 [PATCH v3 0/3] THP Shrinker alexlzhu
2022-10-12 22:51 ` [PATCH v3 1/3] mm: add thp_utilization metrics to debugfs alexlzhu
2022-10-13 11:35   ` Kirill A. Shutemov
2022-10-13 22:53     ` Alex Zhu (Kernel)
2022-10-18  4:28       ` Huang, Ying
2022-10-18  3:21   ` Huang, Ying
2022-10-12 22:51 ` [PATCH v3 2/3] mm: changes to split_huge_page() to free zero filled tail pages alexlzhu
2022-10-13 17:11   ` kernel test robot
2022-10-19  5:43   ` Huang, Ying [this message]
2022-10-12 22:51 ` [PATCH v3 3/3] mm: THP low utilization shrinker alexlzhu
2022-10-13 13:48   ` kernel test robot
2022-10-13 16:39   ` Johannes Weiner
2022-10-13 16:56     ` Johannes Weiner
2022-10-17 18:19       ` Alex Zhu (Kernel)
2022-10-19  7:04   ` Huang, Ying
2022-10-19 19:08     ` Alex Zhu (Kernel)
2022-10-20  1:24       ` Huang, Ying
2022-10-20  3:29         ` Alex Zhu (Kernel)
2022-10-20  8:06           ` Huang, Ying
2022-10-20 17:04             ` Alex Zhu (Kernel)

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=87h700pdvu.fsf@yhuang6-desk2.ccr.corp.intel.com \
    --to=ying.huang@intel.com \
    --cc=alexlzhu@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-mm@kvack.org \
    --cc=riel@surriel.com \
    --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