diff mbox series

[v2,04/16] mm/huge_memory: use helper touch_pud in huge_pud_set_accessed

Message ID 20220628132835.8925-5-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series A few cleanup patches for huge_memory | expand

Commit Message

Miaohe Lin June 28, 2022, 1:28 p.m. UTC
Use helper touch_pud to set pud 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 | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

Comments

Muchun Song June 28, 2022, 2:59 p.m. UTC | #1
On Tue, Jun 28, 2022 at 09:28:23PM +0800, Miaohe Lin wrote:
> Use helper touch_pud to set pud 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 | 16 ++++------------
>  1 file changed, 4 insertions(+), 12 deletions(-)
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index f7164ef8b6e3..d55d5efa06c8 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -1284,15 +1284,15 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
>  
>  #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
>  static void touch_pud(struct vm_area_struct *vma, unsigned long addr,
> -		pud_t *pud, int flags)
> +		      pud_t *pud, bool write)

You have change the last parameter. Have you forgotten to update its user
of follow_devmap_pud()?

Thanks.

>  {
>  	pud_t _pud;
>  
>  	_pud = pud_mkyoung(*pud);
> -	if (flags & FOLL_WRITE)
> +	if (write)
>  		_pud = pud_mkdirty(_pud);
>  	if (pudp_set_access_flags(vma, addr & HPAGE_PUD_MASK,
> -				pud, _pud, flags & FOLL_WRITE))
> +				  pud, _pud, write))
>  		update_mmu_cache_pud(vma, addr, pud);
>  }
>  
> @@ -1384,21 +1384,13 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm,
>  
>  void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
>  {
> -	pud_t entry;
> -	unsigned long haddr;
>  	bool write = vmf->flags & FAULT_FLAG_WRITE;
>  
>  	vmf->ptl = pud_lock(vmf->vma->vm_mm, vmf->pud);
>  	if (unlikely(!pud_same(*vmf->pud, orig_pud)))
>  		goto unlock;
>  
> -	entry = pud_mkyoung(orig_pud);
> -	if (write)
> -		entry = pud_mkdirty(entry);
> -	haddr = vmf->address & HPAGE_PUD_MASK;
> -	if (pudp_set_access_flags(vmf->vma, haddr, vmf->pud, entry, write))
> -		update_mmu_cache_pud(vmf->vma, vmf->address, vmf->pud);
> -
> +	touch_pud(vmf->vma, vmf->address, vmf->pud, write);
>  unlock:
>  	spin_unlock(vmf->ptl);
>  }
> -- 
> 2.23.0
> 
>
Miaohe Lin June 29, 2022, 2:17 a.m. UTC | #2
On 2022/6/28 22:59, Muchun Song wrote:
> On Tue, Jun 28, 2022 at 09:28:23PM +0800, Miaohe Lin wrote:
>> Use helper touch_pud to set pud 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 | 16 ++++------------
>>  1 file changed, 4 insertions(+), 12 deletions(-)
>>
>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>> index f7164ef8b6e3..d55d5efa06c8 100644
>> --- a/mm/huge_memory.c
>> +++ b/mm/huge_memory.c
>> @@ -1284,15 +1284,15 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
>>  
>>  #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
>>  static void touch_pud(struct vm_area_struct *vma, unsigned long addr,
>> -		pud_t *pud, int flags)
>> +		      pud_t *pud, bool write)
> 
> You have change the last parameter. Have you forgotten to update its user
> of follow_devmap_pud()?

My bad. I was overloaded yesterday. Thanks for catching this!
Will change it in next version.

> 
> Thanks.
> 
>>  {
>>  	pud_t _pud;
>>  
>>  	_pud = pud_mkyoung(*pud);
>> -	if (flags & FOLL_WRITE)
>> +	if (write)
>>  		_pud = pud_mkdirty(_pud);
>>  	if (pudp_set_access_flags(vma, addr & HPAGE_PUD_MASK,
>> -				pud, _pud, flags & FOLL_WRITE))
>> +				  pud, _pud, write))
>>  		update_mmu_cache_pud(vma, addr, pud);
>>  }
>>  
>> @@ -1384,21 +1384,13 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm,
>>  
>>  void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
>>  {
>> -	pud_t entry;
>> -	unsigned long haddr;
>>  	bool write = vmf->flags & FAULT_FLAG_WRITE;
>>  
>>  	vmf->ptl = pud_lock(vmf->vma->vm_mm, vmf->pud);
>>  	if (unlikely(!pud_same(*vmf->pud, orig_pud)))
>>  		goto unlock;
>>  
>> -	entry = pud_mkyoung(orig_pud);
>> -	if (write)
>> -		entry = pud_mkdirty(entry);
>> -	haddr = vmf->address & HPAGE_PUD_MASK;
>> -	if (pudp_set_access_flags(vmf->vma, haddr, vmf->pud, entry, write))
>> -		update_mmu_cache_pud(vmf->vma, vmf->address, vmf->pud);
>> -
>> +	touch_pud(vmf->vma, vmf->address, vmf->pud, write);
>>  unlock:
>>  	spin_unlock(vmf->ptl);
>>  }
>> -- 
>> 2.23.0
>>
>>
> .
>
diff mbox series

Patch

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index f7164ef8b6e3..d55d5efa06c8 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1284,15 +1284,15 @@  int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 
 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
 static void touch_pud(struct vm_area_struct *vma, unsigned long addr,
-		pud_t *pud, int flags)
+		      pud_t *pud, bool write)
 {
 	pud_t _pud;
 
 	_pud = pud_mkyoung(*pud);
-	if (flags & FOLL_WRITE)
+	if (write)
 		_pud = pud_mkdirty(_pud);
 	if (pudp_set_access_flags(vma, addr & HPAGE_PUD_MASK,
-				pud, _pud, flags & FOLL_WRITE))
+				  pud, _pud, write))
 		update_mmu_cache_pud(vma, addr, pud);
 }
 
@@ -1384,21 +1384,13 @@  int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 
 void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
 {
-	pud_t entry;
-	unsigned long haddr;
 	bool write = vmf->flags & FAULT_FLAG_WRITE;
 
 	vmf->ptl = pud_lock(vmf->vma->vm_mm, vmf->pud);
 	if (unlikely(!pud_same(*vmf->pud, orig_pud)))
 		goto unlock;
 
-	entry = pud_mkyoung(orig_pud);
-	if (write)
-		entry = pud_mkdirty(entry);
-	haddr = vmf->address & HPAGE_PUD_MASK;
-	if (pudp_set_access_flags(vmf->vma, haddr, vmf->pud, entry, write))
-		update_mmu_cache_pud(vmf->vma, vmf->address, vmf->pud);
-
+	touch_pud(vmf->vma, vmf->address, vmf->pud, write);
 unlock:
 	spin_unlock(vmf->ptl);
 }