Skip to contentSkip to conversation

mm: Fix the pgtable leak

PATCH In review Minchan Kim 3 participants 11 messages Feb 13, 2019 – Feb 18, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: Fix the pgtable leak

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback
[2] b0b9b3df27d10, mm: stop leaking PageTables

Fixes 5cf3e5ff95876 ("mm, memcg: fix reclaim deadlock with writeback")
Cc Johannes Weiner <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Liu Bo <[email protected]>
---
 mm/memory.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
mm/memory.c +15 -6
index 35d8217bb0467..47248dc0b9e1a 100644
@@ -3329,15 +3329,24 @@ static int do_fault(struct fault_env *fe)
 {
 	struct vm_area_struct *vma = fe->vma;
 	pgoff_t pgoff = linear_page_index(vma, fe->address);
+	int ret;
 
 	/* The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */
 	if (!vma->vm_ops->fault)
-		return VM_FAULT_SIGBUS;
-	if (!(fe->flags & FAULT_FLAG_WRITE))
-		return do_read_fault(fe, pgoff);
-	if (!(vma->vm_flags & VM_SHARED))
-		return do_cow_fault(fe, pgoff);
-	return do_shared_fault(fe, pgoff);
+		ret = VM_FAULT_SIGBUS;
+	else if (!(fe->flags & FAULT_FLAG_WRITE))
+		ret = do_read_fault(fe, pgoff);
+	else if (!(vma->vm_flags & VM_SHARED))
+		ret = do_cow_fault(fe, pgoff);
+	else
+		ret = do_shared_fault(fe, pgoff);
+
+	/* preallocated pagetable is unused: free it */
+	if (fe->prealloc_pte) {
+		pte_free(vma->vm_mm, fe->prealloc_pte);
+		fe->prealloc_pte = 0;
+	}
+	return ret;
 }
 
 static int numa_migrate_prep(struct page *page, struct vm_area_struct *vma,
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#1 lore raw
Quoted 8 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback
[2] b0b9b3df27d10, mm: stop leaking PageTables

Quoted 9 lines
Fixes 5cf3e5ff95876 ("mm, memcg: fix reclaim deadlock with writeback")
Cc Johannes Weiner <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Liu Bo <[email protected]>
#2 lore raw
In reply to Minchan Kim
Quoted 8 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback
[2] b0b9b3df27d10, mm: stop leaking PageTables

Quoted 9 lines
Fixes 5cf3e5ff95876 ("mm, memcg: fix reclaim deadlock with writeback")
Cc Johannes Weiner <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Liu Bo <[email protected]>

Thanks for catching this dependency. Do I assume it correctly that this is stable-4.9 only?

Quoted 42 lines
---
 mm/memory.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
mm/memory.c +15 -6
index 35d8217bb0467..47248dc0b9e1a 100644
@@ -3329,15 +3329,24 @@ static int do_fault(struct fault_env *fe)
 {
 	struct vm_area_struct *vma = fe->vma;
 	pgoff_t pgoff = linear_page_index(vma, fe->address);
+	int ret;
 
 	/* The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */
 	if (!vma->vm_ops->fault)
-		return VM_FAULT_SIGBUS;
-	if (!(fe->flags & FAULT_FLAG_WRITE))
-		return do_read_fault(fe, pgoff);
-	if (!(vma->vm_flags & VM_SHARED))
-		return do_cow_fault(fe, pgoff);
-	return do_shared_fault(fe, pgoff);
+		ret = VM_FAULT_SIGBUS;
+	else if (!(fe->flags & FAULT_FLAG_WRITE))
+		ret = do_read_fault(fe, pgoff);
+	else if (!(vma->vm_flags & VM_SHARED))
+		ret = do_cow_fault(fe, pgoff);
+	else
+		ret = do_shared_fault(fe, pgoff);
+
+	/* preallocated pagetable is unused: free it */
+	if (fe->prealloc_pte) {
+		pte_free(vma->vm_mm, fe->prealloc_pte);
+		fe->prealloc_pte = 0;
+	}
+	return ret;
 }
 
 static int numa_migrate_prep(struct page *page, struct vm_area_struct *vma,
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Signature · 2 lines
Michal Hocko
SUSE Labs
#3 lore raw
Quoted 19 lines · Michal Hocko
Quoted 8 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback
[2] b0b9b3df27d10, mm: stop leaking PageTables

Quoted 9 lines
Fixes 5cf3e5ff95876 ("mm, memcg: fix reclaim deadlock with writeback")
Cc Johannes Weiner <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Liu Bo <[email protected]>
Quoted 2 lines

Thanks for catching this dependency. Do I assume it correctly that this is stable-4.9 only?

I have no idea how I could find it automatically that a stable patch of linus tree is spread out with several stable trees(Hope Greg has an answer). I just checked 4.4 longterm kernel and couldn't find it in there.

Thanks.

#4 lore raw
Quoted 20 lines · Minchan Kim
Quoted 19 lines · Michal Hocko
Quoted 17 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback
[2] b0b9b3df27d10, mm: stop leaking PageTables

Fixes 5cf3e5ff95876 ("mm, memcg: fix reclaim deadlock with writeback")
Cc Johannes Weiner <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Liu Bo <[email protected]>
Quoted 6 lines
Quoted 2 lines

Thanks for catching this dependency. Do I assume it correctly that this is stable-4.9 only?

I have no idea how I could find it automatically that a stable patch of linus tree is spread out with several stable trees(Hope Greg has an answer). I just checked 4.4 longterm kernel and couldn't find it in there.

See http://lkml.kernel.org/r/[email protected]

But my question was more about "this is a stable only thing"? It was not obvious from the subject so I wanted to be sure that I am not missing anything.

Signature · 2 lines
Michal Hocko
SUSE Labs
#5 lore raw
Quoted 28 lines · Michal Hocko
Quoted 20 lines · Minchan Kim
Quoted 19 lines · Michal Hocko
Quoted 17 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback
[2] b0b9b3df27d10, mm: stop leaking PageTables

Fixes 5cf3e5ff95876 ("mm, memcg: fix reclaim deadlock with writeback")
Cc Johannes Weiner <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Liu Bo <[email protected]>
Quoted 6 lines
Quoted 2 lines

Thanks for catching this dependency. Do I assume it correctly that this is stable-4.9 only?

I have no idea how I could find it automatically that a stable patch of linus tree is spread out with several stable trees(Hope Greg has an answer). I just checked 4.4 longterm kernel and couldn't find it in there.

Quoted 5 lines

See http://lkml.kernel.org/r/[email protected]

But my question was more about "this is a stable only thing"? It was not obvious from the subject so I wanted to be sure that I am not missing anything.

Yub, I think only 4.9 stable tree need to be fixed because Hugh's patch was in there since v4.10.

Thanks.

maintainer
#6 lore raw
In reply to Minchan Kim
Quoted 6 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback

This is really commit 63f3655f9501 ("mm, memcg: fix reclaim deadlock with writeback") which was in 4.9.152, 4.14.94, 4.19.16, and 4.20.3 as well as 5.0-rc2.

Quoted 1 line

[2] b0b9b3df27d10, mm: stop leaking PageTables

This commit was in 4.10, so I am guessing that this really is just a backport of that commit?

If so, it's not the full backport, why not take the whole thing? Why only cherry-pick one chunk of it? Why do we not need the other parts?

thanks,

greg k-h

#7 lore raw
Quoted 11 lines · Greg KH
Quoted 6 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback

This is really commit 63f3655f9501 ("mm, memcg: fix reclaim deadlock with writeback") which was in 4.9.152, 4.14.94, 4.19.16, and 4.20.3 as well as 5.0-rc2.

Since 4.10, we has [2] so it should be okay other (tree > 4.10)

Quoted 5 lines
Quoted 2 lines

[2] b0b9b3df27d10, mm: stop leaking PageTables

This commit was in 4.10, so I am guessing that this really is just a backport of that commit?

Yub.

Quoted 3 lines

If so, it's not the full backport, why not take the whole thing? Why only cherry-pick one chunk of it? Why do we not need the other parts?

Because [2] actually aims for fixing [3] which was introduced at 4.10. Since then, [1] relies on the chunk I sent. Thus we don't need other part for 4.9.

[3] 953c66c2b22a ("mm: THP page cache support for ppc64")

Thanks.

#8 lore raw
Quoted 24 lines · Minchan Kim
Quoted 11 lines · Greg KH
Quoted 6 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback

This is really commit 63f3655f9501 ("mm, memcg: fix reclaim deadlock with writeback") which was in 4.9.152, 4.14.94, 4.19.16, and 4.20.3 as well as 5.0-rc2.

Since 4.10, we has [2] so it should be okay other (tree > 4.10)

Quoted 5 lines
Quoted 2 lines

[2] b0b9b3df27d10, mm: stop leaking PageTables

This commit was in 4.10, so I am guessing that this really is just a backport of that commit?

Yub.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

If so, it's not the full backport, why not take the whole thing? Why only cherry-pick one chunk of it? Why do we not need the other parts?

Because [2] actually aims for fixing [3] which was introduced at 4.10. Since then, [1] relies on the chunk I sent. Thus we don't need other part for 4.9.

[3] 953c66c2b22a ("mm: THP page cache support for ppc64")

Hi Greg,

Any chance to look into this patch?

maintainer
#9 lore raw
Quoted 32 lines · Minchan Kim
Quoted 31 lines · Minchan Kim
Quoted 11 lines · Greg KH
Quoted 6 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback

This is really commit 63f3655f9501 ("mm, memcg: fix reclaim deadlock with writeback") which was in 4.9.152, 4.14.94, 4.19.16, and 4.20.3 as well as 5.0-rc2.

Since 4.10, we has [2] so it should be okay other (tree > 4.10)

Quoted 5 lines
Quoted 2 lines

[2] b0b9b3df27d10, mm: stop leaking PageTables

This commit was in 4.10, so I am guessing that this really is just a backport of that commit?

Yub.

Quoted 3 lines

If so, it's not the full backport, why not take the whole thing? Why only cherry-pick one chunk of it? Why do we not need the other parts?

Because [2] actually aims for fixing [3] which was introduced at 4.10. Since then, [1] relies on the chunk I sent. Thus we don't need other part for 4.9.

Quoted 5 lines
Quoted 1 line

[3] 953c66c2b22a ("mm: THP page cache support for ppc64")

Hi Greg,

Any chance to look into this patch?

You sent it on Thursday, it is Monday, I tried to actually take the weekend off :)

It's in my queue, relax, it has good company with a few other hundred stable patches being requested...

greg k-h

maintainer
#10 lore raw
In reply to Minchan Kim
Quoted 17 lines · Minchan Kim

[1] was backported to v4.9 stable tree but it introduces pgtable memory leak because with fault retrial, preallocated pagetable could be leaked in second iteration.
To fix the problem, this patch backport [2].

[1] 5cf3e5ff95876, mm, memcg: fix reclaim deadlock with writeback
[2] b0b9b3df27d10, mm: stop leaking PageTables

Fixes 5cf3e5ff95876 ("mm, memcg: fix reclaim deadlock with writeback")
Cc Johannes Weiner <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Liu Bo <[email protected]>
Quoted 3 lines
---
 mm/memory.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

I fixed up the changelog text to be correct, and now queued this up, thanks.

greg k-h