linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Kravetz <mike.kravetz@oracle.com>
To: Peter Xu <peterx@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-s390@vger.kernel.org, shu wang <malate_wangshu@hotmail.com>,
	Axel Rasmussen <axelrasmussen@google.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>
Subject: Re: [RFC PATCH 2/5] hugetlb: enhance hugetlb fault processing to support soft dirty
Date: Thu, 18 Feb 2021 15:26:52 -0800	[thread overview]
Message-ID: <1a1e5bac-a272-384b-9389-df0b3cccba4b@oracle.com> (raw)
In-Reply-To: <20210217193233.GB6519@xz-x1>

On 2/17/21 11:32 AM, Peter Xu wrote:
> On Wed, Feb 10, 2021 at 04:03:19PM -0800, Mike Kravetz wrote:
>> 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);
> 
> Pure question: I see that the check actually changed from VM_MAYSHARE into
> VM_SHARE, then I noticed I'm actually unclear on the difference..  Say, when
> VM_MAYSHARE is set, could VM_SHARED be cleared in any case?  Or say, is this
> change intended?

The change was not intended.  I will use VM_MAYSHARE.

> 
> I see that vma_set_page_prot() tried to remove VM_SHARED if soft dirty enabled
> (which should cause vma_wants_writenotify() to return true, iiuc), however
> that's temporary just to calculate vm_page_prot, and it's not applied to the
> vma->vm_flags.  I failed to find a place where VM_SHARED of the vma is cleared
> while VM_MAYSHARE is set..

I am not 100% sure about differences.  Here is a snippet from do_mmap() where
you can have VM_MAYSHARE and not VM_SHARED

                        vm_flags |= VM_SHARED | VM_MAYSHARE;
                        if (!(file->f_mode & FMODE_WRITE))
                                vm_flags &= ~(VM_MAYWRITE | VM_SHARED);
                        fallthrough;

> 
>>  	}
>>  
>>  	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) &&
> 
> This VM_WRITE check seems to be redundant.  As example, do_user_addr_fault() of
> x86 code will check this right after vma lookup by access_error().  So when
> reach here if "flags & FAULT_FLAG_WRITE", then VM_WRITE must be set, imho.

Thanks, that sounds reasonable.  I will check to make sure and drop the
redundant check.

> 
>> +					(vma->vm_flags & VM_SHARED))
>> +				entry = huge_pte_mkwrite(entry);
> 
> Same question to VM_SHARED, since "(vma->vm_flags & VM_SHARED)" is just checked
> above and we'll go hugetlb_cow() otherwise.

Yes, certainly redundant here.

> 
>> +
>> +			entry = huge_pte_mkdirty(entry);
> 
> There's another huge_pte_mkdirty() right below; likely we could merge them somehow?
> 

Yes,

Thanks for taking a look!

-- 
Mike Kravetz

> Thanks,
> 
>>  		}
>>  		entry = huge_pte_mkdirty(entry);
>>  	}
>> -- 
>> 2.29.2
>>
> 

  reply	other threads:[~2021-02-18 23:28 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 ` [RFC PATCH 2/5] hugetlb: enhance hugetlb fault processing to support soft dirty Mike Kravetz
2021-02-17 19:32   ` Peter Xu
2021-02-18 23:26     ` Mike Kravetz [this message]
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=1a1e5bac-a272-384b-9389-df0b3cccba4b@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).