Skip to content

Commit c3f0327

Browse files
koct9itorvalds
authored andcommitted
mm: add rss counters consistency check
Warn about non-zero rss counters at final mmdrop. This check will prevent reoccurences of bugs such as that fixed in "mm: fix rss count leakage during migration". I didn't hide this check under CONFIG_VM_DEBUG because it rather small and rss counters cover whole page-table management, so this is a good invariant. Signed-off-by: Konstantin Khlebnikov <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent dc3f21e commit c3f0327

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

kernel/fork.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,23 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)
511511
return NULL;
512512
}
513513

514+
static void check_mm(struct mm_struct *mm)
515+
{
516+
int i;
517+
518+
for (i = 0; i < NR_MM_COUNTERS; i++) {
519+
long x = atomic_long_read(&mm->rss_stat.count[i]);
520+
521+
if (unlikely(x))
522+
printk(KERN_ALERT "BUG: Bad rss-counter state "
523+
"mm:%p idx:%d val:%ld\n", mm, i, x);
524+
}
525+
526+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
527+
VM_BUG_ON(mm->pmd_huge_pte);
528+
#endif
529+
}
530+
514531
/*
515532
* Allocate and initialize an mm_struct.
516533
*/
@@ -538,9 +555,7 @@ void __mmdrop(struct mm_struct *mm)
538555
mm_free_pgd(mm);
539556
destroy_context(mm);
540557
mmu_notifier_mm_destroy(mm);
541-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
542-
VM_BUG_ON(mm->pmd_huge_pte);
543-
#endif
558+
check_mm(mm);
544559
free_mm(mm);
545560
}
546561
EXPORT_SYMBOL_GPL(__mmdrop);

0 commit comments

Comments
 (0)