linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Kravetz <mike.kravetz@oracle.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-s390@vger.kernel.org
Cc: shu wang <malate_wangshu@hotmail.com>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Peter Xu <peterx@redhat.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Matthew Wilcox <willy@infradead.org>,
	Michel Lespinasse <walken@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Kravetz <mike.kravetz@oracle.com>
Subject: [RFC PATCH 2/5] hugetlb: enhance hugetlb fault processing to support soft dirty
Date: Wed, 10 Feb 2021 16:03:19 -0800	[thread overview]
Message-ID: <20210211000322.159437-3-mike.kravetz@oracle.com> (raw)
In-Reply-To: <20210211000322.159437-1-mike.kravetz@oracle.com>

hugetlb fault processing code would COW all write faults where the
pte was not writable.  Soft dirty will write protect ptes as part
of it's tracking mechanism.  The existing hugetlb_cow  code will do
the right thing for PRIVATE mappings as it checks map_count.  However,
for SHARED mappings it would actually allocate and install a COW page.
Modify the code to not call hugetlb_cow for SHARED mappings and just
update the pte.

Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/hugetlb.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 47f3123afd1a..b561b6867ec1 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -4584,8 +4584,10 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 	 * spinlock. For private mappings, we also lookup the pagecache
 	 * page now as it is used to determine if a reservation has been
 	 * consumed.
+	 * Only non-shared mappings are sent to hugetlb_cow.
 	 */
-	if ((flags & FAULT_FLAG_WRITE) && !huge_pte_write(entry)) {
+	if ((flags & FAULT_FLAG_WRITE) && !huge_pte_write(entry) &&
+					!(vma->vm_flags & VM_SHARED)) {
 		if (vma_needs_reservation(h, vma, haddr) < 0) {
 			ret = VM_FAULT_OOM;
 			goto out_mutex;
@@ -4593,9 +4595,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 		/* Just decrements count, does not deallocate */
 		vma_end_reservation(h, vma, haddr);
 
-		if (!(vma->vm_flags & VM_MAYSHARE))
-			pagecache_page = hugetlbfs_pagecache_page(h,
-								vma, haddr);
+		pagecache_page = hugetlbfs_pagecache_page(h, vma, haddr);
 	}
 
 	ptl = huge_pte_lock(h, mm, ptep);
@@ -4620,9 +4620,18 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 
 	if (flags & FAULT_FLAG_WRITE) {
 		if (!huge_pte_write(entry)) {
-			ret = hugetlb_cow(mm, vma, address, ptep,
-					  pagecache_page, ptl);
-			goto out_put_page;
+			if (!(vma->vm_flags & VM_SHARED)) {
+				ret = hugetlb_cow(mm, vma, address, ptep,
+						pagecache_page, ptl);
+				goto out_put_page;
+			}
+
+			/* write protected for soft dirty processing */
+			if ((vma->vm_flags & VM_WRITE) &&
+					(vma->vm_flags & VM_SHARED))
+				entry = huge_pte_mkwrite(entry);
+
+			entry = huge_pte_mkdirty(entry);
 		}
 		entry = huge_pte_mkdirty(entry);
 	}
-- 
2.29.2



  parent reply	other threads:[~2021-02-11  0:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11  0:03 [RFC PATCH 0/5] Add hugetlb soft dirty support Mike Kravetz
2021-02-11  0:03 ` [RFC PATCH 1/5] hugetlb: add hugetlb helpers for " Mike Kravetz
2021-02-17 16:24   ` Peter Xu
2021-02-18 22:58     ` Mike Kravetz
2021-02-24 16:46     ` Gerald Schaefer
2021-02-24 16:55       ` Gerald Schaefer
2021-02-11  0:03 ` Mike Kravetz [this message]
2021-02-17 19:32   ` [RFC PATCH 2/5] hugetlb: enhance hugetlb fault processing to support soft dirty Peter Xu
2021-02-18 23:26     ` Mike Kravetz
2021-02-11  0:03 ` [RFC PATCH 3/5] mm proc/task_mmu.c: add soft dirty pte checks for hugetlb Mike Kravetz
2021-02-17 19:35   ` Peter Xu
2021-02-18 23:59     ` Mike Kravetz
2021-02-11  0:03 ` [RFC PATCH 4/5] hugetlb: don't permit pmd sharing if soft dirty in use Mike Kravetz
2021-02-17 19:44   ` Peter Xu
2021-02-11  0:03 ` [RFC PATCH 5/5] mm proc/task_mmu.c: add hugetlb specific routine for clear_refs Mike Kravetz
2021-02-17 20:25   ` Peter Xu
2021-02-19  0:14     ` Mike Kravetz

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=20210211000322.159437-3-mike.kravetz@oracle.com \
    --to=mike.kravetz@oracle.com \
    --cc=aarcange@redhat.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=malate_wangshu@hotmail.com \
    --cc=peterx@redhat.com \
    --cc=walken@google.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;
as well as URLs for NNTP newsgroup(s).