From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D85FC61DA4 for ; Sun, 5 Mar 2023 06:51:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2816E6B0071; Sun, 5 Mar 2023 01:51:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 20A9E6B0073; Sun, 5 Mar 2023 01:51:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 084B06B0074; Sun, 5 Mar 2023 01:51:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E6CD06B0071 for ; Sun, 5 Mar 2023 01:51:19 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AF7CC160A01 for ; Sun, 5 Mar 2023 06:51:19 +0000 (UTC) X-FDA: 80533923078.13.EA6DD16 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf09.hostedemail.com (Postfix) with ESMTP id E3F5E14000E for ; Sun, 5 Mar 2023 06:51:17 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="UuIzjK/r"; spf=pass (imf09.hostedemail.com: domain of 35DsEZAgKCJM65xD5LxA3BB381.zB985AHK-997Ixz7.BE3@flex--jiaqiyan.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=35DsEZAgKCJM65xD5LxA3BB381.zB985AHK-997Ixz7.BE3@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677999078; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=c2W3s7Gpir7cTghmu1AY7YZ2JHArdzy1zLJs3Xa+Np4=; b=ncvIyWOFHk7chbo82LsaR8EZkTe1IdZYBDLV7KYQXDKdsRXgFpjQ1SyDtjUZQxPAxIAP6n H+G/qLkKiKDcRVeSVYba+Vgq1uLetXjAjRcIxxowSrOcJ2ehmJjY2ADgJUCvr7MjnVdQPC jCOMriTZkZZMzYCOgGkFPRsqcKf5Ee8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="UuIzjK/r"; spf=pass (imf09.hostedemail.com: domain of 35DsEZAgKCJM65xD5LxA3BB381.zB985AHK-997Ixz7.BE3@flex--jiaqiyan.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=35DsEZAgKCJM65xD5LxA3BB381.zB985AHK-997Ixz7.BE3@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677999078; a=rsa-sha256; cv=none; b=G7XKtMdY6ddW1kg2Pe1Swhwl6TaFX2mPzS/N3VGFUWsX1O8bPjNDUxPV3PM6d4nrRSlMRO eWr/oQHkcFiAGccRFmMf+llxhwURQ+KN5tMSjOXaviN9XFhRNwr/sIoO21TfFIyexaPZUI YPUtIGgAvoIthagR0iY7UeY8FcWto8o= Received: by mail-pl1-f202.google.com with SMTP id iw4-20020a170903044400b0019ccafc1fbeso3821297plb.3 for ; Sat, 04 Mar 2023 22:51:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677999076; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=c2W3s7Gpir7cTghmu1AY7YZ2JHArdzy1zLJs3Xa+Np4=; b=UuIzjK/rbEbsSE+BWqgDdF5ETk7rp9a1rUNj6m86aAwvFLRqdsj4x4kkazDlxMOGHe /j8tOfFRwGcHcn+DI6mdn4E0QTEutOCKMZ4MPOJOPfRAim7cLSdVcMKf60cemdg0kBvz k6SXekNoEt7TXMJKCKbaZC+FM2ZMv1oqnZfqev9wYch2sxk/VEiAbjVPc3Z1COtz1VFx Tm1/cHN1D2KuGXebhF7nxdvw7btKj0U+l/AbByPVvJYfpqlRn9GxchqMoAaeJ/c9gfpR HCfwS/e9pB/mi0+XYOA6v3mpw+3pb9enKDbbOSL+EpsI8MZkRajaA//paUoVh5zcdD4l C2nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677999076; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=c2W3s7Gpir7cTghmu1AY7YZ2JHArdzy1zLJs3Xa+Np4=; b=st5rxw2uGxz+b/IsvnCRWn6YbSD19YdJ2Xlh4tr4ytRrDQYLH4djXbGnOS31F/HLCW MAQfJbFm7dGTn55Mmpi1IB1+DzaZ4Tdzq1qSmV1Vh+c4W0kSXNuFJ8FOMct8Vgpsvn+F xAa1mJmuY/uexD9kdEVVds4/3T1MMM/+W5O+GxbkO4nM1mKuSa+LhoUv3/K6wHt3Z/FM O0yGl52mqc4JPHJmyLGnAXwlpWlplRsRtOt5uuBiHd/ek0GzqmmPLdwN2EbFup4mVjOf 1N57sEUMgbNSeNKQwx/AFUp6xhNVf8GtMnqWKQNK7H45nfNujVYoLsZjyf+JP1xq7vaO pRDw== X-Gm-Message-State: AO0yUKXPpo+nHvvcPM483GRH0N92+w4G5UTM1SVuwLYYez6/iyYTUqmM ovAm+lo7SLAHetfpICET/We06mgF8PmDtA== X-Google-Smtp-Source: AK7set+K2Am5iCCpu6LpUGiB5Q5Xk7LZD07vG3nlXMHsUg56OUfjnR6zJwhn23qNplU2SnfAnywmkR9ig3K6nA== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a17:903:4293:b0:199:ab4:e140 with SMTP id ju19-20020a170903429300b001990ab4e140mr2684967plb.6.1677999076571; Sat, 04 Mar 2023 22:51:16 -0800 (PST) Date: Sat, 4 Mar 2023 22:51:09 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230305065112.1932255-1-jiaqiyan@google.com> Subject: [PATCH v10 0/3] Memory poison recovery in khugepaged collapsing From: Jiaqi Yan To: kirill.shutemov@linux.intel.com, kirill@shutemov.name, shy828301@gmail.com, tongtiangen@huawei.com, tony.luck@intel.com, akpm@linux-foundation.org Cc: naoya.horiguchi@nec.com, linmiaohe@huawei.com, jiaqiyan@google.com, linux-mm@kvack.org, osalvador@suse.de, wangkefeng.wang@huawei.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E3F5E14000E X-Stat-Signature: em4yrec6bxwjc1g7zmbezdfhujp3mrxj X-HE-Tag: 1677999077-932776 X-HE-Meta: U2FsdGVkX19aZCWUmCtd1tmf6CARP5xDEYiNWXTNo4fbtxXZkaUxC0Ifnct/9tgTlJKPmEZ7YkbGf6aHZZOMTbsjuOQWPztyYDDF0z2X4KnbEE/R0Kd0Yx8NMvZJ74sy6VAuaGhEZn0eZ0Vjw+mseiur/CTwuzdMAPgf+qhl2bhCPmKX+V003M1ZJxUf3FVlBOYkN1OGnaVuOg/Z3pFq9MUxvA8+p91JM4icVKPvpHLZ59HFpELZr8jZ3/22InionbIs8dpj6BbCn3g8KPMcHVXPJWQ1PO7i3vWXckGMMs6E2YXTgdadONXBv9cQ3V/jpW8VW+DlX1fOxM8JBWREvwPlNuj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Xx5nB6OLUJSjc9xpguudTLsNFirjj6vgAHPNjoRbxj3nhypObxOp7NgQ+pv9ZLzU/VHu8U0naHsB2uw8pKyPIvSeMPk85fPBFwRwpvjPI4hJNoENuzyj4hq6Z5hQEchVgovT9G3NMCl9C1j27mQOQpdoM210Z1eFVZrTKMbDx0IY7pNuQmlLLWLCYtQSfREHziPoXHgZIRUCys/SfyHv6tjzDSbyful3/ktI9J33iScibE4ADaBu7JxvPPySkBmLnzWL3ugnjf60nWj7UZJgz/rZjsONZaP7chaFTe/H6wCZDGGcr3g7fJ8Py9QnIzAxXXokG+d/ssjnwdNp9aSYTyDx+gC4Tv3Os/AnVtEDmEBERww+qqqnoBGH6r X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Problem =3D=3D=3D=3D=3D=3D=3D Memory DIMMs are subject to multi-bit flips, i.e. memory errors. As memory size and density increase, the chances of and number of memory errors increase. The increasing size and density of server RAM in the data center and cloud have shown increased uncorrectable memory errors. There are already mechanisms in the kernel to recover from uncorrectable memory errors. This series of patches provides the recovery mechanism for the particular kernel agent khugepaged when it collapses memory pages. Impact =3D=3D=3D=3D=3D=3D The main reason we chose to make khugepaged collapsing tolerant of memory failures was its high possibility of accessing poisoned memory while performing functionally optional compaction actions. Standard applications typically don't have strict requirements on the size of its pages. So they are given 4K pages by the kernel. The kernel is able to improve application performance by either 1) giving applications 2M pages to begin with, or 2) collapsing 4K pages into 2M pages when possible. This collapsing operation is done by khugepaged, a kernel agent that is constantly scanning memory. When collapsing 4K pages into a 2M page, it must copy the data from the 4K pages into a physically contiguous 2M page. Therefore, as long as there exists one poisoned cache line in collapsible 4K pages, khugepaged will eventually access it. The current impact to users is a machine check exception triggered kernel panic. However, khugepaged=E2=80=99s compaction operations are not functionally re= quired kernel actions. Therefore making khugepaged tolerant to poisoned memory will greatly improve user experience. This patch series is for cases where khugepaged is the first guy that detects the memory errors on the poisoned pages. IOW, the pages are not known to have memory errors when khugepaged collapsing gets to them. In our observation, this happens frequently when the huge page ratio of the system is relatively low, which is fairly common in virtual machines running on cloud. Solution =3D=3D=3D=3D=3D=3D=3D=3D As stated before, it is less desirable to crash the system only because khugepaged accesses poisoned pages while it is collapsing 4K pages. The high level idea of this patch series is to skip the group of pages (usually 512 4K-size pages) once khugepaged finds one of them is poisoned, as these pages have become ineligible to be collapsed. We are also careful to unwind operations khuagepaged has performed before it detects memory failures. For example, before copying and collapsing a group of anonymous pages into a huge page, the source pages will be isolated and their page table is unlinked from their PMD. These operations need to be undone in order to ensure these pages are not changed/lost from the perspective of other threads (both user and kernel space). As for file backed memory pages, there already exists a rollback case. This patch just extends it so that khugepaged also correctly rolls back when it fails to copy poisoned 4K pages. Changelog =3D=3D=3D=3D=3D=3D=3D=3D=3D v10 changes - Incorporate feedbacks from Kirill A. Shutemov - Refactor the 2nd loop (after the loop for copying memory) into 2 helper functions, one for actions to take when copying succeeded, one for when copying failed due to #MC. - Use copy_mc_user_highpage for anonymous memory. - Introduce copy_mc_highpage and use it for file-backed memory. - Rename the original PMD from `rollback` to `orig_pmd`. - Some minor changes in comments, e.g. `normal page` to `raw page`. - This revision is rebased to mm-unstable at commit df3ae4347aff9 ("dma-buf: system_heap: avoid reclaim for order 4") v9 changes - Incorporate feedback from Andrew Morton - Move copy_mc_highpage into khugepage.c as a static out-of-line function copy_mc_page. v8 changes - Incorporate feedbacks from Tony Luck - Rename copy_highpage_mc to copy_mc_highpage. - Update copy_mc_highpage with kmsan changes. - Code style changes: 1) copy_mc_highpage returns int as "copy" is an action and is consistent with copy_mc_user_highpage. 2) __collapse_huge_page_copy returns scan_result(int) and is consistent with __collapse_huge_page_isolate/swapin. 3) variables are declared in separate lines in collapse_file. v7 changes - Fix a bug "KASAN: stack-out-of-bounds Read in collapse_file". After copyi= ng all pages into the huge page, clear_highpage should use index instead of page->index. v6 changes - Address comments from Kirill Shutemov - Rewrite __collapse_huge_page_copy to make rollback operations more clear to its reader. - Add detailed test steps in each commit message. v5 changes - Rebase patches to mm-unstable at commit ffb39098bf87 ("Merge tag 'linux-kselftest-kunit-6.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest"). - Resolves conflicts with: commit 2f55f070e5b8 ("mm/khugepaged: minor cleanup for collapse_file") commit 1baec203b77c ("mm/khugepaged: try to free transhuge swapcache when possible") v4 changes - Incorporate feedbacks from Yang Shi - Remove tracepoint for __collapse_huge_page_copy, just keep SCAN_COPY_MC and let trace_mm_collapse_huge_page it - Remove unnecessary comments v3 changes - Incorporate feedbacks from Yang Shi - Add tracepoint for __collapse_huge_page_copy - Restore PMD in collapse_huge_page - Correct comment about mmap_read_lock v2 changes - Incorporate feedbacks from Yang Shi - Only keep copy_highpage_mc - Adding new scan_result SCAN_COPY_MC - Defer NR_FILE_THPS update until copying succeeded Jiaqi Yan (3): mm/khugepaged: recover from poisoned anonymous memory mm/hwpoison: introduce copy_mc_highpage mm/khugepaged: recover from poisoned file-backed memory include/linux/highmem.h | 54 +++++-- include/trace/events/huge_memory.h | 3 +- mm/khugepaged.c | 226 ++++++++++++++++++++++------- 3 files changed, 217 insertions(+), 66 deletions(-) --=20 2.40.0.rc0.216.gc4246ad0f0-goog