The patch titled Subject: mm: ksm: do not block on page lock when searching stable tree fix has been added to the -mm tree. Its filename is mm-ksm-do-not-block-on-page-lock-when-searching-stable-tree-fix.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-ksm-do-not-block-on-page-lock-when-searching-stable-tree-fix.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-ksm-do-not-block-on-page-lock-when-searching-stable-tree-fix.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Hugh Dickins <hughd@xxxxxxxxxx> Subject: mm: ksm: do not block on page lock when searching stable tree fix I hit the kernel BUG at mm/ksm.c:809! quite easily under KSM swapping load. That's the BUG_ON(age > 1) in remove_rmap_item_from_tree(). There is a comment above it, but explaining in more detail: KSM saves effort by not fully maintaining the unstable tree like a proper RB tree throughout, but at the start of each pass forgetting the old tree and rebuilding anew from scratch. But that means that whenever it looks like we need to remove an item from the unstable tree, we have to check whether it has already been linked into the new tree this time around (hence rb_erase needed), or it's just a free-floating leftover from the previous tree. "age" 0 or 1 says which: but if it's more than 1, then something has gone wrong: cmp_and_merge_page() was forgetting to remove the item in the new EBUSY case. Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1902182122280.6914@eggly.anvils Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx> Cc: John Hubbard <jhubbard@xxxxxxxxxx> Cc: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/ksm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/mm/ksm.c~mm-ksm-do-not-block-on-page-lock-when-searching-stable-tree-fix +++ a/mm/ksm.c @@ -2082,10 +2082,6 @@ static void cmp_and_merge_page(struct pa /* We first start with searching the page inside the stable tree */ kpage = stable_tree_search(page); - - if (PTR_ERR(kpage) == -EBUSY) - return; - if (kpage == page && rmap_item->head == stable_node) { put_page(kpage); return; @@ -2094,6 +2090,9 @@ static void cmp_and_merge_page(struct pa remove_rmap_item_from_tree(rmap_item); if (kpage) { + if (PTR_ERR(kpage) == -EBUSY) + return; + err = try_to_merge_with_ksm_page(rmap_item, page, kpage); if (!err) { /* _ Patches currently in -mm which might be from hughd@xxxxxxxxxx are mm-ksm-do-not-block-on-page-lock-when-searching-stable-tree-fix.patch