Skip to content

Commit c17b1f4

Browse files
kiryltorvalds
authored andcommitted
hugetlb: fix nr_pmds accounting with shared page tables
We account HugeTLB's shared page table to all processes who share it. The accounting happens during huge_pmd_share(). If somebody populates pud entry under us, we should decrease pagetable's refcount and decrease nr_pmds of the process. By mistake, I increase nr_pmds again in this case. :-/ It will lead to "BUG: non-zero nr_pmds on freeing mm: 2" on process' exit. Let's fix this by increasing nr_pmds only when we're sure that the page table will be used. Link: http://lkml.kernel.org/r/[email protected] Fixes: dc6c9a3 ("mm: account pmd page tables to the process") Signed-off-by: Kirill A. Shutemov <[email protected]> Reported-by: zhongjiang <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Acked-by: Michal Hocko <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 06d8fbc commit c17b1f4

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

mm/hugetlb.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,7 +4228,6 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
42284228
if (saddr) {
42294229
spte = huge_pte_offset(svma->vm_mm, saddr);
42304230
if (spte) {
4231-
mm_inc_nr_pmds(mm);
42324231
get_page(virt_to_page(spte));
42334232
break;
42344233
}
@@ -4243,9 +4242,9 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
42434242
if (pud_none(*pud)) {
42444243
pud_populate(mm, pud,
42454244
(pmd_t *)((unsigned long)spte & PAGE_MASK));
4245+
mm_inc_nr_pmds(mm);
42464246
} else {
42474247
put_page(virt_to_page(spte));
4248-
mm_inc_nr_pmds(mm);
42494248
}
42504249
spin_unlock(ptl);
42514250
out:

0 commit comments

Comments
 (0)