diff mbox series

[RFC,4/5] hugetlb: don't permit pmd sharing if soft dirty in use

Message ID 20210211000322.159437-5-mike.kravetz@oracle.com (mailing list archive)
State New, archived
Headers show
Series Add hugetlb soft dirty support | expand

Commit Message

Mike Kravetz Feb. 11, 2021, 12:03 a.m. UTC
If page modifications are being monitoried with the soft dirty mechanism,
then this information is contained in page table entries.  Tracking is
enabled on a 'per-process' basis.  hugetlb pmd sharing allows processes
to share page table entries.  This makes pmd sharing incompatible with
soft dirty monitoring.  So, pmd sharing must be disabled if soft dirty
tracking is in use.

The VM_SOFTDIRTY flag is set in all vma's by default.  When soft dirty
monitoring is started, the flag is cleared.  We can therefore allow pmd
sharing in vmas with the VM_SOFTDIRTY flag set.  Check this when deciding
to perform pmd sharing.

A subsequent patch will add code to allow soft dirty monitoring for hugetlb
vmas.  Any existing pmd sharing will be undone at that time.

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

Comments

Peter Xu Feb. 17, 2021, 7:44 p.m. UTC | #1
On Wed, Feb 10, 2021 at 04:03:21PM -0800, Mike Kravetz wrote:
> If page modifications are being monitoried with the soft dirty mechanism,
> then this information is contained in page table entries.  Tracking is
> enabled on a 'per-process' basis.  hugetlb pmd sharing allows processes
> to share page table entries.  This makes pmd sharing incompatible with
> soft dirty monitoring.  So, pmd sharing must be disabled if soft dirty
> tracking is in use.
> 
> The VM_SOFTDIRTY flag is set in all vma's by default.  When soft dirty
> monitoring is started, the flag is cleared.  We can therefore allow pmd
> sharing in vmas with the VM_SOFTDIRTY flag set.  Check this when deciding
> to perform pmd sharing.
> 
> A subsequent patch will add code to allow soft dirty monitoring for hugetlb
> vmas.  Any existing pmd sharing will be undone at that time.
> 
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
>  mm/hugetlb.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index b561b6867ec1..cf4aa63be9b1 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -5285,6 +5285,13 @@ static bool vma_shareable(struct vm_area_struct *vma, unsigned long addr)
>  	unsigned long base = addr & PUD_MASK;
>  	unsigned long end = base + PUD_SIZE;
>  
> +	/*
> +	 * Do not allow pmd sharing if soft dirty tracking is in use.
> +	 */
> +	if (IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) &&
> +				!(vma->vm_flags & VM_SOFTDIRTY))
> +		return false;
> +

Reviewed-by: Peter Xu <peterx@redhat.com>

The indent of using three tabs is a bit weird to me, though.. I do see this
happen somewhere else in the repo too, so maybe it's a way to indent that I
don't know.

Thanks,
diff mbox series

Patch

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b561b6867ec1..cf4aa63be9b1 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5285,6 +5285,13 @@  static bool vma_shareable(struct vm_area_struct *vma, unsigned long addr)
 	unsigned long base = addr & PUD_MASK;
 	unsigned long end = base + PUD_SIZE;
 
+	/*
+	 * Do not allow pmd sharing if soft dirty tracking is in use.
+	 */
+	if (IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) &&
+				!(vma->vm_flags & VM_SOFTDIRTY))
+		return false;
+
 	/*
 	 * check on proper vm_flags and page table alignment
 	 */