All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miaohe Lin <linmiaohe@huawei.com>
To: <akpm@linux-foundation.org>
Cc: <shy828301@gmail.com>, <willy@infradead.org>,
	<zokeefe@google.com>, <songmuchun@bytedance.com>,
	<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	<linmiaohe@huawei.com>
Subject: [PATCH v3 05/16] mm/huge_memory: use helper touch_pmd in huge_pmd_set_accessed
Date: Mon, 4 Jul 2022 21:21:50 +0800	[thread overview]
Message-ID: <20220704132201.14611-6-linmiaohe@huawei.com> (raw)
In-Reply-To: <20220704132201.14611-1-linmiaohe@huawei.com>

Use helper touch_pmd to set pmd accessed to simplify the code and improve
the readability. No functional change intended.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/huge_memory.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 30acb3b994cf..f9b6eb3f2215 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1121,15 +1121,15 @@ EXPORT_SYMBOL_GPL(vmf_insert_pfn_pud_prot);
 #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */
 
 static void touch_pmd(struct vm_area_struct *vma, unsigned long addr,
-		pmd_t *pmd, int flags)
+		      pmd_t *pmd, bool write)
 {
 	pmd_t _pmd;
 
 	_pmd = pmd_mkyoung(*pmd);
-	if (flags & FOLL_WRITE)
+	if (write)
 		_pmd = pmd_mkdirty(_pmd);
 	if (pmdp_set_access_flags(vma, addr & HPAGE_PMD_MASK,
-				pmd, _pmd, flags & FOLL_WRITE))
+				  pmd, _pmd, write))
 		update_mmu_cache_pmd(vma, addr, pmd);
 }
 
@@ -1162,7 +1162,7 @@ struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr,
 		return NULL;
 
 	if (flags & FOLL_TOUCH)
-		touch_pmd(vma, addr, pmd, flags);
+		touch_pmd(vma, addr, pmd, flags & FOLL_WRITE);
 
 	/*
 	 * device mapped pages can only be returned if the
@@ -1399,21 +1399,13 @@ void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
 
 void huge_pmd_set_accessed(struct vm_fault *vmf)
 {
-	pmd_t entry;
-	unsigned long haddr;
 	bool write = vmf->flags & FAULT_FLAG_WRITE;
-	pmd_t orig_pmd = vmf->orig_pmd;
 
 	vmf->ptl = pmd_lock(vmf->vma->vm_mm, vmf->pmd);
-	if (unlikely(!pmd_same(*vmf->pmd, orig_pmd)))
+	if (unlikely(!pmd_same(*vmf->pmd, vmf->orig_pmd)))
 		goto unlock;
 
-	entry = pmd_mkyoung(orig_pmd);
-	if (write)
-		entry = pmd_mkdirty(entry);
-	haddr = vmf->address & HPAGE_PMD_MASK;
-	if (pmdp_set_access_flags(vmf->vma, haddr, vmf->pmd, entry, write))
-		update_mmu_cache_pmd(vmf->vma, vmf->address, vmf->pmd);
+	touch_pmd(vmf->vma, vmf->address, vmf->pmd, write);
 
 unlock:
 	spin_unlock(vmf->ptl);
@@ -1549,7 +1541,7 @@ struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
 		return ERR_PTR(-ENOMEM);
 
 	if (flags & FOLL_TOUCH)
-		touch_pmd(vma, addr, pmd, flags);
+		touch_pmd(vma, addr, pmd, flags & FOLL_WRITE);
 
 	page += (addr & ~HPAGE_PMD_MASK) >> PAGE_SHIFT;
 	VM_BUG_ON_PAGE(!PageCompound(page) && !is_zone_device_page(page), page);
-- 
2.23.0


  parent reply	other threads:[~2022-07-04 13:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04 13:21 [PATCH v3 00/16] A few cleanup patches for huge_memory Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 01/16] mm/huge_memory: use flush_pmd_tlb_range in move_huge_pmd Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 02/16] mm/huge_memory: access vm_page_prot with READ_ONCE in remove_migration_pmd Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 03/16] mm/huge_memory: fix comment of __pud_trans_huge_lock Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 04/16] mm/huge_memory: use helper touch_pud in huge_pud_set_accessed Miaohe Lin
2022-07-04 13:52   ` Muchun Song
2022-07-04 13:21 ` Miaohe Lin [this message]
2022-07-04 13:53   ` [PATCH v3 05/16] mm/huge_memory: use helper touch_pmd in huge_pmd_set_accessed Muchun Song
2022-07-04 13:21 ` [PATCH v3 06/16] mm/huge_memory: rename mmun_start to haddr in remove_migration_pmd Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 07/16] mm/huge_memory: use helper function vma_lookup in split_huge_pages_pid Miaohe Lin
2022-07-04 13:54   ` Muchun Song
2022-07-04 13:21 ` [PATCH v3 08/16] mm/huge_memory: use helper macro __ATTR_RW Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 09/16] mm/huge_memory: fix comment in zap_huge_pud Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 10/16] mm/huge_memory: check pmd_present first in is_huge_zero_pmd Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 11/16] mm/huge_memory: try to free subpage in swapcache when possible Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 12/16] mm/huge_memory: minor cleanup for split_huge_pages_all Miaohe Lin
2022-07-04 13:21 ` [PATCH v3 13/16] mm/huge_memory: fix comment of page_deferred_list Miaohe Lin
2022-07-04 13:55   ` Muchun Song
2022-07-04 13:21 ` [PATCH v3 14/16] mm/huge_memory: correct comment of prep_transhuge_page Miaohe Lin
2022-07-04 13:22 ` [PATCH v3 15/16] mm/huge_memory: comment the subtly logic in __split_huge_pmd Miaohe Lin
2022-07-04 13:22 ` [PATCH v3 16/16] mm/huge_memory: use helper macro IS_ERR_OR_NULL in split_huge_pages_pid Miaohe Lin

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=20220704132201.14611-6-linmiaohe@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shy828301@gmail.com \
    --cc=songmuchun@bytedance.com \
    --cc=willy@infradead.org \
    --cc=zokeefe@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.