[PATCH v2 2/2] mm: set pte writable while pte_soft_dirty() is true in do_swap_page()

Barry Song posted 2 patches 1 year, 8 months ago
[PATCH v2 2/2] mm: set pte writable while pte_soft_dirty() is true in do_swap_page()
Posted by Barry Song 1 year, 8 months ago
From: Barry Song <v-songbaohua@oppo.com>

This patch leverages the new pte_needs_soft_dirty_wp() helper to optimize
a scenario where softdirty is enabled, but the softdirty flag has already
been set in do_swap_page(). In this situation, we can use pte_mkwrite
instead of applying write-protection since we don't depend on write
faults.

Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory.c b/mm/memory.c
index db9130488231..a063e489446d 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4322,7 +4322,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
 	if (!folio_test_ksm(folio) &&
 	    (exclusive || folio_ref_count(folio) == 1)) {
 		if ((vma->vm_flags & VM_WRITE) && !userfaultfd_pte_wp(vma, pte) &&
-		    !vma_soft_dirty_enabled(vma)) {
+		    !pte_needs_soft_dirty_wp(vma, pte)) {
 			pte = pte_mkwrite(pte, vma);
 			if (vmf->flags & FAULT_FLAG_WRITE) {
 				pte = pte_mkdirty(pte);
-- 
2.34.1
Re: [PATCH v2 2/2] mm: set pte writable while pte_soft_dirty() is true in do_swap_page()
Posted by David Hildenbrand 1 year, 8 months ago
On 07.06.24 23:13, Barry Song wrote:
> From: Barry Song <v-songbaohua@oppo.com>
> 
> This patch leverages the new pte_needs_soft_dirty_wp() helper to optimize
> a scenario where softdirty is enabled, but the softdirty flag has already
> been set in do_swap_page(). In this situation, we can use pte_mkwrite
> instead of applying write-protection since we don't depend on write
> faults.
> 
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> ---
>   mm/memory.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index db9130488231..a063e489446d 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -4322,7 +4322,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
>   	if (!folio_test_ksm(folio) &&
>   	    (exclusive || folio_ref_count(folio) == 1)) {
>   		if ((vma->vm_flags & VM_WRITE) && !userfaultfd_pte_wp(vma, pte) &&
> -		    !vma_soft_dirty_enabled(vma)) {
> +		    !pte_needs_soft_dirty_wp(vma, pte)) {
>   			pte = pte_mkwrite(pte, vma);
>   			if (vmf->flags & FAULT_FLAG_WRITE) {
>   				pte = pte_mkdirty(pte);

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb