diff mbox series

[RESEND,v5,3/4] mm/mlock: check for THP missing the mlock in try_to_unmap_one()

Message ID 20240513074712.7608-4-ioworker0@gmail.com (mailing list archive)
State New
Headers show
Series Reclaim lazyfree THP without splitting | expand

Commit Message

Lance Yang May 13, 2024, 7:47 a.m. UTC
The TTU_SPLIT_HUGE_PMD will no longer perform immediately, so we might
encounter a PMD-mapped THP missing the mlock in the VM_LOCKED range
during the pagewalk. It's likely necessary to mlock this THP to prevent
it from being picked up during page reclaim.

Suggested-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Signed-off-by: Lance Yang <ioworker0@gmail.com>
---
 mm/rmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Baolin Wang May 14, 2024, 6:41 a.m. UTC | #1
On 2024/5/13 15:47, Lance Yang wrote:
> The TTU_SPLIT_HUGE_PMD will no longer perform immediately, so we might
> encounter a PMD-mapped THP missing the mlock in the VM_LOCKED range
> during the pagewalk. It's likely necessary to mlock this THP to prevent
> it from being picked up during page reclaim.
> 
> Suggested-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> Signed-off-by: Lance Yang <ioworker0@gmail.com>

IMO, this patch should be merged into patch 2, otherwise patch 2 is 
buggy. Quote the description in the 'submission patches.rst' document:

"When dividing your change into a series of patches, take special care 
to ensure that the kernel builds and runs properly after each patch in 
the series.  Developers using ``git bisect`` to track down a problem can 
end up splitting your patch series at any point; they will not thank you 
if you introduce bugs in the middle."

> ---
>   mm/rmap.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 4c4d14325f2e..08a93347f283 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1671,7 +1671,8 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
>   		if (!(flags & TTU_IGNORE_MLOCK) &&
>   		    (vma->vm_flags & VM_LOCKED)) {
>   			/* Restore the mlock which got missed */
> -			if (!folio_test_large(folio))
> +			if (!folio_test_large(folio) ||
> +			    (!pvmw.pte && (flags & TTU_SPLIT_HUGE_PMD)))
>   				mlock_vma_folio(folio, vma);
>   			goto walk_done_err;
>   		}
Lance Yang May 14, 2024, 7:46 a.m. UTC | #2
On Tue, May 14, 2024 at 2:41 PM Baolin Wang
<baolin.wang@linux.alibaba.com> wrote:
>
>
>
> On 2024/5/13 15:47, Lance Yang wrote:
> > The TTU_SPLIT_HUGE_PMD will no longer perform immediately, so we might
> > encounter a PMD-mapped THP missing the mlock in the VM_LOCKED range
> > during the pagewalk. It's likely necessary to mlock this THP to prevent
> > it from being picked up during page reclaim.
> >
> > Suggested-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> > Signed-off-by: Lance Yang <ioworker0@gmail.com>
>
> IMO, this patch should be merged into patch 2, otherwise patch 2 is
> buggy. Quote the description in the 'submission patches.rst' document:
>
> "When dividing your change into a series of patches, take special care
> to ensure that the kernel builds and runs properly after each patch in
> the series.  Developers using ``git bisect`` to track down a problem can
> end up splitting your patch series at any point; they will not thank you
> if you introduce bugs in the middle."

Thanks for bringing this up!

I completely agree that this patch should be merged into patch2.

Thanks,
Lance

>
> > ---
> >   mm/rmap.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/rmap.c b/mm/rmap.c
> > index 4c4d14325f2e..08a93347f283 100644
> > --- a/mm/rmap.c
> > +++ b/mm/rmap.c
> > @@ -1671,7 +1671,8 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
> >               if (!(flags & TTU_IGNORE_MLOCK) &&
> >                   (vma->vm_flags & VM_LOCKED)) {
> >                       /* Restore the mlock which got missed */
> > -                     if (!folio_test_large(folio))
> > +                     if (!folio_test_large(folio) ||
> > +                         (!pvmw.pte && (flags & TTU_SPLIT_HUGE_PMD)))
> >                               mlock_vma_folio(folio, vma);
> >                       goto walk_done_err;
> >               }
diff mbox series

Patch

diff --git a/mm/rmap.c b/mm/rmap.c
index 4c4d14325f2e..08a93347f283 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1671,7 +1671,8 @@  static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
 		if (!(flags & TTU_IGNORE_MLOCK) &&
 		    (vma->vm_flags & VM_LOCKED)) {
 			/* Restore the mlock which got missed */
-			if (!folio_test_large(folio))
+			if (!folio_test_large(folio) ||
+			    (!pvmw.pte && (flags & TTU_SPLIT_HUGE_PMD)))
 				mlock_vma_folio(folio, vma);
 			goto walk_done_err;
 		}